database

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeMySQL    = "mysql"
	TypePostgres = "postgres"
	TypeSQLite   = "sqlite"
)

Variables

This section is empty.

Functions

func CtxWithWriterOverride added in v0.33.0

func CtxWithWriterOverride(parent context.Context) context.Context

Types

type Database

type Database interface {
	Type() string
	Connect(ctx context.Context) error
	Migrate(ctx context.Context, toVersion uint) error
	Ping(ctx context.Context) error
	WithinTransaction(ctx context.Context, txCallback func(ctx context.Context) error) error
}

type MySQL

type MySQL struct {
	SQL
	Config config.MySQLConfig
}

func NewMySQL

func NewMySQL(config config.MySQLConfig) *MySQL

func (*MySQL) Connect

func (ds *MySQL) Connect(ctx context.Context) error

func (MySQL) Migrate added in v0.6.0

func (ds MySQL) Migrate(ctx context.Context, toVersion uint) error

func (MySQL) Ping

func (ds MySQL) Ping(ctx context.Context) error

func (MySQL) Type

func (ds MySQL) Type() string

type Postgres added in v0.4.0

type Postgres struct {
	SQL
	Config config.PostgresConfig
}

func NewPostgres added in v0.4.0

func NewPostgres(config config.PostgresConfig) *Postgres

func (*Postgres) Connect added in v0.4.0

func (ds *Postgres) Connect(ctx context.Context) error

func (Postgres) Migrate added in v0.6.0

func (ds Postgres) Migrate(ctx context.Context, toVersion uint) error

func (Postgres) Ping added in v0.4.0

func (ds Postgres) Ping(ctx context.Context) error

func (Postgres) Type added in v0.4.0

func (ds Postgres) Type() string

type SQL

type SQL struct {
	Writer         *sqlx.DB
	Reader         *sqlx.DB
	WriterHostname string
	ReaderHostname string
	DatabaseName   string
}

Wrapper around a sql database with support for a writer + reader pool and the ability to start txns.

func NewSQL added in v0.13.0

func NewSQL(writer *sqlx.DB, reader *sqlx.DB, writerHostname string, readerHostname string, databaseName string) SQL

func (SQL) ExecContext

func (ds SQL) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (SQL) GetContext

func (ds SQL) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (SQL) NamedExecContext

func (ds SQL) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

func (SQL) PrepareContext

func (ds SQL) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

func (SQL) QueryContext

func (ds SQL) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (SQL) QueryRowContext

func (ds SQL) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (SQL) SelectContext

func (ds SQL) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (SQL) WithinTransaction

func (ds SQL) WithinTransaction(ctx context.Context, txFunc func(txCtx context.Context) error) error

Execute txFunc() within the context of a single write transaction

type SQLRepository

type SQLRepository struct {
	DB *SQL
}

func NewSQLRepository

func NewSQLRepository(db *SQL) SQLRepository

type SQLite added in v0.11.0

type SQLite struct {
	SQL
	Config config.SQLiteConfig
}

func NewSQLite added in v0.11.0

func NewSQLite(config config.SQLiteConfig) *SQLite

func (*SQLite) Connect added in v0.11.0

func (ds *SQLite) Connect(ctx context.Context) error

func (SQLite) Migrate added in v0.11.0

func (ds SQLite) Migrate(ctx context.Context, toVersion uint) error

func (SQLite) Ping added in v0.11.0

func (ds SQLite) Ping(ctx context.Context) error

func (SQLite) Type added in v0.11.0

func (ds SQLite) Type() string

type SqlQueryable

type SqlQueryable interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

type SqlTx

type SqlTx struct {
	Tx           *sqlx.Tx
	Hostname     string
	DatabaseName string
}

Encapsulates a sql transaction for an atomic write op

func (SqlTx) ExecContext

func (q SqlTx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (SqlTx) GetContext

func (q SqlTx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (SqlTx) NamedExecContext

func (q SqlTx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

func (SqlTx) PrepareContext

func (q SqlTx) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

func (SqlTx) QueryContext

func (q SqlTx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (SqlTx) QueryRowContext

func (q SqlTx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (SqlTx) SelectContext

func (q SqlTx) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

Jump to

Keyboard shortcuts

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