Documentation ¶
Overview ¶
Package sqldb provides support for access the database.
Index ¶
- Variables
- func ExecContext(ctx context.Context, db sqlx.ExtContext, query string) error
- func GetExtContext(tx CommitRollbacker) (sqlx.ExtContext, error)
- func NamedExecContext(ctx context.Context, db sqlx.ExtContext, query string, data any) (err error)
- func NamedQuerySlice[T any](ctx context.Context, db sqlx.ExtContext, query string, data any, dest *[]T) error
- func NamedQuerySliceUsingIn[T any](ctx context.Context, db sqlx.ExtContext, query string, data any, dest *[]T) error
- func NamedQueryStruct(ctx context.Context, db sqlx.ExtContext, query string, data any, dest any) error
- func NamedQueryStructUsingIn(ctx context.Context, db sqlx.ExtContext, query string, data any, dest any) error
- func Open(cfg Config) (*sqlx.DB, error)
- func QueryMap(ctx context.Context, db sqlx.ExtContext, query string, dest *[]map[string]any) (err error)
- func QuerySlice[T any](ctx context.Context, db sqlx.ExtContext, query string, dest *[]T) error
- func QueryStruct(ctx context.Context, db sqlx.ExtContext, query string, dest any) error
- func StatusCheck(ctx context.Context, db *sqlx.DB) error
- type Beginner
- type CommitRollbacker
- type Config
- type DBBeginner
Constants ¶
This section is empty.
Variables ¶
var ( ErrDBNotFound = sql.ErrNoRows ErrDBDuplicatedEntry = errors.New("duplicated entry") ErrUndefinedTable = errors.New("undefined table") )
Set of error variables for CRUD operations.
Functions ¶
func ExecContext ¶
ExecContext is a helper function to execute a CUD operation with logging and tracing.
func GetExtContext ¶
func GetExtContext(tx CommitRollbacker) (sqlx.ExtContext, error)
GetExtContext is a helper function that extracts the sqlx value from the domain transactor interface for transactional use.
func NamedExecContext ¶
NamedExecContext is a helper function to execute a CUD operation with logging and tracing where field replacement is necessary.
func NamedQuerySlice ¶
func NamedQuerySlice[T any](ctx context.Context, db sqlx.ExtContext, query string, data any, dest *[]T) error
NamedQuerySlice is a helper function for executing queries that return a collection of data to be unmarshalled into a slice where field replacement is necessary.
func NamedQuerySliceUsingIn ¶
func NamedQuerySliceUsingIn[T any](ctx context.Context, db sqlx.ExtContext, query string, data any, dest *[]T) error
NamedQuerySliceUsingIn is a helper function for executing queries that return a collection of data to be unmarshalled into a slice where field replacement is necessary. Use this if the query has an IN clause.
func NamedQueryStruct ¶
func NamedQueryStruct(ctx context.Context, db sqlx.ExtContext, query string, data any, dest any) error
NamedQueryStruct is a helper function for executing queries that return a single value to be unmarshalled into a struct type where field replacement is necessary.
func NamedQueryStructUsingIn ¶
func NamedQueryStructUsingIn(ctx context.Context, db sqlx.ExtContext, query string, data any, dest any) error
NamedQueryStructUsingIn is a helper function for executing queries that return a single value to be unmarshalled into a struct type where field replacement is necessary. Use this if the query has an IN clause.
func QueryMap ¶
func QueryMap(ctx context.Context, db sqlx.ExtContext, query string, dest *[]map[string]any) (err error)
QueryMap executes a query and places results into a map.
func QuerySlice ¶
QuerySlice is a helper function for executing queries that return a collection of data to be unmarshalled into a slice.
func QueryStruct ¶
QueryStruct is a helper function for executing queries that return a single value to be unmarshalled into a struct type where field replacement is necessary.
Types ¶
type Beginner ¶
type Beginner interface {
Begin() (CommitRollbacker, error)
}
Beginner represents a value that can begin a transaction.
type CommitRollbacker ¶
CommitRollbacker represents a value that can commit or rollback a transaction.
type Config ¶
type Config struct { User string Password string Host string Name string Schema string MaxIdleConns int MaxOpenConns int DisableTLS bool }
Config is the required properties to use the database.
type DBBeginner ¶
type DBBeginner struct {
// contains filtered or unexported fields
}
DBBeginner implements the Beginner interface,
func NewBeginner ¶
func NewBeginner(sqlxDB *sqlx.DB) *DBBeginner
NewBeginner constructs a value that implements the beginner interface.
func (*DBBeginner) Begin ¶
func (db *DBBeginner) Begin() (CommitRollbacker, error)
Begin implements the Beginner interface and returns a concrete value that implements the CommitRollbacker interface.