dbx

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: BSD-3-Clause Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound           = errors.New("Not found")
	ErrImmutable          = errors.New("Immutable")
	ErrInvalidField       = errors.New("Invalid field")
	ErrInvalidKeyCount    = errors.New("Invalid primary key count")
	ErrNotAPointer        = errors.New("Not a pointer")
	ErrNotAStruct         = errors.New("Not a struct")
	ErrMissingField       = errors.New("Missing field")
	ErrDriverNotSupported = errors.New("Driver not supported")
)

Functions

func IsTx added in v1.11.0

func IsTx(cxt Context) bool

Determine if a context is implemented by a transaction or not

func Now

func Now() time.Time

Obtain the current timestamp truncated to milliseconds, which is the most precision most databases (including Postgres) support.

Types

type Context

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

An SQL context. This defines a unified type that encompasses the basic methods of sqlx.DB and sqlx.Tx so they can be used interchangably.

type DB

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

func New

func New(dsn string, opts ...Option) (*DB, error)

func (*DB) Exec

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

func (*DB) Migrate

func (d *DB) Migrate(rc string) (upgrade.Results, error)

func (*DB) Monitor added in v1.8.0

func (d *DB) Monitor(cxt context.Context, iv time.Duration) <-chan error

func (*DB) Query

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

func (*DB) QueryRow

func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row

func (*DB) QueryRowx

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

func (*DB) Queryx

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

func (*DB) Transaction

func (d *DB) Transaction(h TransactionHandler) error

Execute in a transaction. A transaction is created and the handler is invoked. If the handler returns a non-nil error the transaction is rolled back, otherwise the transaction is committed.

type Option

type Option func(d *DB) (*DB, error)

func WithConnMaxIdleTime added in v1.10.0

func WithConnMaxIdleTime(v time.Duration) Option

func WithConnMaxLifetime added in v1.10.0

func WithConnMaxLifetime(v time.Duration) Option

func WithDebug

func WithDebug(on bool) Option

func WithLogger

func WithLogger(l *log.Logger) Option

func WithMaxIdleConns

func WithMaxIdleConns(v int) Option

func WithMaxOpenConns

func WithMaxOpenConns(v int) Option

type TransactionHandler

type TransactionHandler func(cxt Context) error

type Tx added in v1.11.0

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

A transactional SQL context. This defines a unified type that encompasses the basic methods of sqlx.Tx and other theoretical transaction implementsions so that they can be used interchangably.

Directories

Path Synopsis
DEPRECATED: everything in this package is deprecated and will be removed in a future release.
DEPRECATED: everything in this package is deprecated and will be removed in a future release.
pql
The `query` package replaces the `filter` package and improves support for both read- and write-oriented configuration options.
The `query` package replaces the `filter` package and improves support for both read- and write-oriented configuration options.

Jump to

Keyboard shortcuts

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