Documentation
¶
Overview ¶
Package dbx implements a small set of rather opinionated utilities for dealing with databases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrDatabaseTooNew = errors.New("database may be newer than migrations available in this binary") ErrNoDSN = errors.New("no data source name given") )
errors
Functions ¶
Types ¶
type DriverForFunc ¶
DriverForFunc returns (driver, migrateDBName, error).
type EntityQueryRowxFunc ¶
EntityQueryRowxFunc is useful for queries that take some entity and return an entity of the same type. For instance when using RETURNING in SQL statement.
func NewEntityQueryRowxFunc ¶
func NewEntityQueryRowxFunc[T any](db *sqlx.DB, stmt string) EntityQueryRowxFunc[T]
NewEntityQueryRowxFunc creates a new EntityQueryRowxFunc
type ExecFunc ¶
ExecFunc is useful for very simple operations like DELETE with positional arguments.
type NamedExecFunc ¶
NamedExecFunc is useful for create, update etc where you send an entity in and just want a Result and error back.
func NewNamedExecFunc ¶
func NewNamedExecFunc[T any](db *sqlx.DB, stmt string) NamedExecFunc[T]
NewNamedExecFunc creates a new NamedExecFunc
type Option ¶
type Option func(*config) error
Option is a configuration option callback type
func WithMigrationDriver ¶
func WithMigrationDriver(sqlDriverName string, migrateName string, create func(*sql.DB) (database.Driver, error)) Option
WithMigrationDriver is provided in case you want to use SQL databases beyond those provided in the default config (sqlite, postgres, mysql).
func WithMigrations ¶
WithMigrations sets the migrations filesystem and path within that filesystem. You can either pass an embed.FS or a fs.FS for a OS filesystem path using os.DirFS(path).
func WithPragmas ¶
WithPragmas appends pragmas to the config
type QueryRowxFunc ¶
QueryRowxFunc is useful for queries that return one row and takes positional arguments. For instance get operations on a single row.
func NewQueryRowxFunc ¶
func NewQueryRowxFunc[T any](db *sqlx.DB, stmt string) QueryRowxFunc[T]
NewQueryRowxFunc creates a new QueryRowxFunc
type QueryxIteratorFunc ¶
QueryxIteratorFunc is useful for queries that return (poitentially) large result sets and you want to be able to stream the result.
func NewQueryxIteratorFunc ¶
func NewQueryxIteratorFunc[T any](db *sqlx.DB, stmt string) QueryxIteratorFunc[T]
NewQueryxIteratorFunc creates a new QueryxIteratorFunc
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result holds the outcome of a mutating operation
func (Result) LastInsertID ¶
LastInsertID returns the last insert ID if available
func (Result) RowsAffected ¶
RowsAffected returns the number of rows affected if available
type SelectFunc ¶
SelectFunc is useful for when you perform selects and you know the result set will be small or at least bounded to acceptable size.
func NewSelectFunc ¶
func NewSelectFunc[T any](db *sqlx.DB, stmt string) SelectFunc[T]
NewSelectFunc creates a new SelectFunc