db

package
v4.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 9 Imported by: 6 modules, 11 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoHost occurs when host is not provided in configuration
	ErrNoHost = errors.New("no host for database connection")

	// ErrNoTransaction occurs when no transaction is provided but needed
	ErrNoTransaction = errors.New("no transaction in context, please wrap with DoAtomic()")

	// ErrBulkEnded occurs when bulk creation is over
	ErrBulkEnded = errors.New("no more data to copy")

	// SQLTimeout when running queries
	SQLTimeout = time.Second * 5
)

Functions

func Bulk

func Bulk(ctx context.Context, feeder func(*sql.Stmt) error, schema, table string, columns ...string) error

Bulk load data into schema and table by batch

func Create

func Create(ctx context.Context, query string, args ...interface{}) (uint64, error)

Create execute query with a RETURNING id

func DoAtomic

func DoAtomic(ctx context.Context, db *sql.DB, action func(context.Context) error) error

DoAtomic execute given action in a transactionnal context

func Exec

func Exec(ctx context.Context, query string, args ...interface{}) error

Exec execute query with specified timeout, disregarding result

func Get

func Get(ctx context.Context, db *sql.DB, scanner func(*sql.Row) error, query string, args ...interface{}) error

Get execute single row query

func List

func List(ctx context.Context, db *sql.DB, scanner func(*sql.Rows) error, query string, args ...interface{}) error

List execute multiple rows query

func New

func New(config Config) (*sql.DB, error)

New creates new App from Config

func Ping

func Ping(db *sql.DB) bool

Ping indicate if database is ready or not

func StoreTx

func StoreTx(ctx context.Context, tx *sql.Tx) context.Context

StoreTx stores given transaction in context

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config of package

func Flags

func Flags(fs *flag.FlagSet, prefix string, overrides ...flags.Override) Config

Flags adds flags for configuring package

Jump to

Keyboard shortcuts

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