sql

package
v0.0.0-...-c2c9c91 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 22 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = sql.ErrNoRows

Functions

This section is empty.

Types

type Helper

type Helper struct {
	DB    *sqlx.DB
	JobsQ *goqite.Queue
	// contains filtered or unexported fields
}

func NewHelper

func NewHelper(opts NewHelperOptions) *Helper

NewHelper with the given options. If no logger is provided, logs are discarded.

func (*Helper) Connect

func (h *Helper) Connect() error

func (*Helper) CreateJobInTx

func (h *Helper) CreateJobInTx(ctx context.Context, tx *Tx, name string, m stringMap) error

func (*Helper) Exec

func (h *Helper) Exec(ctx context.Context, query string, args ...any) error

func (*Helper) Get

func (h *Helper) Get(ctx context.Context, dest any, query string, args ...any) error

func (*Helper) GetUser

func (h *Helper) GetUser(ctx context.Context, id model.ID) (model.User, error)

func (*Helper) InTransaction

func (h *Helper) InTransaction(ctx context.Context, callback func(tx *Tx) error) (err error)

InTransaction runs callback in a transaction, and makes sure to handle rollbacks, commits etc.

func (*Helper) Login

func (h *Helper) Login(ctx context.Context, token string) (model.User, error)

Login with the given token. It marks the token as used (but this isn't currently checked anywhere) if it's not expired and if the user is marked active. It also sets the user confirmed. Returns the user.

func (*Helper) MigrateDown

func (h *Helper) MigrateDown(ctx context.Context) error

func (*Helper) MigrateUp

func (h *Helper) MigrateUp(ctx context.Context) error

func (*Helper) Ping

func (h *Helper) Ping(ctx context.Context) error

func (*Helper) Select

func (h *Helper) Select(ctx context.Context, dest any, query string, args ...any) error

func (*Helper) Signup

func (h *Helper) Signup(ctx context.Context, u model.User) (model.User, error)

Signup creates an account, an unconfirmed user, and a token. Returns the new user.

func (*Helper) TryLogin

func (h *Helper) TryLogin(ctx context.Context, email model.Email) error

TryLogin checks whether the user exists and is active, creates a login token, and creates a job to send an email with the token in it.

type NewHelperOptions

type NewHelperOptions struct {
	Log  *snorkel.Logger
	Path string
}

type Tx

type Tx struct {
	Tx *sqlx.Tx
}

func (*Tx) Exec

func (t *Tx) Exec(ctx context.Context, query string, args ...any) error

func (*Tx) Get

func (t *Tx) Get(ctx context.Context, dest any, query string, args ...any) error

func (*Tx) Select

func (t *Tx) Select(ctx context.Context, dest any, query string, args ...any) error

Jump to

Keyboard shortcuts

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