db

package
v0.0.0-...-2e936b0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDBNotFound        = errors.New("not found")
	ErrDBDuplicatedEntry = errors.New("duplicated entry")
	ErrUndefinedTable    = errors.New("undefined table")
)

Functions

func NamedExecContext

func NamedExecContext(ctx context.Context, log *logger.Logger, db sqlx.ExtContext, query string, data any) error

NamedExecContext is a helper function to execute a CUD operation where field replacement is necessary.

func NamedQuerySlice

func NamedQuerySlice[T any](ctx context.Context, log *logger.Logger, db sqlx.ExtContext, query string, data any, dest *[]T) error

NamedQuerySlice is a helper function to executing queries that return a collection of data to be unmarshalled into a slice where field replacement is necessary.

func NamedQueryStruct

func NamedQueryStruct(ctx context.Context, log *logger.Logger, db sqlx.ExtContext, query string, data any, dest any) error

NamedQueryStruct is used to return a single value to be unmarshalled into a struct type where field replacement is necessary.

func Open

func Open(cfg Config) (*sqlx.DB, error)

Open used to open a database connection based on the configuration.

func QuerySlice

func QuerySlice[T any](ctx context.Context, log *logger.Logger, db sqlx.ExtContext, query string, dest *[]T) error

QuerySlice is a helper function to executing queries that return a collection of data to be unmarshalled into a slice.

func StatusCheck

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

StatusCheck checks if it can successfully talk to the database.

Types

type Config

type Config struct {
	User         string
	Password     string
	Host         string
	Name         string
	MaxIdleConns int
	MaxOpenConns int
	DisableTLS   bool
}

Jump to

Keyboard shortcuts

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