Documentation
¶
Overview ¶
Package sqlx provides extra features for go's standard database/sql library.
Index ¶
- Constants
- Variables
- func Named(name string, value any) sql.NamedArg
- func Query[T any](db *DB, cmd string, args ...any) iter.Seq2[T, error]
- func QueryContext[T any](ctx context.Context, db *DB, cmd string, args ...any) iter.Seq2[T, error]
- func QuerySingle[T any](db *DB, cmd string, args ...any) (T, error)
- func QuerySingleContext[T any](ctx context.Context, db *DB, cmd string, args ...any) (T, error)
- type DB
- func (db *DB) Begin(options *TxOptions) (*Tx, error)
- func (db *DB) BeginContext(ctx context.Context, options *TxOptions) (*Tx, error)
- func (db *DB) Close() error
- func (db *DB) Exec(cmd string, args ...any) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, cmd string, args ...any) (sql.Result, error)
- func (db *DB) GetRow(cmd string, args ...any) *sql.Row
- func (db *DB) GetRowContext(ctx context.Context, cmd string, args ...any) *sql.Row
- func (db *DB) Prepare(cmd string) (*Stmt, error)
- func (db *DB) PrepareContext(ctx context.Context, cmd string) (*Stmt, error)
- func (db *DB) Query(cmd string, result any, args ...any) error
- func (db *DB) QueryContext(ctx context.Context, cmd string, result any, args ...any) error
- func (db *DB) QueryRows(cmd string, args ...any) (*sql.Rows, error)
- func (db *DB) QueryRowsContext(ctx context.Context, cmd string, args ...any) (*sql.Rows, error)
- func (db *DB) QuerySingle(cmd string, result any, args ...any) error
- func (db *DB) QuerySingleContext(ctx context.Context, cmd string, result any, args ...any) error
- func (db *DB) Raw() *sql.DB
- type IsolationLevel
- type Stmt
- func (s *Stmt) Close() error
- func (s *Stmt) Exec(args ...any) (sql.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args ...any) (sql.Result, error)
- func (s *Stmt) GetRow(args ...any) *sql.Row
- func (s *Stmt) GetRowContext(ctx context.Context, args ...any) *sql.Row
- func (s *Stmt) Query(result any, args ...any) error
- func (s *Stmt) QueryContext(ctx context.Context, result any, args ...any) error
- func (s *Stmt) QueryRows(args ...any) (*sql.Rows, error)
- func (s *Stmt) QueryRowsContext(ctx context.Context, args ...any) (*sql.Rows, error)
- func (s *Stmt) QuerySingle(result any, args ...any) error
- func (s *Stmt) QuerySingleContext(ctx context.Context, result any, args ...any) error
- func (s *Stmt) Raw() *sql.Stmt
- type Tx
- func (tx *Tx) Commit() error
- func (tx *Tx) Exec(cmd string, args ...any) (sql.Result, error)
- func (tx *Tx) ExecContext(ctx context.Context, cmd string, args ...any) (sql.Result, error)
- func (tx *Tx) GetRow(cmd string, args ...any) *sql.Row
- func (tx *Tx) GetRowContext(ctx context.Context, cmd string, args ...any) *sql.Row
- func (tx *Tx) Prepare(cmd string) (*Stmt, error)
- func (tx *Tx) PrepareContext(ctx context.Context, cmd string) (*Stmt, error)
- func (tx *Tx) Query(cmd string, result any, args ...any) error
- func (tx *Tx) QueryContext(ctx context.Context, cmd string, result any, args ...any) error
- func (tx *Tx) QueryRows(cmd string, args ...any) (*sql.Rows, error)
- func (tx *Tx) QueryRowsContext(ctx context.Context, cmd string, args ...any) (*sql.Rows, error)
- func (tx *Tx) QuerySingle(cmd string, result any, args ...any) error
- func (tx *Tx) QuerySingleContext(ctx context.Context, cmd string, result any, args ...any) error
- func (tx *Tx) Raw() *sql.Tx
- func (tx *Tx) Rollback() error
- func (tx *Tx) Stmt(stmt *Stmt) *Stmt
- func (tx *Tx) StmtContext(ctx context.Context, stmt *Stmt) *Stmt
- type TxOptions
Constants ¶
const ( LevelDefault = sql.LevelDefault LevelReadUncommitted = sql.LevelReadUncommitted LevelReadCommitted = sql.LevelReadCommitted LevelWriteCommitted = sql.LevelWriteCommitted LevelRepeatableRead = sql.LevelRepeatableRead LevelSnapshot = sql.LevelSnapshot LevelSerializable = sql.LevelSerializable LevelLinearizable = sql.LevelLinearizable )
Isolation levels.
Variables ¶
var ( ErrNotFound = errors.New("sqlx: result is not found") ErrNotSingle = errors.New("sqlx: result is not single") )
Errors.
Functions ¶
func QueryContext ¶
QueryContext executes a query that returns a sequence.
func QuerySingle ¶ added in v0.5.0
QuerySingle executes a query that returns a single value.
Types ¶
type DB ¶
DB is a database handle representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines.
func Open ¶
Open opens a database specified by its database driver name and a driver-specific data source name.
func (*DB) Begin ¶
Begin starts a transaction. The default isolation level is dependent on the driver.
func (*DB) BeginContext ¶ added in v0.6.0
Begin starts a transaction. The default isolation level is dependent on the driver.
func (*DB) ExecContext ¶ added in v0.6.0
ExecContext executes a query without returning any rows.
func (*DB) GetRowContext ¶ added in v0.6.0
GetRowContext executes a query that returns a single row.
func (*DB) Prepare ¶ added in v0.6.0
Prepare creates a prepared statement for later queries or executions.
func (*DB) PrepareContext ¶ added in v0.6.0
PrepareContext creates a prepared statement for later queries or executions.
func (*DB) QueryContext ¶ added in v0.6.0
QueryContext executes a query and fills the slice result.
func (*DB) QueryRowsContext ¶ added in v0.6.0
QueryRowsContext executes a query that returns rows.
func (*DB) QuerySingle ¶ added in v0.7.0
QuerySingle executes a query and fills the non-slice result.
func (*DB) QuerySingleContext ¶ added in v0.7.0
QuerySingleContext executes a query and fills the non-slice result.
type IsolationLevel ¶
type IsolationLevel = sql.IsolationLevel
IsolationLevel is the transaction isolation level.
type Stmt ¶
Stmt is a prepared statement.
func (*Stmt) ExecContext ¶
ExecContext executes a query without returning any rows.
func (*Stmt) GetRowContext ¶ added in v0.6.0
GetRowContext executes a query that returns a single row.
func (*Stmt) QueryContext ¶
QueryContext executes a query and fills the slice result.
func (*Stmt) QueryRowsContext ¶
QueryRowsContext executes a query that returns rows.
func (*Stmt) QuerySingle ¶ added in v0.5.0
QuerySingle executes a query and fills the non-slice result.
func (*Stmt) QuerySingleContext ¶ added in v0.7.0
QuerySingleContext executes a query and fills the non-slice result.
type Tx ¶
Tx is an in-progress database transaction.
func (*Tx) ExecContext ¶ added in v0.6.0
ExecContext executes a query without returning any rows.
func (*Tx) GetRowContext ¶ added in v0.6.0
GetRowContext executes a query that returns a single row.
func (*Tx) Prepare ¶ added in v0.6.0
Prepare creates a prepared statement for later queries or executions.
func (*Tx) PrepareContext ¶ added in v0.6.0
PrepareContext creates a prepared statement for later queries or executions.
func (*Tx) QueryContext ¶ added in v0.6.0
QueryContext executes a query and fills the slice result.
func (*Tx) QueryRowsContext ¶ added in v0.6.0
QueryRowsContext executes a query that returns rows.
func (*Tx) QuerySingle ¶ added in v0.7.0
QuerySingle executes a query and fills the non-slice result.
func (*Tx) QuerySingleContext ¶ added in v0.7.0
QuerySingleContext executes a query and fills the non-slice result.
type TxOptions ¶ added in v0.6.0
type TxOptions struct {
// contains filtered or unexported fields
}
TxOptions holds the transaction options.
func NewTxOptions ¶ added in v0.6.0
func NewTxOptions() *TxOptions
NewTxOptions creates the default options.
func (*TxOptions) Isolation ¶ added in v0.6.0
func (options *TxOptions) Isolation(level IsolationLevel) *TxOptions
Isolation is the transaction isolation level.