dbx

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: BSD-3-Clause Imports: 13 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")
)

Functions

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 sql.DB and sql.Tx so they can be used interchangably.

func NewContext

func NewContext(cxt Context, l *log.Logger, d bool) Context

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

func (*DB) Wrap

func (d *DB) Wrap(cxt Context) Context

type Option

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

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

Directories

Path Synopsis
pql

Jump to

Keyboard shortcuts

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