Documentation ¶
Overview ¶
Package db provides access to the database backend of the application.
In particular, the package reads the parameters of the database given in the configuration file and provides the pool of database connections to the application.
Index ¶
- Constants
- Variables
- func AddURLQuery(url, query string) string
- func CreateConfirmation(ctx context.Context, user uint32, type_ string, duration time.Duration) (ret salted.Segment, err error)
- func DurationToTime(duration time.Duration) string
- func IdFromResult(result sql.Result) (uint32, error)
- func RepeatDeadlocked(logger slog.Logger, ctx context.Context, opts *sql.TxOptions, ...)
- type Electorate
Constants ¶
const (
ConfirmationTypeVerify = "verify"
)
Variables ¶
var ( PollTypeAcceptanceSet uint8 PollRulePlurality uint8 RoundTypeFreelyAsynchronous uint8 )
var DB *sql.DB
DB is the pool of database connections for the application.
var (
NotFound = errors.New("Not found")
)
var Ok bool
Ok indicates whether the database is usable. May be false if there is no configuration for the package.
Functions ¶
func AddURLQuery ¶
AddURLQuery adds a query string to an url string. TODO: Move this function somewhere else.
func CreateConfirmation ¶
func CreateConfirmation(ctx context.Context, user uint32, type_ string, duration time.Duration) (ret salted.Segment, err error)
CreateConfirmation creates a new confirmation. The created confirmation will be valid only for the given duration, starting at the moment the confirmation is created. Currently, no check is made to ensure that the creation of the confirmation will succeed, and nothing is done when it doesn't.
func DurationToTime ¶
DurationToTime convert a duration into a time understandable by the database.
func IdFromResult ¶
IdFromResult extracts an identifier from a query result of type sql.Result. Such identifiers are used as primary keys for Polls, Users and other tables.
Types ¶
type Electorate ¶
type Electorate string
Electorate is the enum type for the field Electorate of table Polls.
const ( ElectorateAll Electorate = "All" ElectorateLogged Electorate = "Logged" ElectorateVerified Electorate = "Verified" )