Documentation ¶
Overview ¶
Package sqlx 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 ¶
- Constants
- Variables
- func Create(x Sqlx, query string, args ...any) (int64, error)
- func CreateContext(ctx context.Context, x Sqlx, query string, args ...any) (int64, error)
- func Get(q Queryerx, dest any, query string, args ...any) error
- func GetContext(ctx context.Context, q ContextQueryerx, dest any, query string, args ...any) error
- func MapScan(r ColScanner, dest map[string]any) error
- func Named(query string, arg any) (string, []any, error)
- func NamedCreate(x Sqlx, query string, arg any) (int64, error)
- func NamedCreateContext(ctx context.Context, x Sqlx, query string, arg any) (int64, error)
- func NamedGet(q NamedQueryer, dest any, query string, arg any) error
- func NamedGetContext(ctx context.Context, q ContextNamedQueryer, dest any, query string, arg any) error
- func NamedSelect(q NamedQueryer, dest any, query string, arg any) error
- func NamedSelectContext(ctx context.Context, q ContextNamedQueryer, dest any, query string, arg any) error
- func Select(q Queryerx, dest any, query string, args ...any) error
- func SelectContext(ctx context.Context, q ContextQueryerx, dest any, query string, args ...any) error
- func SliceScan(r ColScanner) ([]any, error)
- func StructScan(rows iRows, dest any) error
- func Transaction(db Beginxer, fc func(tx *Tx) error) (err error)
- func Transactionx(ctx context.Context, db BeginTxxer, opts *sql.TxOptions, fc func(tx *Tx) error) (err error)
- type BeginTxxer
- type Beginxer
- type BindNamed
- type Binder
- type Build
- type Builder
- func (b *Builder) Build() (string, []any)
- func (b *Builder) Columns(cols ...string) *Builder
- func (b *Builder) Count(cols ...string) *Builder
- func (b *Builder) CountDistinct(cols ...string) *Builder
- func (b *Builder) Delete(tb string) *Builder
- func (b *Builder) Distinct() *Builder
- func (b *Builder) From(tb string) *Builder
- func (b *Builder) In(col string, val any) *Builder
- func (b *Builder) Insert(tb string) *Builder
- func (b *Builder) Join(query string, args ...any) *Builder
- func (b *Builder) Limit(limit int) *Builder
- func (b *Builder) Names(cols ...string) *Builder
- func (b *Builder) NotIn(col string, val any) *Builder
- func (b *Builder) Offset(offset int) *Builder
- func (b *Builder) Omits(cols ...string) *Builder
- func (b *Builder) Order(order string, desc ...bool) *Builder
- func (b *Builder) Params() []any
- func (b *Builder) Reset() *Builder
- func (b *Builder) Returns(cols ...string) *Builder
- func (b *Builder) SQL() string
- func (b *Builder) Select(cols ...string) *Builder
- func (b *Builder) Setc(col string, arg any) *Builder
- func (b *Builder) Setx(col string, val string, args ...any) *Builder
- func (b *Builder) StructNames(a any, omits ...string) *Builder
- func (b *Builder) StructPrefixSelect(a any, prefix string, omits ...string) *Builder
- func (b *Builder) StructSelect(a any, omits ...string) *Builder
- func (b *Builder) Update(tb string) *Builder
- func (b *Builder) Values(vals ...string) *Builder
- func (b *Builder) Where(q string, args ...any) *Builder
- type ColScanner
- type Conn
- func (c *Conn) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
- func (c *Conn) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (c *Conn) Beginx() (*Tx, error)
- func (c *Conn) BindNamed(query string, arg any) (string, []any, error)
- func (ext *Conn) Binder() Binder
- func (ext *Conn) Builder() *Builder
- func (c *Conn) Close() error
- func (c *Conn) Conn() *sql.Conn
- func (c *Conn) Create(query string, args ...any) (int64, error)
- func (c *Conn) CreateContext(ctx context.Context, query string, args ...any) (int64, error)
- func (ext *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 (ext *Conn) IsUnsafe() bool
- func (ext *Conn) Mapper() *ref.Mapper
- func (c *Conn) NamedCreate(query string, arg any) (int64, error)
- func (c *Conn) NamedCreateContext(ctx context.Context, query string, arg any) (int64, error)
- 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, arg any) error
- func (c *Conn) NamedGetContext(ctx context.Context, dest any, query string, arg 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) NamedQueryRow(query string, arg any) *Row
- func (c *Conn) NamedQueryRowContext(ctx context.Context, query string, arg any) *Row
- func (c *Conn) NamedSelect(dest any, query string, arg any) error
- func (c *Conn) NamedSelectContext(ctx context.Context, dest any, query string, arg any) error
- func (c *Conn) Ping() error
- func (c *Conn) PingContext(ctx context.Context) error
- func (c *Conn) Prepare(query string) (*sql.Stmt, error)
- func (c *Conn) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (c *Conn) Preparex(query string) (*Stmt, 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) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (c *Conn) QueryRow(query string, args ...any) *sql.Row
- func (c *Conn) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- 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 (ext *Conn) Quote(s string) string
- func (ext *Conn) Quoter() Quoter
- func (c *Conn) Raw(f func(driverConn any) error) error
- func (ext *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 (ext *Conn) SupportLastInsertID() bool
- func (c *Conn) Transactionx(ctx context.Context, opts *sql.TxOptions, fc func(tx *Tx) error) (err error)
- type ContextMixer
- type ContextNamedExecer
- type ContextNamedQueryer
- type ContextPreparerx
- type ContextQueryerx
- type DB
- func Connect(driverName, dataSourceName string, trace ...Trace) (*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, trace ...Trace) *DB
- func Open(driverName, dataSourceName string, trace ...Trace) (*DB, error)
- func (db *DB) Begin() (*sql.Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, 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 (ext *DB) Builder() *Builder
- func (db *DB) Close() error
- func (db *DB) Conn(ctx context.Context) (*sql.Conn, error)
- func (db *DB) Connx(ctx context.Context) (*Conn, error)
- func (db *DB) Create(query string, args ...any) (int64, error)
- func (db *DB) CreateContext(ctx context.Context, query string, args ...any) (int64, error)
- func (db *DB) DB() *sql.DB
- func (db *DB) Driver() driver.Driver
- func (ext *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 (ext *DB) IsUnsafe() bool
- func (ext *DB) Mapper() *ref.Mapper
- func (db *DB) MapperFunc(mf func(string) string)
- func (db *DB) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *Tx
- func (db *DB) MustBeginx() *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) NamedCreate(query string, arg any) (int64, error)
- func (db *DB) NamedCreateContext(ctx context.Context, query string, arg any) (int64, error)
- 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, arg any) error
- func (db *DB) NamedGetContext(ctx context.Context, dest any, query string, arg 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) NamedQueryRow(query string, arg any) *Row
- func (db *DB) NamedQueryRowContext(ctx context.Context, query string, arg any) *Row
- func (db *DB) NamedSelect(dest any, query string, arg any) error
- func (db *DB) NamedSelectContext(ctx context.Context, dest any, query string, arg any) error
- func (db *DB) Ping() error
- func (db *DB) PingContext(ctx context.Context) error
- func (db *DB) Prepare(query string) (*sql.Stmt, error)
- func (db *DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, 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) Query(query string, args ...any) (*sql.Rows, error)
- func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (db *DB) QueryRow(query string, args ...any) *sql.Row
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- 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() 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 (db *DB) SetConnMaxIdleTime(d time.Duration)
- func (db *DB) SetConnMaxLifetime(d time.Duration)
- func (db *DB) SetMaxIdleConns(n int)
- func (db *DB) SetMaxOpenConns(n int)
- func (db *DB) Stats() sql.DBStats
- 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 Mixer
- type NamedExecer
- type NamedQueryer
- type NamedStmt
- func (ns *NamedStmt) Close() error
- func (ns *NamedStmt) Exec(arg any) (sql.Result, error)
- func (ns *NamedStmt) ExecContext(ctx context.Context, arg any) (sql.Result, error)
- func (ns *NamedStmt) Get(dest any, arg any) error
- func (ns *NamedStmt) GetContext(ctx context.Context, dest any, arg any) error
- func (ns *NamedStmt) IsUnsafe() bool
- func (ns *NamedStmt) MustExec(arg any) sql.Result
- func (ns *NamedStmt) MustExecContext(ctx context.Context, arg any) sql.Result
- func (ns *NamedStmt) Query(arg any) (*sql.Rows, error)
- func (ns *NamedStmt) QueryContext(ctx context.Context, arg any) (*sql.Rows, error)
- func (ns *NamedStmt) QueryRow(arg any) *Row
- func (ns *NamedStmt) QueryRowContext(ctx context.Context, arg any) *Row
- func (ns *NamedStmt) QueryRowx(arg any) *Row
- func (ns *NamedStmt) QueryRowxContext(ctx context.Context, arg any) *Row
- func (ns *NamedStmt) Queryx(arg any) (*Rows, error)
- func (ns *NamedStmt) QueryxContext(ctx context.Context, arg any) (*Rows, error)
- func (ns *NamedStmt) Select(dest any, arg any) error
- func (ns *NamedStmt) SelectContext(ctx context.Context, dest any, arg any) error
- func (ns *NamedStmt) Unsafe() *NamedStmt
- type Preparerx
- type Queryerx
- type Quoter
- type Result
- type Row
- func (ext *Row) Binder() Binder
- func (ext *Row) Builder() *Builder
- 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() 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) Builder() *Builder
- 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() 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 Sqltx
- type Sqlx
- type Stmt
- func (ext *Stmt) Binder() Binder
- func (ext *Stmt) Builder() *Builder
- func (s *Stmt) Close() error
- func (ext *Stmt) DriverName() string
- 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 (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) 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 (ext *Stmt) Quote(s string) string
- func (ext *Stmt) Quoter() 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 (s *Stmt) Stmt() *sql.Stmt
- func (ext *Stmt) SupportLastInsertID() bool
- func (s *Stmt) Unsafe() *Stmt
- type Supporter
- type Trace
- type Transactioner
- type Transactionerx
- type Tx
- func (tx *Tx) BindNamed(query string, arg any) (string, []any, error)
- func (ext *Tx) Binder() Binder
- func (ext *Tx) Builder() *Builder
- func (tx *Tx) Commit() error
- func (tx *Tx) Create(query string, args ...any) (int64, error)
- func (tx *Tx) CreateContext(ctx context.Context, query string, args ...any) (int64, error)
- func (ext *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) 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) NamedCreate(query string, arg any) (int64, error)
- func (tx *Tx) NamedCreateContext(ctx context.Context, query string, arg any) (int64, error)
- 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, arg any) error
- func (tx *Tx) NamedGetContext(ctx context.Context, dest any, query string, arg 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) NamedQueryRow(query string, arg any) *Row
- func (tx *Tx) NamedQueryRowContext(ctx context.Context, query string, arg any) *Row
- func (tx *Tx) NamedSelect(dest any, query string, arg any) error
- func (tx *Tx) NamedSelectContext(ctx context.Context, dest any, query string, arg any) error
- func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt
- func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt
- func (tx *Tx) Prepare(query string) (*sql.Stmt, error)
- func (tx *Tx) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- 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) Query(query string, args ...any) (*sql.Rows, error)
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (tx *Tx) QueryRow(query string, args ...any) *sql.Row
- func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- 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() Quoter
- func (ext *Tx) Rebind(query string) string
- func (tx *Tx) Rollback() error
- 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) Stmt(stmt *sql.Stmt) *sql.Stmt
- func (tx *Tx) StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt
- 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) Tx() *sql.Tx
- func (tx *Tx) Unsafe() *Tx
Constants ¶
const ( BindUnknown = sqx.BindUnknown BindQuestion = sqx.BindQuestion BindDollar = sqx.BindDollar BindColon = sqx.BindColon BindAt = sqx.BindAt )
Variables ¶
var ( ErrConnDone = sql.ErrConnDone ErrNoRows = sql.ErrNoRows ErrTxDone = sql.ErrTxDone )
var ( QuoteDefault = sqx.QuoteDefault QuoteBackticks = sqx.QuoteBackticks QuoteBrackets = sqx.QuoteBrackets )
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 sqlx is used as name-to-field mappings are cached after first use on a type.
Functions ¶
func Create ¶ added in v1.0.26
Create does a QueryRowx() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() and returns Result.LastInsertId().
func CreateContext ¶ added in v1.0.26
CreateContext does a QueryRowxContext() scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() return Result.LastInsertId().
func Get ¶
Get does a QueryRowx() 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 QueryRowxContext() 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 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 NamedCreate ¶ added in v1.0.26
NamedCreate does a NamedQueryRowx() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() return Result.LastInsertId().
func NamedCreateContext ¶ added in v1.0.26
NamedCreateContext does a NamedQueryRow() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), does a NamedExecContext() and returns Result.LastInsertId().
func NamedGet ¶ added in v1.0.26
func NamedGet(q NamedQueryer, dest any, query string, arg any) error
NamedGet does a NamedQueryRow() 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 NamedGetContext ¶ added in v1.0.26
func NamedGetContext(ctx context.Context, q ContextNamedQueryer, dest any, query string, arg any) error
NamedGetContext does a NamedQueryRowContext() 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 NamedSelect ¶ added in v1.0.26
func NamedSelect(q NamedQueryer, dest any, query string, arg any) error
NamedSelect executes a query, 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 NamedSelectContext ¶ added in v1.0.26
func NamedSelectContext(ctx context.Context, q ContextNamedQueryer, dest any, query string, arg any) error
NamedSelectContext executes a query, 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 arg.
func Select ¶
Select executes a query, 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 ContextQueryerx, dest any, query string, args ...any) error
SelectContext executes a query, 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 arg.
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 sqlx.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 sqlx.Rows.StructScan. If rows is sqlx.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(ctx context.Context, db BeginTxxer, 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 ¶
type Builder ¶ added in v1.0.26
type Builder struct {
// contains filtered or unexported fields
}
Builder a simple sql builder NOTE: the arguments are strict to it's order
func (*Builder) CountDistinct ¶ added in v1.0.26
Count shortcut for SELECT COUNT(distinct *)
func (*Builder) Join ¶ added in v1.0.26
Join specify Join query and conditions
sqb.Join("JOIN emails ON emails.user_id = users.id AND emails.email = ?", "abc@example.org")
func (*Builder) Names ¶ added in v1.0.26
Names add named columns and values. Example:
sqb.Insert("a").Names("id", "name", "value") // INSERT INTO a (id, name, value) VALUES (:id, :name,, :value) sqb.Update("a").Names("name", "value").Where("id = :id") // UPDATE a SET name = :name, value = :value WHERE id = :id
func (*Builder) Returns ¶ added in v1.0.26
Returns add RETURNING cols... if `cols` is not specified, RETURNING *
func (*Builder) Select ¶ added in v1.0.26
Select add select columns if `cols` is not specified, default select "*"
func (*Builder) StructNames ¶ added in v1.0.26
StructNames add named columns and values for Struct. Example:
type User struct { ID int64 Name string Value string } u := &User{} sqb.Insert("users").StructNames(u) // INSERT INTO users (id, name, value) VALUES (:id, :name, :value) sqb.Update("users").StructNames(u, "id").Where("id = :id") // UPDATE users SET name = :name, value = :value WHERE id = :id
func (*Builder) StructPrefixSelect ¶ added in v1.0.26
StructPrefixSelect add columns for Struct. Example:
type User struct { ID int64 Name string Value string } u := &User{} sqb.StructPrefixSelect(u, "u.") // SELECT u.id, u.name, value FROM ...
func (*Builder) StructSelect ¶ added in v1.0.26
StructSelect add columns for Struct. Example:
type User struct { ID int64 Name string Value string } u := &User{} sqb.StructSelect(u) // SELECT id, name, value FROM ...
type ColScanner ¶
ColScanner is an interface used by MapScan and SliceScan
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a wrapper around sql.Conn with extra functionality
func (*Conn) BeginTx ¶ added in v1.0.26
BeginTx starts a transaction.
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 BeginTx is canceled.
The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*Conn) BeginTxx ¶
BeginTxx begins a transaction and returns an *sqlx.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) Beginx ¶ added in v1.0.26
Beginx begins a transaction and returns an *sqlx.Tx instead of an *sql.Tx.
func (*Conn) BindNamed ¶ added in v1.0.26
BindNamed binds a query using the DB driver's bindvar type.
func (*Conn) Binder ¶
func (ext *Conn) Binder() Binder
Binder returns the binder by driverName passed to the Open function for this DB.
func (*Conn) Builder ¶ added in v1.0.26
func (ext *Conn) Builder() *Builder
Builder returns a new sql builder
func (*Conn) Close ¶ added in v1.0.26
Close returns the connection to the connection pool. All operations after a Close will return with ErrConnDone. Close is safe to call concurrently with other operations and will block until all other operations finish. It may be useful to first cancel any used context and then call close directly after.
func (*Conn) Create ¶ added in v1.0.26
Create does a QueryRowx() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() and returns Result.LastInsertId().
func (*Conn) CreateContext ¶ added in v1.0.26
CreateContext does a QueryRowxContext() scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() return Result.LastInsertId().
func (*Conn) DriverName ¶
func (ext *Conn) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Conn) Exec ¶ added in v1.0.26
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Conn) ExecContext ¶ added in v1.0.26
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Conn) Get ¶ added in v1.0.26
Get does a QueryRowx() 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 (*Conn) GetContext ¶
GetContext does a QueryRowxContext() 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 (*Conn) NamedCreate ¶ added in v1.0.26
NamedCreate does a NamedQueryRowx() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() return Result.LastInsertId().
func (*Conn) NamedCreateContext ¶ added in v1.0.26
NamedCreateContext does a NamedQueryRow() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), does a NamedExecContext() and returns Result.LastInsertId().
func (*Conn) NamedExec ¶ added in v1.0.26
NamedExec using this Conn. Any named placeholder parameters are replaced with fields from arg.
func (*Conn) NamedExecContext ¶ added in v1.0.26
NamedExecContext using this Conn. Any named placeholder parameters are replaced with fields from arg.
func (*Conn) NamedGet ¶ added in v1.0.26
NamedGet does a NamedQueryRow() 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 (*Conn) NamedGetContext ¶ added in v1.0.26
NamedGetContext does a NamedQueryRowContext() 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 (*Conn) NamedQuery ¶ added in v1.0.26
NamedQuery using this Conn. Any named placeholder parameters are replaced with fields from arg.
func (*Conn) NamedQueryContext ¶ added in v1.0.26
NamedQueryContext using this Conn. Any named placeholder parameters are replaced with fields from arg.
func (*Conn) NamedQueryRow ¶ added in v1.0.26
NamedQueryRow using this Conn. Any named placeholder parameters are replaced with fields from arg.
func (*Conn) NamedQueryRowContext ¶ added in v1.0.26
NamedQueryRowContext using the Conn. Any named placeholder parameters are replaced with fields from arg.
func (*Conn) NamedSelect ¶ added in v1.0.26
NamedSelect executes a query, 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 (*Conn) NamedSelectContext ¶ added in v1.0.26
NamedSelectContext executes a query, 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 arg.
func (*Conn) PingContext ¶ added in v1.0.26
PingContext verifies the connection to the database is still alive.
func (*Conn) Prepare ¶ added in v1.0.26
Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Conn) PrepareContext ¶ added in v1.0.26
PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*Conn) Preparex ¶ added in v1.0.26
Preparex returns an sqlx.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) PreparexContext ¶
PreparexContext returns an sqlx.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) Query ¶ added in v1.0.26
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Conn) QueryContext ¶ added in v1.0.26
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Conn) QueryRow ¶ added in v1.0.26
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*Conn) QueryRowContext ¶ added in v1.0.26
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*Conn) QueryRowx ¶ added in v1.0.26
QueryRowx queries the database and returns an *sqlx.Row. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryRowxContext ¶
QueryRowxContext queries the database and returns an *sqlx.Row. Any placeholder parameters are replaced with supplied args.
func (*Conn) Queryx ¶ added in v1.0.26
Queryx queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
func (*Conn) QueryxContext ¶
QueryxContext queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
func (*Conn) Quoter ¶
func (ext *Conn) Quoter() Quoter
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*Conn) Raw ¶ added in v1.0.26
Raw executes f exposing the underlying driver connection for the duration of f. The driverConn must not be used outside of f.
Once f returns and err is not driver.ErrBadConn, the Conn will continue to be usable until Conn.Close is called.
func (*Conn) Select ¶ added in v1.0.26
Select executes a query, 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 (*Conn) SelectContext ¶
SelectContext executes a query, 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 arg.
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 ContextMixer ¶ added in v1.0.26
type ContextNamedExecer ¶ added in v1.0.26
type ContextNamedQueryer ¶ added in v1.0.26
type ContextPreparerx ¶ added in v1.0.26
type ContextQueryerx ¶ added in v1.0.26
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
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 *sqlx.DB instead and panics on error.
func NewDB ¶
NewDB returns a new sqlx DB wrapper for a pre-existing *sql.DB. The driverName of the original database is required for named query support.
func (*DB) Begin ¶ added in v1.0.26
Begin starts a transaction. The default isolation level is dependent on the driver.
func (*DB) BeginTx ¶ added in v1.0.26
BeginTx starts a transaction.
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 BeginTx is canceled.
The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*DB) BeginTxx ¶
BeginTxx begins a transaction and returns an *sqlx.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) Builder ¶ added in v1.0.26
func (ext *DB) Builder() *Builder
Builder returns a new sql builder
func (*DB) Close ¶ added in v1.0.26
Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish.
It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.
func (*DB) Conn ¶ added in v1.0.26
Conn returns a single connection by either opening a new connection or returning an existing connection from the connection pool. Conn will block until either a connection is returned or ctx is canceled. Queries run on the same Conn will be run in the same database session.
Every Conn must be returned to the database pool after use by calling Conn.Close.
func (*DB) Create ¶ added in v1.0.26
Create does a QueryRowx() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() and returns Result.LastInsertId().
func (*DB) CreateContext ¶ added in v1.0.26
CreateContext does a QueryRowxContext() scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() return Result.LastInsertId().
func (*DB) DriverName ¶
func (ext *DB) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*DB) Exec ¶ added in v1.0.26
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*DB) ExecContext ¶ added in v1.0.26
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*DB) Get ¶
Get does a QueryRowx() 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 (*DB) GetContext ¶
GetContext does a QueryRowxContext() 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 (*DB) MapperFunc ¶
MapperFunc sets a new mapper for this db using the default sqlx struct tag and the provided mapper function.
func (*DB) MustBeginTx ¶
MustBeginTx starts a transaction, and panics on error. Returns an *sqlx.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) MustBeginx ¶ added in v1.0.26
MustBeginx starts a transaction, and panics on error. Returns an *sqlx.Tx instead of an *sql.Tx.
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) NamedCreate ¶ added in v1.0.26
NamedCreate does a NamedQueryRowx() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() return Result.LastInsertId().
func (*DB) NamedCreateContext ¶ added in v1.0.26
NamedCreateContext does a NamedQueryRow() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), does a NamedExecContext() and returns Result.LastInsertId().
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) NamedGet ¶ added in v1.0.26
NamedGet does a NamedQueryRow() 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 (*DB) NamedGetContext ¶ added in v1.0.26
NamedGetContext does a NamedQueryRowContext() 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 (*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) NamedQueryRowContext ¶ added in v1.0.26
NamedQueryRowContext using the DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedSelect ¶ added in v1.0.26
NamedSelect executes a query, 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 (*DB) NamedSelectContext ¶ added in v1.0.26
NamedSelectContext executes a query, 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 arg.
func (*DB) Ping ¶ added in v1.0.26
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
func (*DB) PingContext ¶ added in v1.0.26
PingContext verifies a connection to the database is still alive, establishing a connection if necessary.
func (*DB) PrepareContext ¶ added in v1.0.26
PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement.
func (*DB) PrepareNamed ¶
PrepareNamed returns an sqlx.NamedStmt
func (*DB) PrepareNamedContext ¶
PrepareNamedContext returns an sqlx.NamedStmt
func (*DB) PreparexContext ¶
PreparexContext returns an sqlx.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) Query ¶ added in v1.0.26
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryContext ¶ added in v1.0.26
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryRow ¶ added in v1.0.26
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*DB) QueryRowContext ¶ added in v1.0.26
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*DB) QueryRowx ¶
QueryRowx queries the database and returns an *sqlx.Row. Any placeholder parameters are replaced with supplied args.
func (*DB) QueryRowxContext ¶
QueryRowxContext queries the database and returns an *sqlx.Row. Any placeholder parameters are replaced with supplied args.
func (*DB) Queryx ¶
Queryx queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
func (*DB) QueryxContext ¶
QueryxContext queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
func (*DB) Quoter ¶
func (ext *DB) Quoter() Quoter
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*DB) Select ¶
Select executes a query, 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 (*DB) SelectContext ¶
SelectContext executes a query, 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 arg.
func (*DB) SetConnMaxIdleTime ¶ added in v1.0.26
SetConnMaxIdleTime sets the maximum amount of time a connection may be idle.
Expired connections may be closed lazily before reuse.
If d <= 0, connections are not closed due to a connection's idle time.
func (*DB) SetConnMaxLifetime ¶ added in v1.0.26
SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
Expired connections may be closed lazily before reuse.
If d <= 0, connections are not closed due to a connection's age.
func (*DB) SetMaxIdleConns ¶ added in v1.0.26
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
If MaxOpenConns is greater than 0 but less than the new MaxIdleConns, then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.
If n <= 0, no idle connections are retained.
The default max idle connections is currently 2. This may change in a future release.
func (*DB) SetMaxOpenConns ¶ added in v1.0.26
SetMaxOpenConns sets the maximum number of open connections to the database.
If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit.
If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).
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 NamedExecer ¶
type NamedQueryer ¶
type NamedStmt ¶
type NamedStmt struct {
// 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 sqlx cannot create a *sql.Row with an error condition pre-set for binding errors, sqlx returns a *sqlx.Row instead. Any named placeholder parameters are replaced with fields from arg.
func (*NamedStmt) QueryRowContext ¶
QueryRowContext executes a named statement against the database. Because sqlx cannot create a *sql.Row with an error condition pre-set for binding errors, sqlx returns a *sqlx.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 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) Builder ¶ added in v1.0.26
func (ext *Row) Builder() *Builder
Builder returns a new sql builder
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 ¶
func (ext *Row) Quoter() 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 (*Rows) Binder ¶
func (ext *Rows) Binder() Binder
Binder returns the binder by driverName passed to the Open function for this DB.
func (*Rows) Builder ¶ added in v1.0.26
func (ext *Rows) Builder() *Builder
Builder returns a new sql builder
func (*Rows) DriverName ¶
func (ext *Rows) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Rows) Quoter ¶
func (ext *Rows) Quoter() 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 Sqltx ¶ added in v1.0.26
type Sqltx interface { Sqlx Transactioner }
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt is an sqlx 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) Builder ¶ added in v1.0.26
func (ext *Stmt) Builder() *Builder
Builder returns a new sql builder
func (*Stmt) DriverName ¶
func (ext *Stmt) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Stmt) Exec ¶ added in v1.0.26
Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (*Stmt) ExecContext ¶ added in v1.0.26
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
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) Query ¶ added in v1.0.26
Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (*Stmt) QueryContext ¶ added in v1.0.26
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
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 ¶
func (ext *Stmt) Quoter() 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 Transactioner ¶ added in v1.0.26
type Transactionerx ¶ added in v1.0.26
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is an sqlx 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) Builder ¶ added in v1.0.26
func (ext *Tx) Builder() *Builder
Builder returns a new sql builder
func (*Tx) Create ¶ added in v1.0.26
Create does a QueryRowx() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() and returns Result.LastInsertId().
func (*Tx) CreateContext ¶ added in v1.0.26
CreateContext does a QueryRowxContext() scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() return Result.LastInsertId().
func (*Tx) DriverName ¶
func (ext *Tx) DriverName() string
DriverName returns the driverName passed to the Open function for this DB.
func (*Tx) Exec ¶ added in v1.0.26
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Tx) ExecContext ¶ added in v1.0.26
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Tx) Get ¶
Get does a QueryRowx() 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 (*Tx) GetContext ¶
GetContext does a QueryRowxContext() 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 (*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) NamedCreate ¶ added in v1.0.26
NamedCreate does a NamedQueryRowx() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), do a Exec() return Result.LastInsertId().
func (*Tx) NamedCreateContext ¶ added in v1.0.26
NamedCreateContext does a NamedQueryRow() and scans the resulting row returns the last inserted ID. If the db supports LastInsertId(), does a NamedExecContext() and returns Result.LastInsertId().
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) NamedGet ¶ added in v1.0.26
NamedGet does a NamedQueryRow() 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 (*Tx) NamedGetContext ¶ added in v1.0.26
NamedGetContext does a NamedQueryRowContext() 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 (*Tx) NamedQuery ¶
NamedQuery within a transaction. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedQueryContext ¶ added in v1.0.26
NamedQueryContext using this Tx. 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) NamedQueryRowContext ¶ added in v1.0.26
NamedQueryRowContext within a transaction. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedSelect ¶ added in v1.0.26
NamedSelect executes a query, 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 (*Tx) NamedSelectContext ¶ added in v1.0.26
NamedSelectContext executes a query, 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 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) Prepare ¶ added in v1.0.26
Prepare creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed when the transaction has been committed or rolled back.
To use an existing prepared statement on this transaction, see Tx.Stmt.
func (*Tx) PrepareContext ¶ added in v1.0.26
PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement.
func (*Tx) PrepareNamed ¶
PrepareNamed returns an sqlx.NamedStmt
func (*Tx) PrepareNamedContext ¶
PrepareNamedContext returns an sqlx.NamedStmt
func (*Tx) PreparexContext ¶
PreparexContext returns an sqlx.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) Query ¶ added in v1.0.26
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Tx) QueryContext ¶ added in v1.0.26
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Tx) QueryRow ¶ added in v1.0.26
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*Tx) QueryRowContext ¶ added in v1.0.26
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
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 ¶
func (ext *Tx) Quoter() Quoter
Quoter returns the quoter by driverName passed to the Open function for this DB.
func (*Tx) Select ¶
Select executes a query, 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 (*Tx) SelectContext ¶
SelectContext executes a query, 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 arg.
func (*Tx) Stmt ¶ added in v1.0.26
Stmt returns a transaction-specific prepared statement from an existing statement.
func (*Tx) StmtContext ¶ added in v1.0.26
StmtContext returns a transaction-specific prepared statement from an existing statement.
func (*Tx) Stmtx ¶
Stmtx returns a version of the prepared statement which runs within a transaction. Provided stmt can be either *sql.Stmt or *sqlx.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 *sqlx.Stmt.
func (*Tx) SupportLastInsertID ¶
func (ext *Tx) SupportLastInsertID() bool
SupportRetuning check sql driver support "RETUNING"