db

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: AGPL-3.0 Imports: 11 Imported by: 0

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

This section is empty.

Variables

View Source
var (
	PollTypeAcceptanceSet uint8

	PollRulePlurality uint8

	RoundTypeFreelyAsynchronous uint8
)
View Source
var DB *sql.DB

DB is the pool of database connections for the application.

View Source
var (
	NotFound = errors.New("Not found")
)
View Source
var Ok bool

Ok indicates whether the database is usable. May be false if there is no configuration for the package.

Functions

func AddURLQuery

func AddURLQuery(url, query string) string

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_ ConfirmationType, 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

func DurationToTime(duration time.Duration) string

DurationToTime convert a duration into a time understandable by the database.

func IdFromResult

func IdFromResult(result sql.Result) (uint32, error)

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.

func RepeatDeadlocked

func RepeatDeadlocked(logger slog.Logger, ctx context.Context, opts *sql.TxOptions, fct func(tx *sql.Tx))

RepeatDeadlocked repeats a transaction as long as it produce mySQL deadlocks. MySQL deadlocks are detected by a panic of a mysql.MySQLError with Number 1213.

Types

type ConfirmationType added in v0.1.5

type ConfirmationType string

ConfirmationType is the enum type for the field Type of table Confirmations.

const (
	ConfirmationTypeVerify ConfirmationType = "verify"
	ConfirmationTypePasswd ConfirmationType = "passwd"
)

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"
)

type State added in v0.1.6

type State string

State is the enum type for the field State of table Polls.

const (
	StateWaiting    State = "Waiting"
	StateActive     State = "Active"
	StateTerminated State = "Terminated"
)

Directories

Path Synopsis
Package dbtest allows to temporarily add test data to the database.
Package dbtest allows to temporarily add test data to the database.

Jump to

Keyboard shortcuts

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