mysql

package
v0.0.0-...-4ce15e1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Conn is used as a common interface for the stores so they don't need to worry about whether or not there's a transaction.

type DB

type DB struct {
	Users         *userStore
	Entries       *entryStore
	RefreshTokens *refreshTokenStore
	// contains filtered or unexported fields
}

DB wraps a SQL database with specific functionality

func NewDB

func NewDB(dsn string, options ...Option) (*DB, error)

NewDB returns a new DB with any necessary actions from the given options performed.

func (*DB) Close

func (db *DB) Close() error

Close handles closing any underlying resources for the database. It also runs any of the specified options that are required at the end of the database's use, such as DropDBOnClose.

func (*DB) WithTx

func (db *DB) WithTx() (*DBWithTx, error)

type DBWithTx

type DBWithTx struct {
	*DB
	// contains filtered or unexported fields
}

DBWithTx wraps a DB with a sql Tx.

func (*DBWithTx) Commit

func (tx *DBWithTx) Commit() error

func (*DBWithTx) Rollback

func (tx *DBWithTx) Rollback() error

type Option

type Option func(*DB)

Option is an option to be applied to the DB.

func AutoCreateDB

func AutoCreateDB() Option

AutoCreateDB returns an option that will configure the DB to automatically create the database in the provided instance if it doesn't exist already.

func DropDBOnClose

func DropDBOnClose() Option

DropDBOnClose returns an option that will configure the DB to drop the underlying database when the DB is closed. This is useful if the database is only needed temporarily e.g. for testing.

func DropExistingDB

func DropExistingDB() Option

DropExistingDB returns an option that will configure the DB to drop the database if it currently exists. This would be useful if the DB needs dropped before using the AutoCreateDB Option.

func WithMigrations

func WithMigrations(migrationsDir string) Option

WithMigrations returns an option that will configure the DB to perform automatic migrations. No subdirectories will be searched, and only files with a `.sql` extension will be run. If the directory string provided is empty, no migrations will be run.

type Tx

type Tx interface {
	Rollback() error
	Commit() error
}

Jump to

Keyboard shortcuts

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