sqlx

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

README

sqlx-v2

Go Reference Go Report Card License

sqlx-v2 is an extension of the standard database/sql library, implementing generic type instantiation and offset-based pointer arithmetic for mapping SQL rows directly into Go structures, maps, and slices. It operates as a binary-compatible successor to jmoiron/sqlx.


Overview

The standard database/sql library requires callers to iterate over result sets and pass variable references manually via rows.Scan.

Standard database/sql
for rows.Next() {
    var u User
    err := rows.Scan(&u.ID, &u.Name, &u.Email, &u.CreatedAt, &u.Active)
    if err != nil {
        return nil, err
    }
    users = append(users, u)
}
sqlx-v2

sqlx-v2 automates struct mapping using generic interface parameters.

users, err := sqlx.SelectG[User](ctx, db, "SELECT * FROM users")

Usage

1. Requirements
go get github.com/rpadovani/sqlx-v2

Requires Go 1.24+ to compile the iterator and type parameter patterns.

2. Initialization

sqlx-v2 delegates to standard Go database drivers (e.g. pgx, mysql, sqlite3).

import (
    "github.com/rpadovani/sqlx-v2"
    _ "github.com/jackc/pgx/v5/stdlib"
)

db, err := sqlx.Connect("pgx", "postgres://user:pass@localhost/db")
3. Execution Data-Paths
// Single row instantiation
user, err := sqlx.GetG[User](ctx, db, "SELECT * FROM users WHERE id = $1", id)

// Contiguous memory array instantiation
users, err := sqlx.SelectG[User](ctx, db, "SELECT * FROM users WHERE active = $1", true)

// Iterative sequence evaluation (O(1) memory bounds)
for user, err := range sqlx.SelectIter[User](ctx, db, "SELECT * FROM users") {
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(user.Name)
}

Performance Profile

sqlx-v2 executes contiguous memory writes during result mapping. Memory footprint metrics are bound correctly by skipping dynamic reflection evaluation during the core row reading loop.

Read Benchmark Specification →

Process (1,000 Rows, 50-Field Struct) Execution Duration Cost Output Memory Heap
SelectIter[T] 17.8% reduction (vs v1) 52.1% reduction (vs v1)
SelectG[T] 28.7% reduction (vs v1) 50.9% reduction (vs v1)

Implementation Characteristics

Contiguous Memory Writes

sqlx-v2 indexes structural dimensions into linear scalar byte offsets. During map iterations, it calculates fields by invoking a single runtime.KeepAlive() protected arithmetic statement (P_target = uintptr(base) + offset) to pass exact buffer addresses to the driver. The recursive tree is exclusively mapped once per struct definition lifetime.

Primitive Yield Structures

Methods implement native generics, terminating immediately in fully allocated struct models, bypassing interface{} allocation steps.

Buffered Synchronization

The system caches a sync.Pool of standardized output bindings. Output pointers dynamically reuse these boundaries to subtract slice duplication processes inside the map engine loop.

Validation Matrices

Data paths undergo algorithmic bounds verification via Go property mapping frameworks, establishing bidirectional integrity (Write == Read). Buffer integrity spans execution sequences without crossing safety zones.


Subsystem Interface

The library exports legacy signatures corresponding to internal definitions modeled by jmoiron/sqlx for binary-compatible drop-in.

Attribute sqlx-v2 v1 (jmoiron/sqlx)
Go requirement 1.24+ Backwards compliant
Address Generation Offset-based Calculation Type Field Traversal
Parameterization Generics Definitions Interface Wrapping
Compatibility Type Compliant Interfaces Source Standard

Design and Runtime Mechanisms

The execution map assumes definitions conform to runtime constraint standards:

  1. KeepAlive Enforcement: Evaluates object references explicitly so GC routines maintain allocation maps through native driver block scopes.
  2. Barrier Adherence: Embedded object chaining defaults to reflect.NewAt() to uphold Go write-barriers during address generation paths.
  3. Execution Mapping: Calculation arithmetic honors the runtime limits defined against unsafe.Pointer manipulation boundaries.

Proceed to exact definitions: ARCHITECTURE.md


Development

Modifications process strictly inline with internal tracking specs: CONTRIBUTING.md. Computational execution paths must pass evaluation frameworks like benchstat. Commits exhibiting >2% delta reductions inside critical bounds correctly isolate execution loops and halt commit progress limits.

License

Apache 2.0. Reference LICENSE.

Disclaimer

This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for any particular purpose.

Documentation

Index

Constants

View Source
const (
	UNKNOWN  = bind.UNKNOWN
	QUESTION = bind.QUESTION
	DOLLAR   = bind.DOLLAR
	NAMED    = bind.NAMED
	AT       = bind.AT
)

Bindvar type constants. These are re-exported from the internal bind package to maintain API compatibility with jmoiron/sqlx.

Variables

View Source
var (
	// ErrBindMismatch is returned when there is a mismatch between query variables and arguments.
	ErrBindMismatch = bind.ErrBindMismatch

	// ErrNamedPropertyNotFound is returned when a named parameter cannot be found in the provided struct or map.
	ErrNamedPropertyNotFound = bind.ErrNamedPropertyNotFound

	// ErrUnsupportedType is returned when an unsupported type is provided for binding.
	ErrUnsupportedType = bind.ErrUnsupportedType

	// ErrSyntax is returned when there is a syntax error in the query parsing.
	ErrSyntax = bind.ErrSyntax

	// ErrColumnNotFound is returned when a column from the database cannot be mapped to a destination.
	ErrColumnNotFound = bind.ErrColumnNotFound
)
View Source
var ErrStopIter = fmt.Errorf("stop iteration")
View Source
var NameMapper = strings.ToLower

NameMapper maps 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 sqlx is used as name-to-field mappings are cached after first use on a type.

Functions

func BindDriver

func BindDriver(driverName string, bindType int)

BindDriver sets the BindType for driverName to bindType.

func BindType

func BindType(driverName string) int

BindType returns the bindtype for a given database given a drivername.

func Get

func Get(q Queryer, dest any, query string, args ...any) error

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.

func GetContext

func GetContext(ctx context.Context, q QueryerContext, dest any, query string, args ...any) error

GetContext does a QueryRowContext using the provided QueryerContext, and scans the resulting row to dest.

func GetG

func GetG[T any](ctx context.Context, q QueryerContext, query string, args ...any) (res T, err error)

GetG executes a query that is expected to return at most one row, scanning it into a value of type T. It uses pre-calculated struct field offsets for efficient scanning.

user, err := sqlx.GetG[User](ctx, db, "SELECT * FROM users WHERE id = ?", 1)

func In

func In(query string, args ...any) (string, []any, error)

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.

func LoadFile

func LoadFile(e Execer, path string) (*sql.Result, error)

LoadFile exec's every statement in a file. Used for initializing schemas.

func LoadFileContext

func LoadFileContext(ctx context.Context, e ExecerContext, path string) (*sql.Result, error)

LoadFileContext exec's every statement in a file with context.

func MapScan

func MapScan(r ColScanner, dest map[string]any) error

MapScan scans a single row into a map[string]any.

func MustExec

func MustExec(e Execer, query string, args ...any) sql.Result

MustExec execs the query using e and panics if there was an error.

func MustExecContext

func MustExecContext(ctx context.Context, e ExecerContext, query string, args ...any) sql.Result

MustExecContext execs the query using e and panics if there was an error.

func Named

func Named(query string, arg any) (string, []any, error)

Named takes a query using named parameters and an argument and returns a new query with the named parameters replaced with positional parameters and the corresponding argument list.

func NamedExec

func NamedExec(e Ext, query string, arg any) (sql.Result, error)

NamedExec uses BindNamed to bind a query and then runs Exec on the result.

func NamedExecContext

func NamedExecContext(ctx context.Context, e ExtContext, query string, arg any) (sql.Result, error)

NamedExecContext uses BindNamed to bind a query and then runs Exec on the result.

func Rebind

func Rebind(bindType int, query string) string

Rebind a query from QUESTION to the specified bind type.

func Select

func Select(q Queryer, dest any, query string, args ...any) error

Select executes a query using the provided Queryer, and StructScans each row into dest, which must be a slice.

func SelectContext

func SelectContext(ctx context.Context, q QueryerContext, dest any, query string, args ...any) error

SelectContext executes a query using the provided QueryerContext, and StructScans each row into dest, which must be a slice.

func SelectG

func SelectG[T any](ctx context.Context, q QueryerContext, query string, args ...any) (res []T, err error)

SelectG executes a query and returns a slice of T, using generics for type safety. It uses pre-calculated struct field offsets for efficient scanning.

users, err := sqlx.SelectG[User](ctx, db, "SELECT * FROM users WHERE active = ?", true)

func SelectIter

func SelectIter[T any](ctx context.Context, q QueryerContext, query string, args ...any) iter.Seq2[T, error]

SelectIter returns an iterator (iter.Seq2) that streams rows one at a time, scanning each into a value of type T using pre-calculated struct field offsets. This avoids loading all results into memory at once.

for user, err := range sqlx.SelectIter[User](ctx, db, "SELECT * FROM users") {
    if err != nil {
        return err
    }
    process(user)
}

func SliceScan

func SliceScan(r ColScanner) ([]any, error)

SliceScan using this Rows.

func StructScan

func StructScan(r ColScanner, dest any) error

StructScan scans a ColScanner (Row or Rows) into a struct. It respects the unsafe flag from Row or Rows; if not in unsafe mode, unmapped columns will cause an error.

Types

type ColScanner

type ColScanner interface {
	Columns() ([]string, error)
	Scan(dest ...any) error
	Err() error
}

ColScanner defines the interface for MapScan and SliceScan.

type Conn

type Conn struct {
	*sql.Conn
	DriverName       string
	Mapper           *reflectx.Mapper
	Unsafe           bool
	StrictTagParsing bool
}

Conn wraps sql.Conn with extra functionality.

func (*Conn) BeginTxx

func (c *Conn) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTxx begins a transaction and returns an *sqlx.Tx.

func (*Conn) GetContext

func (c *Conn) GetContext(ctx context.Context, dest any, query string, args ...any) error

GetContext using this Conn.

func (*Conn) PreparexContext

func (c *Conn) PreparexContext(ctx context.Context, query string) (*Stmt, error)

PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.

func (*Conn) QueryRowxContext

func (c *Conn) QueryRowxContext(ctx context.Context, query string, args ...any) *Row

QueryRowxContext queries the database and returns an *sqlx.Row.

func (*Conn) QueryxContext

func (c *Conn) QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error)

QueryxContext queries the database and returns an *sqlx.Rows.

func (*Conn) Rebind

func (c *Conn) Rebind(query string) string

Rebind a query within a Conn's bindvar type.

func (*Conn) SelectContext

func (c *Conn) SelectContext(ctx context.Context, dest any, query string, args ...any) error

SelectContext using this Conn.

type DB

type DB struct {
	*sql.DB
	DriverName       string
	Mapper           *reflectx.Mapper
	Unsafe           bool
	StrictTagParsing bool
}

DB wraps sql.DB with extra functionality.

func Connect

func Connect(driverName, dataSourceName string) (*DB, error)

Connect to a database and verify with a ping.

func ConnectContext

func ConnectContext(ctx context.Context, driverName, dataSourceName string) (*DB, error)

ConnectContext to a database and verify with a ping.

func MustConnect

func MustConnect(driverName, dataSourceName string) *DB

MustConnect connects to a database and panics on error.

func MustOpen

func MustOpen(driverName, dataSourceName string) *DB

MustOpen is the same as sql.Open, but returns an *sqlx.DB instead and panics on error.

func NewDb

func NewDb(db *sql.DB, driverName string) *DB

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 Open

func Open(driverName, dataSourceName string) (*DB, error)

Open is the same as sql.Open, but returns an *sqlx.DB instead.

func (*DB) BeginTxx

func (db *DB) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTxx begins a transaction and returns an *sqlx.Tx instead of an *sql.Tx.

func (*DB) Beginx

func (db *DB) Beginx() (*Tx, error)

Beginx begins a transaction and returns an *sqlx.Tx instead of an *sql.Tx.

func (*DB) BindNamed

func (db *DB) BindNamed(query string, arg any) (string, []any, error)

BindNamed binds a query using the DB driver's bindvar type.

func (*DB) Connx

func (db *DB) Connx(ctx context.Context) (*Conn, error)

Connx returns an *sqlx.Conn instead of an *sql.Conn.

func (*DB) Get

func (db *DB) Get(dest any, query string, args ...any) error

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

func (db *DB) GetContext(ctx context.Context, dest any, query string, args ...any) error

GetContext using this DB.

func (*DB) MapperFunc

func (db *DB) MapperFunc(mf func(string) string)

MapperFunc sets a new mapper for this db using the default sqlx struct tag and the provided mapper function.

func (*DB) MustBegin

func (db *DB) MustBegin() *Tx

MustBegin starts a transaction, and panics on error.

func (*DB) MustBeginTx

func (db *DB) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *Tx

MustBeginTx starts a transaction with context, and panics on error.

func (*DB) MustExec

func (db *DB) MustExec(query string, args ...any) sql.Result

MustExec (panic) runs MustExec using this database.

func (*DB) MustExecContext

func (db *DB) MustExecContext(ctx context.Context, query string, args ...any) sql.Result

MustExecContext (panic) runs MustExecContext using this database.

func (*DB) NamedExec

func (db *DB) NamedExec(query string, arg any) (sql.Result, error)

NamedExec using this DB. Any named placeholder parameters are replaced with fields from arg.

func (*DB) NamedExecContext

func (db *DB) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)

NamedExecContext using this DB.

func (*DB) NamedQuery

func (db *DB) NamedQuery(query string, arg any) (*Rows, error)

NamedQuery using this DB. Any named placeholder parameters are replaced with fields from arg.

func (*DB) NamedQueryContext

func (db *DB) NamedQueryContext(ctx context.Context, query string, arg any) (*Rows, error)

NamedQueryContext using this DB.

func (*DB) PrepareNamed

func (db *DB) PrepareNamed(query string) (*NamedStmt, error)

PrepareNamed returns an sqlx.NamedStmt.

func (*DB) PrepareNamedContext

func (db *DB) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)

PrepareNamedContext returns an sqlx.NamedStmt.

func (*DB) Preparex

func (db *DB) Preparex(query string) (*Stmt, error)

Preparex returns an sqlx.Stmt instead of a sql.Stmt.

func (*DB) PreparexContext

func (db *DB) PreparexContext(ctx context.Context, query string) (*Stmt, error)

PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.

func (*DB) QueryRowx

func (db *DB) QueryRowx(query string, args ...any) *Row

QueryRowx queries the database and returns an *sqlx.Row.

func (*DB) QueryRowxContext

func (db *DB) QueryRowxContext(ctx context.Context, query string, args ...any) *Row

QueryRowxContext queries the database and returns an *sqlx.Row.

func (*DB) Queryx

func (db *DB) Queryx(query string, args ...any) (*Rows, error)

Queryx queries the database and returns an *sqlx.Rows.

func (*DB) QueryxContext

func (db *DB) QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error)

QueryxContext queries the database and returns an *sqlx.Rows.

func (*DB) Rebind

func (db *DB) Rebind(query string) string

Rebind transforms a query from QUESTION to the DB driver's bindvar type.

func (*DB) Select

func (db *DB) Select(dest any, query string, args ...any) error

Select using this DB. Any placeholder parameters are replaced with supplied args.

func (*DB) SelectContext

func (db *DB) SelectContext(ctx context.Context, dest any, query string, args ...any) error

SelectContext using this DB.

type Execer

type Execer interface {
	Exec(query string, args ...any) (sql.Result, error)
}

Execer defines the interface for MustExec and LoadFile.

type ExecerContext

type ExecerContext interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

ExecerContext defines the interface for MustExecContext and LoadFileContext.

type Ext

type Ext interface {
	Queryer
	Execer
}

Ext defines a union interface which can Bind, Query, and Exec.

type ExtContext

type ExtContext interface {
	QueryerContext
	ExecerContext
}

ExtContext defines a union interface which can Bind, Query, and Exec with context.

type NamedStmt

type NamedStmt struct {
	Stmt             *sql.Stmt
	QueryString      string
	Params           []string
	Mapper           *reflectx.Mapper
	Unsafe           bool
	StrictTagParsing bool
}

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) Close

func (n *NamedStmt) Close() error

Close closes the named statement.

func (*NamedStmt) Exec

func (n *NamedStmt) Exec(arg any) (sql.Result, error)

Exec executes a named statement using the struct passed. If the struct is a slice or array, it iterates and executes for each element.

func (*NamedStmt) ExecContext

func (n *NamedStmt) ExecContext(ctx context.Context, arg any) (sql.Result, error)

ExecContext executes a named statement using the struct passed. If the struct is a slice or array, it iterates and executes for each element.

func (*NamedStmt) Get

func (n *NamedStmt) Get(dest any, arg any) error

Get using this NamedStmt.

func (*NamedStmt) GetContext

func (n *NamedStmt) GetContext(ctx context.Context, dest any, arg any) error

GetContext using this NamedStmt.

func (*NamedStmt) MustExec

func (n *NamedStmt) MustExec(arg any) sql.Result

MustExec (panic) runs MustExec using this NamedStmt.

func (*NamedStmt) MustExecContext

func (n *NamedStmt) MustExecContext(ctx context.Context, arg any) sql.Result

MustExecContext (panic) runs MustExecContext using this NamedStmt.

func (*NamedStmt) Query

func (n *NamedStmt) Query(arg any) (*sql.Rows, error)

Query executes a named statement using the struct passed, returns *sql.Rows.

func (*NamedStmt) QueryContext

func (n *NamedStmt) QueryContext(ctx context.Context, arg any) (*sql.Rows, error)

QueryContext executes a named statement using the struct passed, returns *sql.Rows.

func (*NamedStmt) QueryRow

func (n *NamedStmt) QueryRow(arg any) *Row

QueryRow executes a named statement using the struct passed, returns *sqlx.Row.

func (*NamedStmt) QueryRowContext

func (n *NamedStmt) QueryRowContext(ctx context.Context, arg any) *Row

QueryRowContext executes a named statement returning an *sqlx.Row.

func (*NamedStmt) QueryRowx

func (n *NamedStmt) QueryRowx(arg any) *Row

QueryRowx executes a named statement using the struct passed, returns *sqlx.Row.

func (*NamedStmt) QueryRowxContext

func (n *NamedStmt) QueryRowxContext(ctx context.Context, arg any) *Row

QueryRowxContext executes a named statement returning an *sqlx.Row.

func (*NamedStmt) Queryx

func (n *NamedStmt) Queryx(arg any) (*Rows, error)

Queryx executes a named statement returning an *sqlx.Rows.

func (*NamedStmt) QueryxContext

func (n *NamedStmt) QueryxContext(ctx context.Context, arg any) (*Rows, error)

QueryxContext executes a named statement returning an *sqlx.Rows.

func (*NamedStmt) Select

func (n *NamedStmt) Select(dest any, arg any) error

Select using this NamedStmt.

func (*NamedStmt) SelectContext

func (n *NamedStmt) SelectContext(ctx context.Context, dest any, arg any) error

SelectContext using this NamedStmt.

type Preparer

type Preparer interface {
	Prepare(query string) (*sql.Stmt, error)
}

Preparer defines the interface for Preparex.

type PreparerContext

type PreparerContext interface {
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
}

PreparerContext defines the interface for PreparexContext.

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 defines the interface for Get and Select.

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 defines the interface for GetContext and SelectContext.

type Row

type Row struct {
	Mapper           *reflectx.Mapper
	Unsafe           bool
	StrictTagParsing bool
	// contains filtered or unexported fields
}

Row reimplements sql.Row to provide access to the underlying sql.Rows object.

func (*Row) ColumnTypes

func (r *Row) ColumnTypes() ([]*sql.ColumnType, error)

ColumnTypes returns the underlying sql.Rows.ColumnTypes(), or the deferred error.

func (*Row) Columns

func (r *Row) Columns() ([]string, error)

Columns returns the underlying sql.Rows.Columns(), or the deferred error.

func (*Row) Err

func (r *Row) Err() error

Err returns the error encountered, if any.

func (*Row) MapScan

func (r *Row) MapScan(dest map[string]any) error

MapScan scans a single Row into the dest map[string]any.

func (*Row) Scan

func (r *Row) Scan(dest ...any) (err error)

Scan implements sql.Row.Scan without discarding underlying errors.

func (*Row) SliceScan

func (r *Row) SliceScan() ([]any, error)

SliceScan a row, returning a []any with values similar to MapScan.

func (*Row) StructScan

func (r *Row) StructScan(dest any) error

StructScan a single Row into dest.

type Rows

type Rows struct {
	*sql.Rows
	Mapper           *reflectx.Mapper
	Unsafe           bool
	StrictTagParsing bool
	// contains filtered or unexported fields
}

Rows wraps sql.Rows to cache costly reflection operations.

func NamedQuery

func NamedQuery(e Ext, query string, arg any) (*Rows, error)

NamedQuery binds a named query and then runs Query on the result using the provided Ext (which is typically a *DB or *Tx).

func NamedQueryContext

func NamedQueryContext(ctx context.Context, e ExtContext, query string, arg any) (*Rows, error)

NamedQueryContext binds a named query and then runs Query on the result using the provided ExtContext.

func (*Rows) MapScan

func (r *Rows) MapScan(dest map[string]any) error

MapScan scans a single Row from Rows into the dest map[string]any.

func (*Rows) SliceScan

func (r *Rows) SliceScan() ([]any, error)

SliceScan a row, returning a []any with values similar to MapScan.

func (*Rows) StructScan

func (r *Rows) StructScan(dest any) error

type Stmt

type Stmt struct {
	*sql.Stmt
	Mapper           *reflectx.Mapper
	Unsafe           bool
	StrictTagParsing bool
}

Stmt wraps sql.Stmt with extra functionality.

func Preparex

func Preparex(p Preparer, query string) (*Stmt, error)

Preparex prepares a statement and returns an *sqlx.Stmt.

func PreparexContext

func PreparexContext(ctx context.Context, p PreparerContext, query string) (*Stmt, error)

PreparexContext prepares a statement with context and returns an *sqlx.Stmt.

func (*Stmt) Get

func (s *Stmt) Get(dest any, args ...any) error

Get using this prepared statement.

func (*Stmt) GetContext

func (s *Stmt) GetContext(ctx context.Context, dest any, args ...any) error

GetContext using this prepared statement.

func (*Stmt) MustExec

func (s *Stmt) MustExec(args ...any) sql.Result

MustExec (panic) runs MustExec using this statement.

func (*Stmt) MustExecContext

func (s *Stmt) MustExecContext(ctx context.Context, args ...any) sql.Result

MustExecContext (panic) runs MustExecContext using this statement.

func (*Stmt) QueryRowx

func (s *Stmt) QueryRowx(args ...any) *Row

QueryRowx using this prepared statement.

func (*Stmt) QueryRowxContext

func (s *Stmt) QueryRowxContext(ctx context.Context, args ...any) *Row

QueryRowxContext using this prepared statement.

func (*Stmt) Queryx

func (s *Stmt) Queryx(args ...any) (*Rows, error)

Queryx using this prepared statement.

func (*Stmt) QueryxContext

func (s *Stmt) QueryxContext(ctx context.Context, args ...any) (*Rows, error)

QueryxContext using this prepared statement.

func (*Stmt) Select

func (s *Stmt) Select(dest any, args ...any) error

Select using this prepared statement.

func (*Stmt) SelectContext

func (s *Stmt) SelectContext(ctx context.Context, dest any, args ...any) error

SelectContext using this prepared statement.

type Tx

type Tx struct {
	*sql.Tx
	DriverName       string
	Mapper           *reflectx.Mapper
	Unsafe           bool
	StrictTagParsing bool
}

Tx wraps sql.Tx with extra functionality.

func (*Tx) BindNamed

func (tx *Tx) BindNamed(query string, arg any) (string, []any, error)

BindNamed binds a query within this transaction's bindvar type.

func (*Tx) Get

func (tx *Tx) Get(dest any, query string, args ...any) error

Get within this transaction.

func (*Tx) GetContext

func (tx *Tx) GetContext(ctx context.Context, dest any, query string, args ...any) error

GetContext within this transaction.

func (*Tx) MustExec

func (tx *Tx) MustExec(query string, args ...any) sql.Result

MustExec runs MustExec within this transaction.

func (*Tx) MustExecContext

func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...any) sql.Result

MustExecContext runs MustExecContext within this transaction.

func (*Tx) NamedExec

func (tx *Tx) NamedExec(query string, arg any) (sql.Result, error)

NamedExec a named query within this transaction.

func (*Tx) NamedExecContext

func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)

NamedExecContext a named query within this transaction.

func (*Tx) NamedQuery

func (tx *Tx) NamedQuery(query string, arg any) (*Rows, error)

NamedQuery within this transaction.

func (*Tx) NamedQueryContext

func (tx *Tx) NamedQueryContext(ctx context.Context, query string, arg any) (*Rows, error)

NamedQueryContext within this transaction.

func (*Tx) NamedStmt

func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt

NamedStmt returns a version of the prepared statement which runs within a transaction.

func (*Tx) NamedStmtContext

func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt

NamedStmtContext returns a version of the prepared statement which runs within a transaction.

func (*Tx) PrepareNamed

func (tx *Tx) PrepareNamed(query string) (*NamedStmt, error)

PrepareNamed returns an sqlx.NamedStmt.

func (*Tx) PrepareNamedContext

func (tx *Tx) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)

PrepareNamedContext returns an sqlx.NamedStmt.

func (*Tx) Preparex

func (tx *Tx) Preparex(query string) (*Stmt, error)

Preparex returns an sqlx.Stmt instead of a sql.Stmt.

func (*Tx) PreparexContext

func (tx *Tx) PreparexContext(ctx context.Context, query string) (*Stmt, error)

PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.

func (*Tx) QueryRowx

func (tx *Tx) QueryRowx(query string, args ...any) *Row

QueryRowx within this transaction.

func (*Tx) QueryRowxContext

func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...any) *Row

QueryRowxContext within this transaction.

func (*Tx) Queryx

func (tx *Tx) Queryx(query string, args ...any) (*Rows, error)

Queryx within this transaction.

func (*Tx) QueryxContext

func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...any) (*Rows, error)

QueryxContext within this transaction.

func (*Tx) Rebind

func (tx *Tx) Rebind(query string) string

Rebind a query within a transaction's bindvar type.

func (*Tx) Select

func (tx *Tx) Select(dest any, query string, args ...any) error

Select within this transaction.

func (*Tx) SelectContext

func (tx *Tx) SelectContext(ctx context.Context, dest any, query string, args ...any) error

SelectContext within this transaction.

func (*Tx) Stmtx

func (tx *Tx) Stmtx(stmt any) *Stmt

Stmtx returns a version of the prepared statement which runs within a transaction.

func (*Tx) StmtxContext

func (tx *Tx) StmtxContext(ctx context.Context, stmt any) *Stmt

StmtxContext returns a version of the prepared statement which runs within a transaction.

Directories

Path Synopsis
internal
mockdb
Package mockdb provides a mock database/sql driver for benchmarking purposes.
Package mockdb provides a mock database/sql driver for benchmarking purposes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL