db

package
v4.39.3 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: MIT Imports: 12 Imported by: 7

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 StoreTx

func StoreTx(ctx context.Context, tx pgx.Tx) context.Context

StoreTx stores given transaction in context

Types

type App added in v4.14.0

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

App of package

func New

func New(config Config, tracerApp tracer.App) (App, error)

New creates new App from Config

func (App) Bulk added in v4.14.0

func (a App) Bulk(ctx context.Context, fetcher func() ([]any, error), schema, table string, columns ...string) error

Bulk load data into schema and table by batch

func (App) Close added in v4.14.1

func (a App) Close()

Close the database connection

func (App) Create added in v4.14.0

func (a App) Create(ctx context.Context, query string, args ...any) (uint64, error)

Create execute query with a RETURNING id

func (App) DoAtomic added in v4.14.0

func (a App) DoAtomic(ctx context.Context, action func(context.Context) error) error

DoAtomic execute given action in a transactionnal context

func (App) Enabled added in v4.20.0

func (a App) Enabled() bool

Enabled check if sql.DB is provided

func (App) Exec added in v4.14.0

func (a App) Exec(ctx context.Context, query string, args ...any) error

Exec execute query with specified timeout, disregarding result

func (App) Get added in v4.14.0

func (a App) Get(ctx context.Context, scanner func(pgx.Row) error, query string, args ...any) error

Get execute single row query

func (App) List added in v4.14.0

func (a App) List(ctx context.Context, scanner func(pgx.Rows) error, query string, args ...any) (err error)

List execute multiple rows query

func (App) One added in v4.26.0

func (a App) One(ctx context.Context, query string, args ...any) error

One execute query with specified timeout, for exactly one row

func (App) Ping added in v4.14.0

func (a App) Ping() error

Ping indicate if database is ready or not

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

type Database added in v4.24.0

type Database interface {
	Ping(context.Context) error
	Close()
	Begin(context.Context) (pgx.Tx, error)
	Query(context.Context, string, ...any) (pgx.Rows, error)
	QueryRow(context.Context, string, ...any) pgx.Row
}

Database interface needed for working

Jump to

Keyboard shortcuts

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