dbx

package
v0.0.0-...-1762b78 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTransactionStarted = errors.New("transaction has already been started")
	ErrDBType             = errors.New("wrong type of DB interface")
)

Functions

func BeginTx

func BeginTx(ctx context.Context, db DB) (*sqlx.Tx, context.Context, error)

BeginTx start transaction Error ErrTransactionStarted Error ErrDBType

func JsonbToBytes

func JsonbToBytes(jsonb Jsonb) []byte

func Transactional

func Transactional(ctx context.Context, db *sqlx.DB, wrappedFunc func(ctx context.Context) error) (err error)

Transactional run wrapped func in transaction

Types

type DB

type DB interface {
	// GetContext using this DB.
	// Any placeholder parameters are replaced with supplied args.
	// An error is returned if the result set is empty.
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	// SelectContext using this DB.
	// Any placeholder parameters are replaced with supplied args.
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	// Rebind transforms a query from QUESTION to the DB driver's bindvar type.
	Rebind(query string) string
	// BindNamed binds a query using the DB driver's bindvar type.
	BindNamed(query string, arg interface{}) (string, []interface{}, error)
	// NamedExecContext using this DB.
	// Any named placeholder parameters are replaced with fields from arg.
	NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
	// ExecContext executes a query without returning any rows.
	// The args are for any placeholder parameters in the query.
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	// QueryxContext queries the database and returns an *sqlx.Rows.
	// Any placeholder parameters are replaced with supplied args.
	QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
}

DB interface is implemented by sqlx.DB and sqlx.Tx so it can be used either by db or transaction instance

func Connection

func Connection(ctx context.Context, db DB) DB

Connection get connection (*sqlx.db | *sqlx.tx) from the context

type Jsonb

type Jsonb driver.Value

Jump to

Keyboard shortcuts

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