Documentation ¶
Overview ¶
Package sqx provides general purpose extensions to database/sql.
It is intended to seamlessly wrap database/sql and provide convenience methods which are useful in the development of database driven applications. None of the underlying database/sql methods are changed. Instead all extended behavior is implemented through new methods defined on wrapper types.
Additions include scanning into structs, named query support, rebinding queries for different drivers, convenient shorthands for common error handling and more.
This is package is forked from github.com/jmoiron/sqlx
Index ¶
- Variables
- func BindDriver(driverName string, binder Binder)
- func Get(q Queryerx, dest any, query string, args ...any) error
- func GetContext(ctx context.Context, q QueryerContext, dest any, query string, args ...any) error
- func MapScan(r ColScanner, dest map[string]any) error
- func MustExec(e Execer, query string, args ...any) sql.Result
- func MustExecContext(ctx context.Context, e ExecerContext, query string, args ...any) sql.Result
- func Named(query string, arg any) (string, []any, error)
- func NamedExecContext(ctx context.Context, e ExtContext, query string, arg any) (sql.Result, error)
- func Select(q Queryerx, dest any, query string, args ...any) error
- func SelectContext(ctx context.Context, q QueryerContext, dest any, query string, args ...any) error
- func SliceScan(r ColScanner) ([]any, error)
- func StructScan(rows rowsi, dest any) error
- func Transaction(db Beginxer, fc func(tx *Tx) error) (err error)
- func Transactionx(db BeginTxxer, ctx context.Context, opts *sql.TxOptions, fc func(tx *Tx) error) (err error)
- type BeginTxxer
- type Beginxer
- type Bind
- type Binder
- type ColScanner
- type Conn
- func (c *Conn) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (ext *Conn) Binder() Binder
- func (ext *Conn) DriverName() string
- func (c *Conn) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (ext *Conn) IsUnsafe() bool
- func (ext *Conn) Mapper() *ref.Mapper
- func (c *Conn) PreparexContext(ctx context.Context, query string) (*Stmt, error)
- func (c *Conn) QueryRowxContext(ctx context.Context, query string, args ...any) *Row
- func (c *Conn) QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error)
- func (ext *Conn) Quote(s string) string
- func (ext *Conn) Quoter() sqx.Quoter
- func (ext *Conn) Rebind(query string) string
- func (c *Conn) SelectContext(ctx context.Context, dest any, query string, args ...any) error
- func (ext *Conn) SupportLastInsertID() bool
- func (c *Conn) Transactionx(ctx context.Context, opts *sql.TxOptions, fc func(tx *Tx) error) (err error)
- type DB
- func Connect(driverName, dataSourceName string) (*DB, error)
- func ConnectContext(ctx context.Context, driverName, dataSourceName string) (*DB, error)
- func MustConnect(driverName, dataSourceName string) *DB
- func MustOpen(driverName, dataSourceName string) *DB
- func NewDB(db *sql.DB, driverName string) *DB
- func Open(driverName, dataSourceName string) (*DB, error)
- func (db *DB) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *DB) Beginx() (*Tx, error)
- func (db *DB) BindNamed(query string, arg any) (string, []any, error)
- func (ext *DB) Binder() Binder
- func (db *DB) Connx(ctx context.Context) (*Conn, error)
- func (ext *DB) DriverName() string
- func (db *DB) Get(dest any, query string, args ...any) error
- func (db *DB) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (ext *DB) IsUnsafe() bool
- func (ext *DB) Mapper() *ref.Mapper
- func (db *DB) MapperFunc(mf func(string) string)
- func (db *DB) MustBegin() *Tx
- func (db *DB) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *Tx
- func (db *DB) MustExec(query string, args ...any) sql.Result
- func (db *DB) MustExecContext(ctx context.Context, query string, args ...any) sql.Result
- func (db *DB) NamedExec(query string, arg any) (sql.Result, error)
- func (db *DB) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
- func (db *DB) NamedQuery(query string, arg any) (*Rows, error)
- func (db *DB) NamedQueryContext(ctx context.Context, query string, arg any) (*Rows, error)
- func (db *DB) NamedQueryRow(query string, arg any) *Row
- func (db *DB) PrepareNamed(query string) (*NamedStmt, error)
- func (db *DB) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)
- func (db *DB) Preparex(query string) (*Stmt, error)
- func (db *DB) PreparexContext(ctx context.Context, query string) (*Stmt, error)
- func (db *DB) QueryRowx(query string, args ...any) *Row
- func (db *DB) QueryRowxContext(ctx context.Context, query string, args ...any) *Row
- func (db *DB) Queryx(query string, args ...any) (*Rows, error)
- func (db *DB) QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error)
- func (ext *DB) Quote(s string) string
- func (ext *DB) Quoter() sqx.Quoter
- func (ext *DB) Rebind(query string) string
- func (db *DB) Select(dest any, query string, args ...any) error
- func (db *DB) SelectContext(ctx context.Context, dest any, query string, args ...any) error
- func (ext *DB) SupportLastInsertID() bool
- func (db *DB) Transaction(fc func(tx *Tx) error) (err error)
- func (db *DB) Transactionx(ctx context.Context, opts *sql.TxOptions, fc func(tx *Tx) error) (err error)
- func (db *DB) Unsafe() *DB
- type Execer
- type ExecerContext
- type ExtContext
- type NamedExecer
- type NamedQueryer
- type NamedStmt
- func (n *NamedStmt) Close() error
- func (n *NamedStmt) Exec(arg any) (sql.Result, error)
- func (n *NamedStmt) ExecContext(ctx context.Context, arg any) (sql.Result, error)
- func (n *NamedStmt) Get(dest any, arg any) error
- func (n *NamedStmt) GetContext(ctx context.Context, dest any, arg any) error
- func (n *NamedStmt) IsUnsafe() bool
- func (n *NamedStmt) MustExec(arg any) sql.Result
- func (n *NamedStmt) MustExecContext(ctx context.Context, arg any) sql.Result
- func (n *NamedStmt) Query(arg any) (*sql.Rows, error)
- func (n *NamedStmt) QueryContext(ctx context.Context, arg any) (*sql.Rows, error)
- func (n *NamedStmt) QueryRow(arg any) *Row
- func (n *NamedStmt) QueryRowContext(ctx context.Context, arg any) *Row
- func (n *NamedStmt) QueryRowx(arg any) *Row
- func (n *NamedStmt) QueryRowxContext(ctx context.Context, arg any) *Row
- func (n *NamedStmt) Queryx(arg any) (*Rows, error)
- func (n *NamedStmt) QueryxContext(ctx context.Context, arg any) (*Rows, error)
- func (n *NamedStmt) Select(dest any, arg any) error
- func (n *NamedStmt) SelectContext(ctx context.Context, dest any, arg any) error
- func (n *NamedStmt) Unsafe() *NamedStmt
- type Preparer
- type PreparerContext
- type Preparerx
- type PreparerxContext
- type Queryer
- type QueryerContext
- type Queryerx
- type Result
- type Row
- func (ext *Row) Binder() Binder
- func (r *Row) ColumnTypes() ([]*sql.ColumnType, error)
- func (r *Row) Columns() ([]string, error)
- func (ext *Row) DriverName() string
- func (r *Row) Err() error
- func (ext *Row) IsUnsafe() bool
- func (r *Row) MapScan(dest map[string]any) error
- func (ext *Row) Mapper() *ref.Mapper
- func (ext *Row) Quote(s string) string
- func (ext *Row) Quoter() sqx.Quoter
- func (ext *Row) Rebind(query string) string
- func (r *Row) Scan(dest ...any) error
- func (r *Row) SliceScan() ([]any, error)
- func (r *Row) StructScan(dest any) error
- func (ext *Row) SupportLastInsertID() bool
- type Rows
- func (ext *Rows) Binder() Binder
- func (ext *Rows) DriverName() string
- func (ext *Rows) IsUnsafe() bool
- func (r *Rows) MapScan(dest map[string]any) error
- func (ext *Rows) Mapper() *ref.Mapper
- func (ext *Rows) Quote(s string) string
- func (ext *Rows) Quoter() sqx.Quoter
- func (ext *Rows) Rebind(query string) string
- func (r *Rows) SliceScan() ([]any, error)
- func (r *Rows) StructScan(dest any) error
- func (ext *Rows) SupportLastInsertID() bool
- type Selector
- type Sql
- type Sqlx
- type Stmt
- func (ext *Stmt) Binder() Binder
- func (ext *Stmt) DriverName() string
- func (s *Stmt) Get(dest any, args ...any) error
- func (s *Stmt) GetContext(ctx context.Context, dest any, args ...any) error
- func (ext *Stmt) IsUnsafe() bool
- func (ext *Stmt) Mapper() *ref.Mapper
- func (s *Stmt) MustExec(args ...any) sql.Result
- func (s *Stmt) MustExecContext(ctx context.Context, args ...any) sql.Result
- func (s *Stmt) QueryRowx(args ...any) *Row
- func (s *Stmt) QueryRowxContext(ctx context.Context, args ...any) *Row
- func (s *Stmt) Queryx(args ...any) (*Rows, error)
- func (s *Stmt) QueryxContext(ctx context.Context, args ...any) (*Rows, error)
- func (ext *Stmt) Quote(s string) string
- func (ext *Stmt) Quoter() sqx.Quoter
- func (ext *Stmt) Rebind(query string) string
- func (s *Stmt) Select(dest any, args ...any) error
- func (s *Stmt) SelectContext(ctx context.Context, dest any, args ...any) error
- func (ext *Stmt) SupportLastInsertID() bool
- func (s *Stmt) Unsafe() *Stmt
- type Supporter
- type Tx
- func (tx *Tx) BindNamed(query string, arg any) (string, []any, error)
- func (ext *Tx) Binder() Binder
- func (ext *Tx) DriverName() string
- func (tx *Tx) Get(dest any, query string, args ...any) error
- func (tx *Tx) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (ext *Tx) IsUnsafe() bool
- func (ext *Tx) Mapper() *ref.Mapper
- func (tx *Tx) MustExec(query string, args ...any) sql.Result
- func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...any) sql.Result
- func (tx *Tx) NamedExec(query string, arg any) (sql.Result, error)
- func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
- func (tx *Tx) NamedQuery(query string, arg any) (*Rows, error)
- func (tx *Tx) NamedQueryRow(query string, arg any) *Row
- func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt
- func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt
- func (tx *Tx) PrepareNamed(query string) (*NamedStmt, error)
- func (tx *Tx) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)
- func (tx *Tx) Preparex(query string) (*Stmt, error)
- func (tx *Tx) PreparexContext(ctx context.Context, query string) (*Stmt, error)
- func (tx *Tx) QueryRowx(query string, args ...any) *Row
- func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...any) *Row
- func (tx *Tx) Queryx(query string, args ...any) (*Rows, error)
- func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error)
- func (ext *Tx) Quote(s string) string
- func (ext *Tx) Quoter() sqx.Quoter
- func (ext *Tx) Rebind(query string) string
- func (tx *Tx) Select(dest any, query string, args ...any) error
- func (tx *Tx) SelectContext(ctx context.Context, dest any, query string, args ...any) error
- func (tx *Tx) Stmtx(stmt any) *Stmt
- func (tx *Tx) StmtxContext(ctx context.Context, stmt any) *Stmt
- func (ext *Tx) SupportLastInsertID() bool
- func (tx *Tx) Unsafe() *Tx
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnDone = sql.ErrConnDone ErrNoRows = sql.ErrNoRows ErrTxDone = sql.ErrTxDone )
var NameMapper = ref.NewMapperFunc("db", str.SnakeCase)
NameMapper is used to map column names to struct field names. By default, it uses str.SnakeCase to snakecase struct field names. It can be set to whatever you want, but it is encouraged to be set before sqx is used as name-to-field mappings are cached after first use on a type.
Functions ¶
func BindDriver ¶
BindDriver sets the Binder for driverName to binder.
func Get ¶
Get does a QueryRow using the provided Queryer, and scans the resulting row to dest. If dest is scannable, the result must only have one column. Otherwise, StructScan is used. Get will return ErrNoRows like row.Scan would. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func GetContext ¶
GetContext does a QueryRow using the provided Queryer, and scans the resulting row to dest. If dest is scannable, the result must only have one column. Otherwise, StructScan is used. Get will return ErrNoRows like row.Scan would. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func MapScan ¶
func MapScan(r ColScanner, dest map[string]any) error
MapScan scans a single Row into the dest map[string]any. Use this to get results for SQL that might not be under your control (for instance, if you're building an interface for an SQL server that executes SQL from input). Please do not use this as a primary interface! This will modify the map sent to it in place, so reuse the same map with care. Columns which occur more than once in the result will overwrite each other!
func MustExec ¶
MustExec execs the query using e and panics if there was an error. Any placeholder parameters are replaced with supplied args.
func MustExecContext ¶
MustExecContext execs the query using e and panics if there was an error. Any placeholder parameters are replaced with supplied args.
func Named ¶
Named takes a query using named parameters and an argument and returns a new query with a list of args that can be executed by a database. The return value uses the `?` bindvar.
func NamedExecContext ¶
NamedExecContext uses BindStruct to get a query executable by the driver and then runs Exec on the result. Returns an error from the binding or the query execution itself.
func Select ¶
Select executes a query using the provided Queryer, and StructScans each row into dest, which must be a slice. If the slice elements are scannable, then the result set must have only one column. Otherwise, StructScan is used. The *sql.Rows are closed automatically. Any placeholder parameters are replaced with supplied args.
func SelectContext ¶
func SelectContext(ctx context.Context, q QueryerContext, dest any, query string, args ...any) error
SelectContext executes a query using the provided Queryer, and StructScans each row into dest, which must be a slice. If the slice elements are scannable, then the result set must have only one column. Otherwise, StructScan is used. The *sql.Rows are closed automatically. Any placeholder parameters are replaced with supplied args.
func SliceScan ¶
func SliceScan(r ColScanner) ([]any, error)
SliceScan a row, returning a []any with values similar to MapScan. This function is primarily intended for use where the number of columns is not known. Because you can pass an []any directly to Scan, it's recommended that you do that as it will not have to allocate new slices per row.
func StructScan ¶
StructScan all rows from an sql.Rows or an sqx.Rows into the dest slice. StructScan will scan in the entire rows result, so if you do not want to allocate structs for the entire result, use Queryx and see sqx.Rows.StructScan. If rows is sqx.Rows, it will use its mapper, otherwise it will use the default.
func Transaction ¶
Transaction start a transaction as a block, return error will rollback, otherwise to commit. Transaction executes an arbitrary number of commands in fc within a transaction. On success the changes are committed; if an error occurs they are rolled back.
func Transactionx ¶
func Transactionx(db BeginTxxer, ctx context.Context, opts *sql.TxOptions, fc func(tx *Tx) error) (err error)
Transactionx start a transaction as a block, return error will rollback, otherwise to commit. Transaction executes an arbitrary number of commands in fc within a transaction. On success the changes are committed; if an error occurs they are rolled back.
Types ¶
type BeginTxxer ¶
BeginTxxer is an interface used by Transactionx
type Binder ¶
type Binder int
Binder types supported by Rebind, BindMap and BindStruct.
type ColScanner ¶
ColScanner is an interface used by MapScan and SliceScan
type Conn ¶
Conn is a wrapper around sql.Conn with extra functionality
func (*Conn) BeginTxx ¶
BeginTxx begins a transaction and returns an *sqx.Tx instead of an *sql.Tx.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginxContext is canceled.
func (*Conn) Binder ¶
func (ext *Conn) Binder() Binder
Binder returns the binder by driverName passed to the Open function for this DB.
func (*Conn) DriverName ¶
func (ext *Conn) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Conn) GetContext ¶
GetContext using this Conn. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Conn) PreparexContext ¶
PreparexContext returns an sqx.Stmt instead of a sql.Stmt.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Conn) QueryRowxContext ¶
QueryRowxContext queries the database and returns an *sqx.Row. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryxContext ¶
QueryxContext queries the database and returns an *sqx.Rows. Any placeholder parameters are replaced with supplied args.
func (*Conn) Quoter ¶
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*Conn) SelectContext ¶
SelectContext using this Conn. Any placeholder parameters are replaced with supplied args.
func (*Conn) SupportLastInsertID ¶
func (ext *Conn) SupportLastInsertID() bool
SupportRetuning check sql driver support "RETUNING"
func (*Conn) Transactionx ¶
func (c *Conn) Transactionx(ctx context.Context, opts *sql.TxOptions, fc func(tx *Tx) error) (err error)
Transactionx start a transaction as a block, return error will rollback, otherwise to commit. Transaction executes an arbitrary number of commands in fc within a transaction. On success the changes are committed; if an error occurs they are rolled back.
type DB ¶
DB is a wrapper around sql.DB which keeps track of the driverName upon Open, used mostly to automatically bind named queries using the right bindvars.
func ConnectContext ¶
ConnectContext to a database and verify with a ping.
func MustConnect ¶
MustConnect connects to a database and panics on error.
func MustOpen ¶
MustOpen is the same as sql.Open, but returns an *sqx.DB instead and panics on error.
func NewDB ¶
NewDB returns a new sqx DB wrapper for a pre-existing *sql.DB. The driverName of the original database is required for named query support.
func (*DB) BeginTxx ¶
BeginTxx begins a transaction and returns an *sqx.Tx instead of an *sql.Tx.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginxContext is canceled.
func (*DB) Binder ¶
func (ext *DB) Binder() Binder
Binder returns the binder by driverName passed to the Open function for this DB.
func (*DB) DriverName ¶
func (ext *DB) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*DB) Get ¶
Get using this DB. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*DB) GetContext ¶
GetContext using this DB. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*DB) MapperFunc ¶
MapperFunc sets a new mapper for this db using the default sqx struct tag and the provided mapper function.
func (*DB) MustBegin ¶
MustBegin starts a transaction, and panics on error. Returns an *sqx.Tx instead of an *sql.Tx.
func (*DB) MustBeginTx ¶
MustBeginTx starts a transaction, and panics on error. Returns an *sqx.Tx instead of an *sql.Tx.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to MustBeginContext is canceled.
func (*DB) MustExec ¶
MustExec (panic) runs MustExec using this database. Any placeholder parameters are replaced with supplied args.
func (*DB) MustExecContext ¶
MustExecContext (panic) runs MustExec using this database. Any placeholder parameters are replaced with supplied args.
func (*DB) NamedExec ¶
NamedExec using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedExecContext ¶
NamedExecContext using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedQuery ¶
NamedQuery using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedQueryContext ¶
NamedQueryContext using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedQueryRow ¶
NamedQueryRow using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) PrepareNamed ¶
PrepareNamed returns an sqx.NamedStmt
func (*DB) PrepareNamedContext ¶
PrepareNamedContext returns an sqx.NamedStmt
func (*DB) PreparexContext ¶
PreparexContext returns an sqx.Stmt instead of a sql.Stmt.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*DB) QueryRowx ¶
QueryRowx queries the database and returns an *sqx.Row. Any placeholder parameters are replaced with supplied args.
func (*DB) QueryRowxContext ¶
QueryRowxContext queries the database and returns an *sqx.Row. Any placeholder parameters are replaced with supplied args.
func (*DB) Queryx ¶
Queryx queries the database and returns an *sqx.Rows. Any placeholder parameters are replaced with supplied args.
func (*DB) QueryxContext ¶
QueryxContext queries the database and returns an *sqx.Rows. Any placeholder parameters are replaced with supplied args.
func (*DB) Quoter ¶
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*DB) Select ¶
Select using this DB. Any placeholder parameters are replaced with supplied args.
func (*DB) SelectContext ¶
SelectContext using this DB. Any placeholder parameters are replaced with supplied args.
func (*DB) SupportLastInsertID ¶
func (ext *DB) SupportLastInsertID() bool
SupportRetuning check sql driver support "RETUNING"
func (*DB) Transaction ¶
Transaction start a transaction as a block, return error will rollback, otherwise to commit. Transaction executes an arbitrary number of commands in fc within a transaction. On success the changes are committed; if an error occurs they are rolled back.
func (*DB) Transactionx ¶
func (db *DB) Transactionx(ctx context.Context, opts *sql.TxOptions, fc func(tx *Tx) error) (err error)
Transactionx start a transaction as a block, return error will rollback, otherwise to commit. Transaction executes an arbitrary number of commands in fc within a transaction. On success the changes are committed; if an error occurs they are rolled back.
type ExecerContext ¶
type ExecerContext interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
ExecerContext is an interface used by MustExecContext and LoadFileContext
type ExtContext ¶
type ExtContext interface { QueryerContext ExecerContext // contains filtered or unexported methods }
ExtContext is a union interface which can bind, query, and exec, with Context used by NamedQueryContext and NamedExecContext.
type NamedExecer ¶
NamedExecer is an interface used by MustExec
type NamedQueryer ¶
type NamedStmt ¶
NamedStmt is a prepared statement that executes named queries. Prepare it how you would execute a NamedQuery, but pass in a struct or map when executing.
func (*NamedStmt) Exec ¶
Exec executes a named statement using the struct passed. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) ExecContext ¶
ExecContext executes a named statement using the struct passed. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) Get ¶
Get using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) GetContext ¶
GetContext using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) MustExec ¶
MustExec execs a NamedStmt, panicing on error Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) MustExecContext ¶
MustExecContext execs a NamedStmt, panicing on error Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) Query ¶
Query executes a named statement using the struct argument, returning rows. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryContext ¶
QueryContext executes a named statement using the struct argument, returning rows. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRow ¶
QueryRow executes a named statement against the database. Because sqx cannot create a *sql.Row with an error condition pre-set for binding errors, sqx returns a *sqx.Row instead. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRowContext ¶
QueryRowContext executes a named statement against the database. Because sqx cannot create a *sql.Row with an error condition pre-set for binding errors, sqx returns a *sqx.Row instead. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRowx ¶
QueryRowx this NamedStmt. Because of limitations with QueryRow, this is an alias for QueryRow. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRowxContext ¶
QueryRowxContext this NamedStmt. Because of limitations with QueryRow, this is an alias for QueryRow. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) Queryx ¶
Queryx using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryxContext ¶
QueryxContext using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) Select ¶
Select using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) SelectContext ¶
SelectContext using this NamedStmt Any named placeholder parameters are replaced with fields from arg.
type PreparerContext ¶
type PreparerContext interface {
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
}
PreparerContext is an interface used by PreparexContext.
type PreparerxContext ¶
type PreparerxContext interface {
PreparexContext(ctx context.Context, query string) (*Stmt, error)
}
PreparerxContext is an interface used by PreparexContext.
type QueryerContext ¶
type QueryerContext interface { QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error) QueryRowxContext(ctx context.Context, query string, args ...any) *Row }
QueryerContext is an interface used by GetContext and SelectContext
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row is a reimplementation of sql.Row in order to gain access to the underlying sql.Rows.Columns() data, necessary for StructScan.
func (*Row) Binder ¶
func (ext *Row) Binder() Binder
Binder returns the binder by driverName passed to the Open function for this DB.
func (*Row) ColumnTypes ¶
func (r *Row) ColumnTypes() ([]*sql.ColumnType, error)
ColumnTypes returns the underlying sql.Rows.ColumnTypes(), or the deferred error
func (*Row) Columns ¶
Columns returns the underlying sql.Rows.Columns(), or the deferred error usually returned by Row.Scan()
func (*Row) DriverName ¶
func (ext *Row) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Row) Quoter ¶
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*Row) Scan ¶
Scan is a fixed implementation of sql.Row.Scan, which does not discard the underlying error from the internal rows object if it exists.
func (*Row) StructScan ¶
StructScan a single Row into dest.
func (*Row) SupportLastInsertID ¶
func (ext *Row) SupportLastInsertID() bool
SupportRetuning check sql driver support "RETUNING"
type Rows ¶
Rows is a wrapper around sql.Rows which caches costly reflect operations during a looped StructScan
func NamedQueryContext ¶
NamedQueryContext binds a named query and then runs Query on the result using the provided Ext (sqx.Tx, sqx.Db). It works with both structs and with map[string]any types.
func (*Rows) Binder ¶
func (ext *Rows) Binder() Binder
Binder returns the binder by driverName passed to the Open function for this DB.
func (*Rows) DriverName ¶
func (ext *Rows) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Rows) Quoter ¶
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*Rows) StructScan ¶
StructScan is like sql.Rows.Scan, but scans a single Row into a single Struct. Use this and iterate over Rows manually when the memory load of Select() might be prohibitive. *Rows.StructScan caches the reflect work of matching up column positions to fields to avoid that overhead per scan, which means it is not safe to run StructScan on the same Rows instance with different struct types.
func (*Rows) SupportLastInsertID ¶
func (ext *Rows) SupportLastInsertID() bool
SupportRetuning check sql driver support "RETUNING"
type Sqlx ¶
type Sqlx interface { Sql Supporter Bind Selector Queryerx NamedQueryer NamedExecer Preparerx }
type Stmt ¶
Stmt is an sqx wrapper around sql.Stmt with extra functionality
func (*Stmt) Binder ¶
func (ext *Stmt) Binder() Binder
Binder returns the binder by driverName passed to the Open function for this DB.
func (*Stmt) DriverName ¶
func (ext *Stmt) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Stmt) Get ¶
Get using the prepared statement. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Stmt) GetContext ¶
GetContext using the prepared statement. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Stmt) MustExec ¶
MustExec (panic) using this statement. Note that the query portion of the error output will be blank, as Stmt does not expose its query. Any placeholder parameters are replaced with supplied args.
func (*Stmt) MustExecContext ¶
MustExecContext (panic) using this statement. Note that the query portion of the error output will be blank, as Stmt does not expose its query. Any placeholder parameters are replaced with supplied args.
func (*Stmt) QueryRowx ¶
QueryRowx using this statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) QueryRowxContext ¶
QueryRowxContext using this statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) Queryx ¶
Queryx using this statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) QueryxContext ¶
QueryxContext using this statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) Quoter ¶
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*Stmt) Select ¶
Select using the prepared statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) SelectContext ¶
SelectContext using the prepared statement. Any placeholder parameters are replaced with supplied args.
func (*Stmt) SupportLastInsertID ¶
func (ext *Stmt) SupportLastInsertID() bool
SupportRetuning check sql driver support "RETUNING"
type Tx ¶
Tx is an sqx wrapper around sql.Tx with extra functionality
func (*Tx) Binder ¶
func (ext *Tx) Binder() Binder
Binder returns the binder by driverName passed to the Open function for this DB.
func (*Tx) DriverName ¶
func (ext *Tx) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Tx) Get ¶
Get within a transaction. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Tx) GetContext ¶
GetContext within a transaction and context. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*Tx) MustExec ¶
MustExec runs MustExec within a transaction. Any placeholder parameters are replaced with supplied args.
func (*Tx) MustExecContext ¶
MustExecContext runs MustExecContext within a transaction. Any placeholder parameters are replaced with supplied args.
func (*Tx) NamedExec ¶
NamedExec a named query within a transaction. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedExecContext ¶
NamedExecContext using this Tx. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedQuery ¶
NamedQuery within a transaction. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedQueryRow ¶
NamedQueryRow within a transaction. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedStmt ¶
NamedStmt returns a version of the prepared statement which runs within a transaction.
func (*Tx) NamedStmtContext ¶
NamedStmtContext returns a version of the prepared statement which runs within a transaction.
func (*Tx) PrepareNamed ¶
PrepareNamed returns an sqx.NamedStmt
func (*Tx) PrepareNamedContext ¶
PrepareNamedContext returns an sqx.NamedStmt
func (*Tx) PreparexContext ¶
PreparexContext returns an sqx.Stmt instead of a sql.Stmt.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Tx) QueryRowx ¶
QueryRowx within a transaction. Any placeholder parameters are replaced with supplied args.
func (*Tx) QueryRowxContext ¶
QueryRowxContext within a transaction and context. Any placeholder parameters are replaced with supplied args.
func (*Tx) Queryx ¶
Queryx within a transaction. Any placeholder parameters are replaced with supplied args.
func (*Tx) QueryxContext ¶
QueryxContext within a transaction and context. Any placeholder parameters are replaced with supplied args.
func (*Tx) Quoter ¶
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*Tx) Select ¶
Select within a transaction. Any placeholder parameters are replaced with supplied args.
func (*Tx) SelectContext ¶
SelectContext within a transaction and context. Any placeholder parameters are replaced with supplied args.
func (*Tx) Stmtx ¶
Stmtx returns a version of the prepared statement which runs within a transaction. Provided stmt can be either *sql.Stmt or *sqx.Stmt.
func (*Tx) StmtxContext ¶
StmtxContext returns a version of the prepared statement which runs within a transaction. Provided stmt can be either *sql.Stmt or *sqx.Stmt.
func (*Tx) SupportLastInsertID ¶
func (ext *Tx) SupportLastInsertID() bool
SupportRetuning check sql driver support "RETUNING"