db

package
v0.0.0-...-0362a01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2018 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidID is the error returned when encountering an invalid database ID
	ErrInvalidID = errors.New("Invalid id")
)

Functions

func GetDatabase

func GetDatabase() *sql.DB

GetDatabase connects to the database on first run and returns the existing connection on further calls

func SetupPostgres

func SetupPostgres(pc config.PostgreSQLConnection)

SetupPostgres sets the db configuration

func UUID

func UUID() (string, error)

UUID returns a new unique identifier

func WipeDatabase

func WipeDatabase()

WipeDatabase drops all database tables - use carefully!

Types

type BigintSlice

type BigintSlice []int64

BigintSlice is a custom int64 slice for postgres encoding

func (*BigintSlice) Scan

func (s *BigintSlice) Scan(value interface{}) error

Scan converts a postgres value into an int64 slice

func (BigintSlice) Value

func (s BigintSlice) Value() (driver.Value, error)

Value constructs a single postgres query string from a slice of int64

type Mailman

type Mailman struct {
	Mailbox  string
	LastSeen uint64
}

Mailman represents the db schema of mailman info

func (*Mailman) Update

func (mm *Mailman) Update(context *PollyContext) error

Update mailman info in the database

type PgQuery

type PgQuery struct {
	Query    string
	Duration time.Duration
	TxID     int
}

PgQuery keeps stats for a single postgres query

type PollyContext

type PollyContext struct {
	Config config.Data

	Queries []PgQuery
	// contains filtered or unexported fields
}

PollyContext is polly's central context

func (*PollyContext) Authentication

func (context *PollyContext) Authentication(request *restful.Request) (interface{}, error)

Authentication parses the request for an access-/authtoken and returns the matching user

func (*PollyContext) Begin

func (context *PollyContext) Begin() (*PollyContextTx, error)

Begin returns a new polly transactional context

func (*PollyContext) Exec

func (context *PollyContext) Exec(query string, args ...interface{}) (sql.Result, error)

Exec runs a postgres Exec

func (*PollyContext) GetMailman

func (context *PollyContext) GetMailman(mailbox string) (Mailman, error)

GetMailman returns the mailman info for a mailbox

func (*PollyContext) GetProposalByID

func (context *PollyContext) GetProposalByID(id int64) (Proposal, error)

GetProposalByID returns a proposal by ID from the cache

func (*PollyContext) GetUserByAccessToken

func (context *PollyContext) GetUserByAccessToken(token string) (interface{}, error)

GetUserByAccessToken loads a user by accesstoken from the database

func (*PollyContext) GetUserByID

func (context *PollyContext) GetUserByID(id int64) (User, error)

GetUserByID returns a user by ID from the cache

func (*PollyContext) GetUserByNameAndPassword

func (context *PollyContext) GetUserByNameAndPassword(name, password string) (User, error)

GetUserByNameAndPassword loads a user by name & password from the database

func (*PollyContext) GrantMaxValue

func (context *PollyContext) GrantMaxValue() uint

GrantMaxValue returns the max allowed grant value

func (*PollyContext) LoadAllProposals

func (context *PollyContext) LoadAllProposals() ([]Proposal, error)

LoadAllProposals loads all proposals from the database

func (*PollyContext) LoadAllUserVotes

func (context *PollyContext) LoadAllUserVotes(userID int64) ([]Vote, error)

LoadAllUserVotes loads all votes for a user from the database

func (*PollyContext) LoadAllUsers

func (context *PollyContext) LoadAllUsers() ([]User, error)

LoadAllUsers loads all users from the database

func (*PollyContext) LoadProposalByID

func (context *PollyContext) LoadProposalByID(id int64) (Proposal, error)

LoadProposalByID loads a proposal by ID from the database

func (*PollyContext) LoadUserByID

func (context *PollyContext) LoadUserByID(id int64) (User, error)

LoadUserByID loads a user by ID from the database

func (*PollyContext) LogSummary

func (context *PollyContext) LogSummary()

LogSummary logs out the current context stats

func (*PollyContext) NewAPIContext

func (context *PollyContext) NewAPIContext() smolder.APIContext

NewAPIContext returns a new polly context

func (*PollyContext) Query

func (context *PollyContext) Query(query string, args ...interface{}) (*sql.Rows, error)

Query runs a postgres Query

func (*PollyContext) QueryRow

func (context *PollyContext) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow runs a postgres QueryRow

func (*PollyContext) RemainingSmallGrantThisMonth

func (context *PollyContext) RemainingSmallGrantThisMonth(month uint) uint

RemainingSmallGrantThisMonth returns the total available budget for small grants this month

func (*PollyContext) SmallGrantMaxValue

func (context *PollyContext) SmallGrantMaxValue(month uint) uint

SmallGrantMaxValue returns the max available value for a micro budget

type PollyContextTx

type PollyContextTx struct {
	// contains filtered or unexported fields
}

PollyContextTx is a transactional polly context

func (*PollyContextTx) Commit

func (hTx *PollyContextTx) Commit() error

Commit runs a postgres Commit in the transactional context

func (*PollyContextTx) Exec

func (hTx *PollyContextTx) Exec(query string, args ...interface{}) (sql.Result, error)

Exec runs a postgres Exec in the transactional context

func (*PollyContextTx) Query

func (hTx *PollyContextTx) Query(query string, args ...interface{}) (*sql.Rows, error)

Query runs a postgres Query in the transactional context

func (*PollyContextTx) QueryRow

func (hTx *PollyContextTx) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow runs a postgres QueryRow in the transactional context

func (*PollyContextTx) Rollback

func (hTx *PollyContextTx) Rollback() error

Rollback runs a postgres Rollback in the transactional context

type Proposal

type Proposal struct {
	ID           int64
	UserID       int64
	Title        string
	Description  string
	Activities   string
	Contact      string
	Recipient    string
	Recipient2   string
	Value        uint64
	RealValue    uint64
	Starts       time.Time
	FinishedDate time.Time
	Votes        uint64
	Vetos        uint64
	Moderated    bool
	StartTrigger bool
}

Proposal represents the db schema of a proposal

func (*Proposal) Accepted

func (proposal *Proposal) Accepted(context *PollyContext) bool

Accepted returns true if a proposal has finished and was accepted by poll

func (*Proposal) Ended

func (proposal *Proposal) Ended(context *PollyContext) bool

Ended returns true if a proposal ended

func (*Proposal) Ends

func (proposal *Proposal) Ends(context *PollyContext) time.Time

Ends returns when this proposal ends

func (*Proposal) IsTopTwo

func (proposal *Proposal) IsTopTwo(context *PollyContext) bool

func (*Proposal) Save

func (proposal *Proposal) Save(context *PollyContext) error

Save a proposal to the database

func (*Proposal) Started

func (proposal *Proposal) Started(context *PollyContext) bool

Started returns true if a proposal has started

func (*Proposal) Update

func (proposal *Proposal) Update(context *PollyContext) error

Update a proposal in the database

func (*Proposal) Vote

func (proposal *Proposal) Vote(context *PollyContext, user User, up bool) (Vote, error)

Vote marks a vote for a proposal

type StringSlice

type StringSlice []string

StringSlice is a custom string slice for postgres encoding

func (*StringSlice) Scan

func (s *StringSlice) Scan(value interface{}) error

Scan converts a postgres value into a string slice

func (StringSlice) Value

func (s StringSlice) Value() (driver.Value, error)

Value constructs a single postgres query string from a slice of strings

type User

type User struct {
	ID        int64
	Username  string
	About     string
	Email     string
	Activated bool
	AuthToken StringSlice
}

User represents the db schema of a user

func (*User) Save

func (user *User) Save(context *PollyContext) error

Save a user to the database

func (*User) Update

func (user *User) Update(context *PollyContext) error

Update a user in the database

func (*User) UpdatePassword

func (user *User) UpdatePassword(context *PollyContext, password string) error

UpdatePassword sets a new user password in the database

type Vote

type Vote struct {
	ID         int64
	UserID     int64
	ProposalID int64
	Vote       bool
}

Vote represents the db schema of a vote

func (*Vote) Save

func (vote *Vote) Save(context *PollyContext) error

Save a proposal to the database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL