Documentation
¶
Overview ¶
Package sqlex is a modern enhancement of database/sql based on jmoiron/sqlx.
sqlex's design philosophy is SQL-centric: developers write SQL directly, and sqlex handles parameter binding and result mapping. No chain APIs, implicit query building, or ORM-style abstractions are introduced.
Core Enhancements ¶
- Hook aspects: onion-model SQL interceptors supporting logging, monitoring, and tracing
- JsonValue[T]: generic JSON column type, NULL-safe
- Auto Rebind: all query methods use ? placeholders uniformly, auto-converting to target database format
- Transparent IN: Select/Get/NamedGet/NamedSelect auto-expand slice parameters
- StrictMode: optional strict mode detecting query result / struct field mismatches
- CloseWithErr: auto-commits or rolls back transactions based on error; failures reported via Hook
- NamedExt/BindExt: unified interfaces, DB and Tx are interchangeable
- Functional Options: Open/Connect support WithHooks/WithStrictMode etc.
Quick Start ¶
db, err := sqlex.Connect("postgres", dsn,
sqlex.WithStrictMode(),
)
var users []User
err = db.Select(&users, "SELECT * FROM users WHERE age > ?", 18)
// Named parameters + auto IN expansion
err = db.NamedSelect(&users, "SELECT * FROM users WHERE id IN (:ids)",
map[string]any{"ids": []int{1, 2, 3}})
Supported Databases ¶
PostgreSQL, MySQL, SQLite, Oracle, SQL Server
Index ¶
- Constants
- Variables
- func AsList(slice any) any
- func AsValue(v any) any
- func BindDriver(driverName string, bindType int)
- func BindNamed(bindType int, query string, arg any) (string, []any, error)deprecated
- func BindType(driverName string) int
- func Get(q Queryer, dest any, query string, args ...any) error
- func GetContext(ctx context.Context, q QueryerContext, dest any, query string, args ...any) error
- func In(query string, args ...any) (string, []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)deprecated
- func NamedExec(e Ext, query string, arg any) (sql.Result, error)
- func NamedExecContext(ctx context.Context, e ExtContext, query string, arg any) (sql.Result, error)
- func Rebind(bindType int, query string) string
- func ScanAll(rows rowsi, dest any) error
- func Select(q Queryer, 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) errordeprecated
- type BindExt
- type ColScanner
- type Conn
- func (c *Conn) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (c *Conn) BindNamed(query string, arg any) (string, []any, error)
- func (c *Conn) DriverName() string
- func (c *Conn) Exec(query string, args ...any) (sql.Result, error)
- func (c *Conn) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (c *Conn) Get(dest any, query string, args ...any) error
- func (c *Conn) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (c *Conn) GetMapper() *reflectx.Mapper
- func (c *Conn) IsStrict() bool
- func (c *Conn) MustExec(query string, args ...any) sql.Result
- func (c *Conn) MustExecContext(ctx context.Context, query string, args ...any) sql.Result
- func (c *Conn) NamedExec(query string, arg any) (sql.Result, error)
- func (c *Conn) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
- func (c *Conn) NamedGet(dest any, query string, param any) error
- func (c *Conn) NamedGetContext(ctx context.Context, dest any, query string, param any) error
- func (c *Conn) NamedQuery(query string, arg any) (*Rows, error)
- func (c *Conn) NamedQueryContext(ctx context.Context, query string, arg any) (*Rows, error)
- func (c *Conn) NamedSelect(dest any, query string, param any) error
- func (c *Conn) NamedSelectContext(ctx context.Context, dest any, query string, param any) error
- func (c *Conn) Prepare(query string) (*sql.Stmt, error)
- func (c *Conn) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)
- func (c *Conn) PreparexContext(ctx context.Context, query string) (*Stmt, error)
- func (c *Conn) Query(query string, args ...any) (*sql.Rows, error)
- func (c *Conn) QueryRowx(query string, args ...any) *Row
- func (c *Conn) QueryRowxContext(ctx context.Context, query string, args ...any) *Row
- func (c *Conn) Queryx(query string, args ...any) (*Rows, error)
- func (c *Conn) QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error)
- func (c *Conn) Rebind(query string) string
- func (c *Conn) Select(dest any, query string, args ...any) error
- func (c *Conn) SelectContext(ctx context.Context, dest any, query string, args ...any) error
- func (c *Conn) SetStrict(strict bool)
- type DB
- func Connect(driverName, dataSourceName string, opts ...Opt) (*DB, error)
- func ConnectContext(ctx context.Context, driverName, dataSourceName string, opts ...Opt) (*DB, error)
- func MustConnect(driverName, dataSourceName string, opts ...Opt) *DB
- func MustOpen(driverName, dataSourceName string, opts ...Opt) *DB
- func NewDb(db *sql.DB, driverName string, opts ...Opt) *DB
- func Open(driverName, dataSourceName string, opts ...Opt) (*DB, error)
- func (db *DB) AddHook(hook Hook)
- 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 (db *DB) Connx(ctx context.Context) (*Conn, error)
- func (db *DB) DriverName() string
- func (db *DB) Exec(query string, args ...any) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- 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 (db *DB) GetMapper() *reflectx.Mapper
- func (db *DB) IsStrict() bool
- func (db *DB) MapperFunc(mf func(string) string)
- func (db *DB) MustBegin() *Tx
- func (db *DB) MustBeginTxx(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) NamedGet(dest any, query string, param any) error
- func (db *DB) NamedGetContext(ctx context.Context, dest any, query string, param any) 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) NamedSelect(dest any, query string, param any) error
- func (db *DB) NamedSelectContext(ctx context.Context, dest any, query string, param any) error
- 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 (db *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 (db *DB) SetStrict(strict bool)
- type Execer
- type ExecerContext
- type Ext
- type ExtContext
- type Hook
- type NamedExt
- 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) GetMapper() *reflectx.Mapper
- 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
- type Opt
- type Preparer
- type PreparerContext
- type QueryEvent
- type Queryer
- type QueryerContext
- type Row
- func (r *Row) ColumnTypes() ([]*sql.ColumnType, error)
- func (r *Row) Columns() ([]string, error)
- func (r *Row) Err() error
- func (r *Row) GetMapper() *reflectx.Mapper
- func (r *Row) MapScan(dest map[string]any) error
- func (r *Row) Scan(dest ...any) error
- func (r *Row) SliceScan() ([]any, error)
- func (r *Row) StructScan(dest any) error
- type Rows
- type Stmt
- func (s *Stmt) Exec(args ...any) (sql.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args ...any) (sql.Result, error)
- func (s *Stmt) Get(dest any, args ...any) error
- func (s *Stmt) GetContext(ctx context.Context, dest any, args ...any) error
- func (s *Stmt) GetMapper() *reflectx.Mapper
- func (s *Stmt) MustExec(args ...any) sql.Result
- func (s *Stmt) MustExecContext(ctx context.Context, args ...any) sql.Result
- func (s *Stmt) Query(args ...any) (*sql.Rows, error)
- func (s *Stmt) QueryContext(ctx context.Context, args ...any) (*sql.Rows, error)
- 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 (s *Stmt) Select(dest any, args ...any) error
- func (s *Stmt) SelectContext(ctx context.Context, dest any, args ...any) error
- type Tx
- func (tx *Tx) BindNamed(query string, arg any) (string, []any, error)
- func (tx *Tx) CloseWithErr(err error)
- func (tx *Tx) DriverName() string
- func (tx *Tx) Exec(query string, args ...any) (sql.Result, error)
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (tx *Tx) ExecFunc(fn func(tx *Tx))
- 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 (tx *Tx) GetMapper() *reflectx.Mapper
- func (tx *Tx) IsStrict() bool
- 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) NamedGet(dest any, query string, param any) error
- func (tx *Tx) NamedGetContext(ctx context.Context, dest any, query string, param any) error
- func (tx *Tx) NamedQuery(query string, arg any) (*Rows, error)
- func (tx *Tx) NamedQueryContext(ctx context.Context, query string, arg any) (*Rows, error)
- func (tx *Tx) NamedSelect(dest any, query string, param any) error
- func (tx *Tx) NamedSelectContext(ctx context.Context, dest any, query string, param any) error
- 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 (tx *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) SetStrict(strict bool)
- func (tx *Tx) Stmtx(stmt any) *Stmt
- func (tx *Tx) StmtxContext(ctx context.Context, stmt any) *Stmt
- func (tx *Tx) TryStmtx(stmt any) (*Stmt, error)
- func (tx *Tx) TryStmtxContext(ctx context.Context, stmt any) (*Stmt, error)
Constants ¶
const ( UNKNOWN = iota QUESTION DOLLAR NAMED AT )
Bindvar types supported by Rebind, BindMap and BindStruct.
Variables ¶
var NameMapper = strings.ToLower
NameMapper is used to map column names to struct field names. By default, it uses strings.ToLower to lowercase struct field names. It can be set to whatever you want, but it is encouraged to be set before sqlex is used as name-to-field mappings are cached after first use on a type.
Warning: NameMapper reads and writes are not concurrency-safe. It is recommended to set it only in an init() function; modifying it at runtime may cause data races. If you need different mapping strategies at runtime, use DB.MapperFunc() to set each DB instance individually.
Functions ¶
func AsList ¶
AsList wraps a slice, forcing expansion into an IN list (even if ? is not in the (?) form). Returns an error from In if the argument is not a slice or is an empty slice.
db.Exec("WHERE x = ?", sqlex.AsList([]int{1, 2, 3}))
// Expands to "WHERE x = ?, ?, ?"
func AsValue ¶
AsValue wraps a value, telling In/autoIn not to expand it into an IN list; it is passed as a single argument as-is.
Use case: INSERT/UPDATE slice field values, PG's ANY(?)/ALL(?) and other patterns that might be misidentified as the (?) form.
db.Exec("INSERT INTO t (col) VALUES (?)", sqlex.AsValue([]int{1, 2, 3}))
db.Select(&rows, "WHERE id = ANY(?)", sqlex.AsValue(pq.Array([]int{1,2,3})))
func BindDriver ¶
BindDriver sets the BindType for driverName to bindType.
func BindNamed
deprecated
BindNamed binds a struct or a map to a query with named parameters.
Deprecated: It is recommended to use db.NamedSelect / NamedExec / NamedQuery etc. directly, as they already include Rebind/Hook/StrictMode aspects automatically, eliminating the need to call BindNamed manually. Use this function only when you specifically need to control bindType yourself (rare).
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 sql.ErrNoRows like row.Scan would. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
Note: This function only does "scan dispatch"; it does not perform autoIn / Rebind / Hook — these cross-cutting concerns are guaranteed by the Queryer.QueryRowx implementation (see Queryer interface contract).
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 sql.ErrNoRows like row.Scan would. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
Note: This function only does "scan dispatch"; it does not perform autoIn / Rebind / Hook — these cross-cutting concerns are guaranteed by the QueryerContext.QueryRowxContext implementation.
func In ¶
In expands slice values in args, returning the modified query string and a new arg list that can be executed by a database. The `query` should use the `?` bindVar. The return value uses the `?` bindVar.
Lexical skip: ? inside single/double/backtick-quoted strings, dollar-quoted strings, and line/block comments will not be recognized as placeholders; `\?` and `??` output a literal ?. Lexical rules are symmetric with Rebind.
Slice expansion rules ("strict (?) context recognition"):
- ? in strict (?) form (only ? and optional ASCII whitespace between ( and )) + slice -> expand to ?, ?, ?
- ? elsewhere + slice -> no expansion, passed as a single value to the driver
- sqlex.AsValue(v) -> force no expansion (even if ? is in (?) form)
- sqlex.AsList(slice) -> force expansion (even if ? is not in (?) form)
- driver.Valuer -> .Value() is called first, then the above rules apply
- []byte -> treated as a single value (standard driver.Value type)
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
deprecated
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.
Deprecated: It is recommended to use db.NamedSelect / NamedExec / NamedQuery etc. directly, as they already include Rebind/Hook/StrictMode aspects automatically. Use this function only in dynamic SQL composition scenarios (e.g. multi-segment UNION, dynamic WHERE condition merging) that cannot be expressed with the higher-level methods.
func NamedExec ¶
NamedExec 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 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 Rebind ¶
Rebind a query from the default bindtype (QUESTION) to the target bindtype.
Lexical skip: ? inside single/double/backtick-quoted strings, dollar-quoted strings, and line/block comments will not be replaced; `\?` and `??` output a literal ?. Rules are symmetric with compileNamedQuery / In.
func ScanAll ¶
ScanAll scans all rows from an sql.Rows or an sqlex.Rows into the dest slice. ScanAll is the preferred alias for StructScan with a clearer naming convention. If rows is sqlex.Rows, it will use its mapper, otherwise it will use the default.
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.
Note: This function only does "scan dispatch"; it does not perform autoIn / Rebind / Hook — these cross-cutting concerns are guaranteed by the Queryer.Queryx implementation (see Queryer interface contract).
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.
Note: This function only does "scan dispatch"; it does not perform autoIn / Rebind / Hook — these cross-cutting concerns are guaranteed by the QueryerContext.QueryxContext implementation (see QueryerContext interface contract).
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
deprecated
StructScan all rows from an sql.Rows or an sqlex.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 sqlex.Rows.StructScan. If rows is sqlex.Rows, it will use its mapper, otherwise it will use the default.
Deprecated: Use ScanAll instead, which has a clearer name.
Types ¶
type BindExt ¶
type BindExt interface {
// --- High-level convenience methods (struct scanning) ---
Select(dest any, query string, args ...any) error
SelectContext(ctx context.Context, dest any, query string, args ...any) error
Get(dest any, query string, args ...any) error
GetContext(ctx context.Context, dest any, query string, args ...any) error
// --- Execution (INSERT/UPDATE/DELETE) ---
Exec(query string, args ...any) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
// --- Low-level query primitives ---
Queryx(query string, args ...any) (*Rows, error)
QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error)
QueryRowx(query string, args ...any) *Row
QueryRowxContext(ctx context.Context, query string, args ...any) *Row
}
BindExt is a unified interface that keeps the basic query method signatures of DB, Tx, and Conn consistent, enabling generic data access functions that are agnostic to the execution context (DB / Tx / Conn). This interface covers high-level convenience methods, execution, and low-level query primitives, unifying the capabilities of Queryer, Execer, QueryerContext, and ExecerContext.
Contract guarantees (all implementations must satisfy):
- Automatic IN expansion: when slice arguments are passed, IN (?) is automatically expanded to IN (?,?,...,?), consistent with NamedExt behavior; zero overhead when no slices. Applicable methods: Exec/ExecContext, Queryx/QueryxContext, QueryRowx/QueryRowxContext, Select/SelectContext, Get/GetContext.
- Automatic Rebind: callers use unified ? placeholders; internally converted to the target database's bindvar format (?/$N/:argN/@pN) without worrying about underlying differences.
- Hook chain integration: all methods trigger BeforeQuery/AfterQuery hooks; the observable query is the final SQL after autoIn expansion + Rebind (i.e. the SQL actually sent to the driver).
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 *sqlex.Tx instead of an *sql.Tx.
func (*Conn) DriverName ¶
DriverName returns the driverName used by the DB which created this Conn.
func (*Conn) Exec ¶
Exec executes a query without returning any rows. Any placeholder parameters are replaced with supplied args.
func (*Conn) ExecContext ¶
ExecContext executes a query without returning any rows. Overrides sql.Conn's ExecContext to integrate Hook logic. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*Conn) Get ¶
Get using this Conn. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
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) MustExec ¶
MustExec (panic) runs MustExec using this Conn. Any placeholder parameters are replaced with supplied args.
func (*Conn) MustExecContext ¶
MustExecContext (panic) runs MustExec using this Conn. Any placeholder parameters are replaced with supplied args.
func (*Conn) NamedExec ¶
NamedExec using this Conn. Any named placeholder parameters are replaced with fields from arg. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*Conn) NamedExecContext ¶
NamedExecContext using this Conn. Any named placeholder parameters are replaced with fields from arg.
Note: This method only does named-to-? conversion and forwarding; autoIn / Rebind / Hook are guaranteed by the downstream c.ExecContext implementation (see ExecerContext interface contract).
func (*Conn) NamedGet ¶
NamedGet executes a query with named parameters and scans a single row result. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*Conn) NamedGetContext ¶
NamedGetContext executes a query with named parameters and scans a single row result.
func (*Conn) NamedQuery ¶
NamedQuery using this Conn. Any named placeholder parameters are replaced with fields from arg.
func (*Conn) NamedQueryContext ¶
NamedQueryContext using this Conn. Any named placeholder parameters are replaced with fields from arg.
func (*Conn) NamedSelect ¶
NamedSelect executes a query with named parameters and scans the result set into a slice. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*Conn) NamedSelectContext ¶
NamedSelectContext executes a query with named parameters and scans the result set into a slice.
func (*Conn) PrepareNamedContext ¶
PrepareNamedContext returns an sqlex.NamedStmt
func (*Conn) PreparexContext ¶
PreparexContext returns an sqlex.Stmt instead of a sql.Stmt.
func (*Conn) Query ¶
Query executes a query that returns rows. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryRowx ¶
QueryRowx queries the database and returns an *sqlex.Row. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryRowxContext ¶
QueryRowxContext queries the database and returns an *sqlex.Row. Any placeholder parameters are replaced with supplied args. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*Conn) Queryx ¶
Queryx queries the database and returns an *sqlex.Rows. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryxContext ¶
QueryxContext queries the database and returns an *sqlex.Rows. Any placeholder parameters are replaced with supplied args. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*Conn) Select ¶
Select using this Conn. Any placeholder parameters are replaced with supplied args.
func (*Conn) SelectContext ¶
SelectContext using this Conn. Any placeholder parameters are replaced with supplied args.
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 ¶
func ConnectContext(ctx context.Context, driverName, dataSourceName string, opts ...Opt) (*DB, error)
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 *sqlex.DB instead and panics on error.
func NewDb ¶
NewDb returns a new sqlex 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 *sqlex.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 BeginTxx is canceled.
func (*DB) DriverName ¶
DriverName returns the driverName passed to the Open function for this DB.
func (*DB) Exec ¶
Exec executes a query without returning any rows. Any placeholder parameters are replaced with supplied args. Overrides sql.DB's Exec, delegating to ExecContext to integrate Hook logic.
func (*DB) ExecContext ¶
ExecContext executes a query without returning any rows. Overrides sql.DB's ExecContext to integrate Hook logic. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
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 sqlex struct tag and the provided mapper function.
func (*DB) MustBegin ¶
MustBegin starts a transaction, and panics on error. Returns an *sqlex.Tx instead of an *sql.Tx.
func (*DB) MustBeginTxx ¶
MustBeginTxx starts a transaction, and panics on error. Returns an *sqlex.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. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*DB) NamedExecContext ¶
NamedExecContext using this DB. Any named placeholder parameters are replaced with fields from arg.
Note: This method only does named-to-? conversion and forwarding; autoIn / Rebind / Hook are guaranteed by the downstream db.ExecContext implementation (see ExecerContext interface contract).
func (*DB) NamedGet ¶
NamedGet executes a query with named parameters and scans a single row result.
func (*DB) NamedGetContext ¶
NamedGetContext executes a query with named parameters and scans a single row result.
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) NamedSelect ¶
NamedSelect executes a query with named parameters and scans the result set into a slice.
func (*DB) NamedSelectContext ¶
NamedSelectContext executes a query with named parameters and scans the result set into a slice.
func (*DB) PrepareNamed ¶
PrepareNamed returns an sqlex.NamedStmt
func (*DB) PrepareNamedContext ¶
PrepareNamedContext returns an sqlex.NamedStmt
func (*DB) PreparexContext ¶
PreparexContext returns an sqlex.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 *sqlex.Row. Any placeholder parameters are replaced with supplied args.
func (*DB) QueryRowxContext ¶
QueryRowxContext queries the database and returns an *sqlex.Row. Any placeholder parameters are replaced with supplied args. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*DB) Queryx ¶
Queryx queries the database and returns an *sqlex.Rows. Any placeholder parameters are replaced with supplied args.
func (*DB) QueryxContext ¶
QueryxContext queries the database and returns an *sqlex.Rows. Any placeholder parameters are replaced with supplied args. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
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.
type Execer ¶
Execer is an interface used by MustExec.
Implementer contract (must be upheld, otherwise cross-cutting concerns of MustExec and other high-level methods will be broken):
- Exec must perform autoIn internally (automatic IN slice expansion)
- Exec must perform Rebind internally (driver bindvar conversion)
- Exec must trigger the Hook chain
sqlex.DB / Tx / Conn satisfy all contract requirements.
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.
Implementer contract (must be upheld, otherwise cross-cutting concerns of MustExecContext and other high-level methods will be broken):
- ExecContext must perform autoIn internally (automatic IN slice expansion)
- ExecContext must perform Rebind internally (driver bindvar conversion)
- ExecContext must trigger the Hook chain
sqlex.DB / Tx / Conn satisfy all contract requirements.
type Ext ¶
Ext is a union interface which can bind, query, and exec, used by NamedQuery and NamedExec.
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 Hook ¶
type Hook interface {
BeforeQuery(ctx context.Context, event *QueryEvent) context.Context
AfterQuery(ctx context.Context, event *QueryEvent)
}
Hook is the SQL execution aspect interface. BeforeQuery is called before SQL execution and can modify the context. AfterQuery is called after SQL execution. Multiple Hooks execute BeforeQuery in registration order and AfterQuery in reverse order (onion model).
Note: For QueryRowx/QueryRowxContext methods, the Hook fires immediately after QueryContext returns, before the row data is scanned. Therefore, QueryEvent.Error only reflects errors from the query dispatch phase and does not include subsequent row.Scan() errors (e.g., type mismatch, sql.ErrNoRows). For full lifecycle observability, use the QueryxContext + rows.Next() + StructScan pattern.
type NamedExt ¶
type NamedExt interface {
// --- High-level convenience methods (struct scanning + automatic IN expansion) ---
NamedGet(dest any, query string, param any) error
NamedGetContext(ctx context.Context, dest any, query string, param any) error
NamedSelect(dest any, query string, param any) error
NamedSelectContext(ctx context.Context, dest any, query string, param any) error
// --- Execution (INSERT/UPDATE/DELETE, with built-in IN expansion) ---
NamedExec(query string, arg any) (sql.Result, error)
NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
// --- Low-level query primitives (with built-in IN expansion) ---
NamedQuery(query string, arg any) (*Rows, error)
NamedQueryContext(ctx context.Context, query string, arg any) (*Rows, error)
}
NamedExt is a unified interface that keeps the named-parameter method signatures of DB, Tx, and Conn consistent, enabling generic data access functions that are agnostic to the execution context (DB / Tx / Conn). Symmetric with BindExt.
Contract guarantees (all implementations must satisfy):
- Automatic IN expansion: when a map/struct field contains a slice, IN (:field) is automatically expanded to IN (?,?,...,?), consistent with BindExt behavior; zero overhead when no slices.
- Automatic Rebind: callers use unified :name named placeholders; internally converted to the target database's bindvar format (?/$N/:argN/@pN) without worrying about underlying differences.
- Hook chain integration: all methods trigger BeforeQuery/AfterQuery hooks; the observable query is the final SQL after IN expansion + Rebind (i.e. the SQL actually sent to the driver).
type NamedStmt ¶
type NamedStmt struct {
Params []string
QueryString string
Stmt *Stmt
// contains filtered or unexported fields
}
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 sqlex cannot create a *sql.Row with an error condition pre-set for binding errors, sqlex returns a *sqlex.Row instead. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRowContext ¶
QueryRowContext executes a named statement against the database. Because sqlex cannot create a *sql.Row with an error condition pre-set for binding errors, sqlex returns a *sqlex.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.
type Opt ¶
type Opt func(db *DB)
func WithMapperFunc ¶
WithMapperFunc returns an Opt that sets a custom field mapping function when creating a DB.
type Preparer ¶
type Preparer interface {
Prepare(query string) (*sql.Stmt, error)
// contains filtered or unexported methods
}
Preparer is an interface used by Preparex. It embeds the binder interface, enabling Preparex to automatically Rebind, allowing unified use of ? placeholders without worrying about underlying database differences.
type PreparerContext ¶
type PreparerContext interface {
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
// contains filtered or unexported methods
}
PreparerContext is an interface used by PreparexContext. It embeds the binder interface, enabling PreparexContext to automatically Rebind, allowing unified use of ? placeholders without worrying about underlying database differences.
type QueryEvent ¶
type QueryEvent struct {
// Query is the SQL statement.
Query string
// Args are the execution parameters.
Args []any
// StartTime is the start time (includes Hook chain execution time).
StartTime time.Time
// Duration is the total elapsed time from the start of the BeforeQuery chain
// to the end of the AfterQuery chain. Includes Hook chain execution overhead,
// suitable for distributed tracing.
Duration time.Duration
// Error is the execution error (only set in the AfterQuery phase).
Error error
// OperationType is the operation type: query/exec/prepare/commit/rollback.
OperationType string
}
QueryEvent describes the context of a SQL execution event.
type Queryer ¶
type Queryer interface {
Query(query string, args ...any) (*sql.Rows, error)
Queryx(query string, args ...any) (*Rows, error)
QueryRowx(query string, args ...any) *Row
}
Queryer is an interface used by Get and Select.
Implementer contract (must be upheld, otherwise cross-cutting concerns of Get/Select and other high-level methods will be broken):
- Queryx / QueryRowx must perform autoIn internally (automatic IN slice expansion)
- Queryx / QueryRowx must perform Rebind internally (driver bindvar conversion)
- Queryx / QueryRowx must trigger the Hook chain
sqlex.DB / Tx / Conn satisfy all contract requirements. The top-level Get/Select functions do not perform autoIn / Rebind / Hook themselves — they rely entirely on the Queryer implementation's guarantees. This is the design principle since Phase 2.0.
Note: The standard library's Query method (returning *sql.Rows) is sqlx-compatible legacy and is not covered by this contract.
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.
Implementer contract (must be upheld, otherwise cross-cutting concerns of GetContext/SelectContext and other high-level methods will be broken):
- QueryxContext / QueryRowxContext must perform autoIn internally (automatic IN slice expansion)
- QueryxContext / QueryRowxContext must perform Rebind internally (driver bindvar conversion)
- QueryxContext / QueryRowxContext must trigger the Hook chain
sqlex.DB / Tx / Conn satisfy all contract requirements.
Note: The standard library's QueryContext method (returning *sql.Rows) is sqlx-compatible legacy and is not covered by this contract.
type Row ¶
Row is a reimplementation of sql.Row in order to gain access to the underlying sql.Rows.Columns() data, necessary for StructScan.
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) 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.
type Rows ¶
Rows is a wrapper around sql.Rows which caches costly reflect operations during a looped StructScan
func NamedQuery ¶
NamedQuery binds a named query and then runs Query on the result using the provided Ext (sqlex.Tx, sqlex.Db). It works with both structs and with map[string]any types.
func NamedQueryContext ¶
NamedQueryContext binds a named query and then runs Query on the result using the provided Ext (sqlex.Tx, sqlex.Db). It works with both structs and with map[string]any types.
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.
Note: Rows, like database/sql.Rows, is not safe for concurrent use. Do not call StructScan on the same Rows instance from multiple goroutines.
type Stmt ¶
Stmt is an sqlex wrapper around sql.Stmt with extra functionality
func Preparex ¶
Preparex prepares a statement. Automatically converts ? placeholders to the target database's bindvar format (e.g. PostgreSQL's $N), consistent with other query methods, enabling unified ?-style SQL authoring.
func PreparexContext ¶
PreparexContext prepares a statement. Automatically converts ? placeholders to the target database's bindvar format (e.g. PostgreSQL's $N), consistent with other query methods, enabling unified ?-style SQL authoring.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Stmt) ExecContext ¶
ExecContext executes the prepared statement with the given arguments.
func (*Stmt) Get ¶
Get using the prepared statement. An error is returned if the result set is empty.
func (*Stmt) GetContext ¶
GetContext using the prepared statement. An error is returned if the result set is empty.
func (*Stmt) MustExecContext ¶
MustExecContext (panic) using this statement.
func (*Stmt) QueryContext ¶
QueryContext executes the prepared statement with the given arguments.
func (*Stmt) QueryRowxContext ¶
QueryRowxContext using the prepared statement.
func (*Stmt) QueryxContext ¶
QueryxContext using the prepared statement.
type Tx ¶
Tx is sqlex's enhanced wrapper around sql.Tx. Note: Tx, like database/sql.Tx, is not safe for concurrent use. Do not share the same Tx instance across goroutines for concurrent queries. If you need serialized operations within a transaction, use the ExecFunc method, which is the only method that provides internal locking.
func (*Tx) CloseWithErr ¶
CloseWithErr automatically commits or rolls back the transaction based on the error value. If err is nil, the transaction is committed; otherwise, it is rolled back. Commit/Rollback failures are reported via Hook.
func (*Tx) DriverName ¶
DriverName returns the driverName used by the DB which began this transaction.
func (*Tx) Exec ¶
Exec executes a query within a transaction without returning any rows. Any placeholder parameters are replaced with supplied args. Overrides sql.Tx's Exec, delegating to ExecContext to integrate Hook logic.
func (*Tx) ExecContext ¶
ExecContext executes a query without returning any rows. Overrides sql.Tx's ExecContext to integrate Hook logic. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*Tx) ExecFunc ¶
ExecFunc executes a function within a transaction, using a mutex to ensure concurrency safety. This is the only method in Tx that provides internal locking, suitable for scenarios requiring serialized transaction operations. All other Tx methods are unlocked; callers must ensure that the same Tx is not used concurrently across goroutines.
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. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
func (*Tx) NamedExecContext ¶
NamedExecContext using this Tx. Any named placeholder parameters are replaced with fields from arg.
Note: This method only does named-to-? conversion and forwarding; autoIn / Rebind / Hook are guaranteed by the downstream tx.ExecContext implementation (see ExecerContext interface contract).
func (*Tx) NamedGet ¶
NamedGet executes a query with named parameters and scans a single row result.
func (*Tx) NamedGetContext ¶
NamedGetContext executes a query with named parameters and scans a single row result.
func (*Tx) NamedQuery ¶
NamedQuery within a transaction. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedQueryContext ¶
NamedQueryContext within a transaction and context. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedSelect ¶
NamedSelect executes a query with named parameters and scans the result set into a slice.
func (*Tx) NamedSelectContext ¶
NamedSelectContext executes a query with named parameters and scans the result set into a slice.
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 sqlex.NamedStmt
func (*Tx) PrepareNamedContext ¶
PrepareNamedContext returns an sqlex.NamedStmt
func (*Tx) PreparexContext ¶
PreparexContext returns an sqlex.Stmt instead of a sql.Stmt.
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. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
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. Automatically detects slice args and expands IN clauses; zero overhead when no slices are present.
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) SetStrict ¶
SetStrict enables or disables strict mode. In strict mode (true), an error is returned if the query result contains columns that have no corresponding field in the target struct. In lenient mode (false), mismatched columns are silently ignored.
func (*Tx) Stmtx ¶
Stmtx returns a version of the prepared statement which runs within a transaction. Provided stmt can be either *sql.Stmt or *sqlex.Stmt.
WARNING: Stmtx will panic if stmt is not a valid type. Use TryStmtx for a safe version.
func (*Tx) StmtxContext ¶
StmtxContext returns a version of the prepared statement which runs within a transaction. Provided stmt can be either *sql.Stmt or *sqlex.Stmt.
WARNING: StmtxContext will panic if stmt is not a valid type. Use TryStmtxContext for a safe version.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshalling and unmarshalling packages.
|
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshalling and unmarshalling packages. |
|
Package types provides some useful types which implement the `sql.Scanner` and `driver.Valuer` interfaces, suitable for use as scan and value targets with database/sql.
|
Package types provides some useful types which implement the `sql.Scanner` and `driver.Valuer` interfaces, suitable for use as scan and value targets with database/sql. |