db

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateKey is a constraint violation error.
	ErrDuplicateKey = errors.New("duplicate key value violates table constraint")

	// ErrRecordNotFound is returned when a record is not found.
	ErrRecordNotFound = sql.ErrNoRows
)
View Source
var ContextKey = struct{ string }{"db"}

ContextKey is the key used to store the database in the context.

Functions

func WithContext

func WithContext(ctx context.Context, db *DB) context.Context

WithContext returns a new context with the database.

func WrapError

func WrapError(err error) error

WrapError is a convenient function that unite various database driver errors to consistent errors.

Types

type DB

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

DB is the interface for a Soft Serve database.

func FromContext

func FromContext(ctx context.Context) *DB

FromContext returns the database from the context.

func Open

func Open(ctx context.Context, driverName string, dsn string) (*DB, error)

Open opens a database connection.

func (*DB) Close

func (d *DB) Close() error

Close implements db.DB.

func (*DB) Exec

func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error)

Exec is a wrapper around sqlx.Exec that logs the query and arguments.

func (*DB) ExecContext

func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext is a wrapper around sqlx.ExecContext that logs the query and arguments.

func (*DB) Get

func (d *DB) Get(dest interface{}, query string, args ...interface{}) error

Get is a wrapper around sqlx.Get that logs the query and arguments.

func (*DB) GetContext

func (d *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetContext is a wrapper around sqlx.GetContext that logs the query and arguments.

func (*DB) QueryRowx

func (d *DB) QueryRowx(query string, args ...interface{}) *sqlx.Row

QueryRowx is a wrapper around sqlx.QueryRowx that logs the query and arguments.

func (*DB) QueryRowxContext

func (d *DB) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row

QueryRowxContext is a wrapper around sqlx.QueryRowxContext that logs the query and arguments.

func (*DB) Queryx

func (d *DB) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

Queryx is a wrapper around sqlx.Queryx that logs the query and arguments.

func (*DB) QueryxContext

func (d *DB) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)

QueryxContext is a wrapper around sqlx.QueryxContext that logs the query and arguments.

func (*DB) Select

func (d *DB) Select(dest interface{}, query string, args ...interface{}) error

Select is a wrapper around sqlx.Select that logs the query and arguments.

func (*DB) SelectContext

func (d *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

SelectContext is a wrapper around sqlx.SelectContext that logs the query and arguments.

func (*DB) Transaction

func (d *DB) Transaction(fn func(tx *Tx) error) error

Transaction implements db.DB.

func (*DB) TransactionContext

func (d *DB) TransactionContext(ctx context.Context, fn func(tx *Tx) error) error

TransactionContext implements db.DB.

type Handler

type Handler interface {
	Rebind(string) string

	Select(interface{}, string, ...interface{}) error
	Get(interface{}, string, ...interface{}) error
	Queryx(string, ...interface{}) (*sqlx.Rows, error)
	QueryRowx(string, ...interface{}) *sqlx.Row
	Exec(string, ...interface{}) (sql.Result, error)

	SelectContext(context.Context, interface{}, string, ...interface{}) error
	GetContext(context.Context, interface{}, string, ...interface{}) error
	QueryxContext(context.Context, string, ...interface{}) (*sqlx.Rows, error)
	QueryRowxContext(context.Context, string, ...interface{}) *sqlx.Row
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
}

Handler is a database handler.

type Tx

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

Tx is a database transaction.

func (*Tx) Exec

func (t *Tx) Exec(query string, args ...interface{}) (sql.Result, error)

Exec is a wrapper around sqlx.Exec that logs the query and arguments.

func (*Tx) ExecContext

func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext is a wrapper around sqlx.ExecContext that logs the query and arguments.

func (*Tx) Get

func (t *Tx) Get(dest interface{}, query string, args ...interface{}) error

Get is a wrapper around sqlx.Get that logs the query and arguments.

func (*Tx) GetContext

func (t *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetContext is a wrapper around sqlx.GetContext that logs the query and arguments.

func (*Tx) QueryRowx

func (t *Tx) QueryRowx(query string, args ...interface{}) *sqlx.Row

QueryRowx is a wrapper around sqlx.QueryRowx that logs the query and arguments.

func (*Tx) QueryRowxContext

func (t *Tx) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row

QueryRowxContext is a wrapper around sqlx.QueryRowxContext that logs the query and arguments.

func (*Tx) Queryx

func (t *Tx) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

Queryx is a wrapper around sqlx.Queryx that logs the query and arguments.

func (*Tx) QueryxContext

func (t *Tx) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)

QueryxContext is a wrapper around sqlx.QueryxContext that logs the query and arguments.

func (*Tx) Select

func (t *Tx) Select(dest interface{}, query string, args ...interface{}) error

Select is a wrapper around sqlx.Select that logs the query and arguments.

func (*Tx) SelectContext

func (t *Tx) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

SelectContext is a wrapper around sqlx.SelectContext that logs the query and arguments.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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