Documentation ¶
Overview ¶
Package database provides support for access the database.
Index ¶
- Variables
- func NamedExecContext(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, ...) error
- func NamedQuerySlice(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, ...) error
- func NamedQueryStruct(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, ...) error
- func Open(cfg Config) (*sqlx.DB, error)
- func StatusCheck(ctx context.Context, db *sqlx.DB) error
- func WithinTran(ctx context.Context, log *zap.SugaredLogger, db Transactor, ...) error
- type Config
- type Transactor
Constants ¶
This section is empty.
Variables ¶
var (
ErrDBNotFound = errors.New("not found")
)
Set of error variables for CRUD operations.
Functions ¶
func NamedExecContext ¶
func NamedExecContext(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, data interface{}) error
NamedExecContext is a helper function to execute a CUD operation with logging and tracing.
func NamedQuerySlice ¶
func NamedQuerySlice(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, data interface{}, dest interface{}) error
NamedQuerySlice is a helper function for executing queries that return a collection of data to be unmarshaled into a slice.
func NamedQueryStruct ¶
func NamedQueryStruct(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, data interface{}, dest interface{}) error
NamedQueryStruct is a helper function for executing queries that return a single value to be unmarshalled into a struct type.
func StatusCheck ¶
StatusCheck returns nil if it can successfully talk to the database. It returns a non-nil error otherwise.
func WithinTran ¶
func WithinTran(ctx context.Context, log *zap.SugaredLogger, db Transactor, fn func(sqlx.ExtContext) error) error
WithinTran runs passed function and do commit/rollback at the end.
Types ¶
type Config ¶
type Config struct { User string Password string Host string Name string MaxIdleConns int MaxOpenConns int DisableTLS bool }
Config is the required properties to use the database.
type Transactor ¶
Transactor interface needed to begin transaction.