db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected = errors.New("not connected to the database")
	ErrReadOnly     = errors.New("connected in readonly mode - only readonly transactions allowed")
	ErrNotfound     = errors.New("record not found or no rows returned")
)

Functions

func BeginTx

func BeginTx(ctx context.Context, opts *sql.TxOptions) (tx *sql.Tx, err error)

BeginTx creates a transaction with the connected dtabase; errors if not connected.

func Close

func Close() (err error)

Close the database safely and allow reconnect after close.

func Connect

func Connect(conf config.DatabaseConfig) (err error)

Connect to the Postgres stabase specified by theDSN. Connecting in read-only mode is is managed by the package, not by the database. Multiple or concurrent calls to Connect will be ignored even if a different configuration is passed.

func Mock

func Mock() sqlmock.Sqlmock

Mock returns the sql mock object for use in unit testing

func Prep added in v0.4.0

func Prep(query string, args ...any) (string, []any)

Prep converts named query arguments into positional arguments for postgres queries.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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