sql

package
v0.0.0-...-b0f0a3b Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(opts NewDatabaseOptions) *Database

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

func (*Database) Connect

func (d *Database) Connect() error

func (*Database) CreateJob

func (d *Database) CreateJob(ctx context.Context, name string, payload model.Map, timeout time.Duration) error

CreateJob to run immediately.

func (*Database) CreateJobForLater

func (d *Database) CreateJobForLater(ctx context.Context, name string, payload model.Map, timeout, after time.Duration) error

func (*Database) DeleteJob

func (d *Database) DeleteJob(ctx context.Context, id int) error

func (*Database) GetJob

func (d *Database) GetJob(ctx context.Context) (*model.Job, error)

GetJob which is eligible to run. Returns nil if no job available.

func (*Database) GetUser

func (d *Database) GetUser(ctx context.Context, id model.ID) (*model.User, error)

func (*Database) GetUserFromToken

func (d *Database) GetUserFromToken(ctx context.Context, token string) (*model.User, error)

func (*Database) Login

func (d *Database) Login(ctx context.Context, token string) (*model.ID, 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.

func (*Database) LoginWithEmail

func (d *Database) LoginWithEmail(ctx context.Context, email model.Email) error

LoginWithEmail 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.

func (*Database) MigrateDown

func (d *Database) MigrateDown(ctx context.Context) error

func (*Database) MigrateUp

func (d *Database) MigrateUp(ctx context.Context) error

func (*Database) Ping

func (d *Database) Ping(ctx context.Context) error

func (*Database) Signup

func (d *Database) Signup(ctx context.Context, u *model.User) error

Signup creates an account, a personal group, an unconfirmed user, and a token. Also creates a job to send an email with a token.

type NewDatabaseOptions

type NewDatabaseOptions struct {
	URL                   string
	MaxOpenConnections    int
	MaxIdleConnections    int
	ConnectionMaxLifetime time.Duration
	ConnectionMaxIdleTime time.Duration
	Log                   *log.Logger
	Metrics               *prometheus.Registry
}

Jump to

Keyboard shortcuts

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