Documentation
¶
Index ¶
- Variables
- func ApplySQLConfig(db *sql.DB, sqlCfg *config.SQLConfig) error
- func IsolationToSQL(level config.TxIsolationLevel) sql.IsolationLevel
- func NewRows(sqlRows *sql.Rows) driver.Rows
- func PoolSnapshot(db *sql.DB, scope string) driver.PoolSnapshot
- func ProcessArgs(dialect queries.Dialect, sqlStr string, args map[string]any) (newSQL string, argsArr []any, err error)
- func ProcessArgsInto(dialect queries.Dialect, sqlStr string, args map[string]any, destination []any) (newSQL string, argsArr []any, err error)
- func ReferencedArgs(sqlStr string, args map[string]any) map[string]any
- func RunBulkInsert[T any](ctx context.Context, db ExecContext[T], table string, src source.RowSource, ...) error
- func RunQuery[R any](ctx context.Context, db QueryContext[R], wrapRows func(R) driver.Rows, ...) (*driver.QueryResult, error)
- func StatementTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- func Teardown(_ context.Context, db io.Closer) error
- func WaitForDB(ctx context.Context, lg *zap.Logger, pingable interface{ ... }, ...) error
- type ConnOnlyTx
- type DBPinger
- type ExecContext
- type PreparedQuery
- type QueryContext
- type Rows
- type SQLTxAdapter
- type Session
- func (s *Session[R]) Begin(ctx context.Context, isolation config.TxIsolationLevel) (driver.SessionTx, error)
- func (s *Session[R]) Close(ctx context.Context) error
- func (s *Session[R]) Prepare(ctx context.Context, _, sql string) (driver.Prepared, error)
- func (s *Session[R]) RunQuery(ctx context.Context, sql string, args map[string]any) (*driver.QueryResult, error)
- type SessionConnection
- type Tx
- type TxConn
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissedArgument = errors.New("missed arguments present") ErrExtraArgument = errors.New("extra arguments provided") )
var ErrDBConnectionTimeout = errors.New("database connection timeout")
ErrDBConnectionTimeout is returned when database connection times out.
var ErrEmptyColumnOrder = errors.New("sqldriver: source reports zero columns")
ErrEmptyColumnOrder is returned when the source reports zero columns; an INSERT without columns is not a valid target for the bulk path.
var ErrUnsupportedInsertMethod = errors.New("sqldriver: unsupported insert method")
ErrUnsupportedInsertMethod is returned when the shared SQL helper receives a driver-specific method (currently NATIVE). Drivers handle that method before delegating here.
Functions ¶
func ApplySQLConfig ¶
ApplySQLConfig applies SQL pool configuration to a *sql.DB. Returns an error if any duration string is malformed.
func IsolationToSQL ¶
func IsolationToSQL(level config.TxIsolationLevel) sql.IsolationLevel
IsolationToSQL maps the isolated level to database/sql isolation level.
func PoolSnapshot ¶ added in v6.4.0
func PoolSnapshot(db *sql.DB, scope string) driver.PoolSnapshot
func ProcessArgs ¶
func ProcessArgs( dialect queries.Dialect, sqlStr string, args map[string]any, ) (newSQL string, argsArr []any, err error)
ProcessArgs takes sql which contains ":arg" marks and args map "arg" -> value. It returns sql where all marks are replaced with dialect-specific placeholders, and an array of any containing the arguments in the right order. When dialect.Deduplicate() is true, repeated named parameters share a single positional placeholder (e.g. pgx's $1 back-references).
The regex + string-building parse phase is cached per (dialect, sqlStr) pair so that repeated calls with the same template pay only a map lookup.
func ProcessArgsInto ¶ added in v6.4.0
func ProcessArgsInto( dialect queries.Dialect, sqlStr string, args map[string]any, destination []any, ) (newSQL string, argsArr []any, err error)
ProcessArgsInto reuses caller-owned storage. The caller must not refill it until the previous query has finished consuming all arguments and rows.
func ReferencedArgs ¶ added in v6.4.0
ReferencedArgs uses the same parameter-token rules as ProcessArgs so callers can adapt shared parameter sets without hiding missing bindings.
func RunBulkInsert ¶
func RunQuery ¶
func RunQuery[R any]( ctx context.Context, db QueryContext[R], wrapRows func(R) driver.Rows, dialect queries.Dialect, lg *zap.Logger, sqlStr string, args map[string]any, timeout time.Duration, ) (*driver.QueryResult, error)
RunQuery executes sql with named :arg placeholders and returns rows cursor. timeout > 0 bounds the single statement: every call derives a child context so the deadline applies per statement rather than to an entire query suite, and a dialect-provided server-side hint (MySQL MAX_EXECUTION_TIME) bounds the backend where client-side cancellation alone would not keep the pooled connection reusable.
func StatementTimeout ¶
func StatementTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
StatementTimeout returns a child context bounded by timeout, or ctx unchanged (with a no-op cancel) when timeout is non-positive. Callers release the child once the statement and any result-row iteration complete.
Types ¶
type ConnOnlyTx ¶
type ConnOnlyTx[R any] struct { // contains filtered or unexported fields }
ConnOnlyTx wraps a bare connection (no SQL transaction) as a driver.Tx. Commit and Rollback both call close to release the connection.
func NewConnOnlyTx ¶
func (*ConnOnlyTx[R]) Isolation ¶
func (t *ConnOnlyTx[R]) Isolation() config.TxIsolationLevel
type ExecContext ¶
type ExecContext[T any] interface { ExecContext(ctx context.Context, query string, args ...any) (T, error) }
ExecContext is accepted by InsertPlainQuery and InsertPlainBulk.
type PreparedQuery ¶ added in v6.3.0
type QueryContext ¶
type QueryContext[R any] interface { QueryContext(ctx context.Context, query string, args ...any) (R, error) }
QueryContext is accepted by RunQuery.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
type SQLTxAdapter ¶
SQLTxAdapter adapts *sql.Tx to TxConn[*sql.Rows]. *sql.Tx already satisfies QueryContext[*sql.Rows]; this adapter adds context-aware Commit/Rollback wrappers (sql.Tx has no-context variants).
type Session ¶ added in v6.3.0
type Session[R any] struct { // contains filtered or unexported fields }