Documentation
¶
Overview ¶
Package sqldb provides a lightweight database/sql helper with simple query building and struct scanning.
Index ¶
- func FormatSQL(query string, args []any) string
- func Scan(queryer Queryer, dest any, query string, args ...any) error
- func ScanContext(ctx context.Context, queryer Queryer, dest any, query string, args ...any) error
- type DB
- func (db *DB) Begin() (*Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (b DB) Clone() *builder
- func (b DB) Count() (int, error)
- 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 (b DB) GroupBy(expr string) *builder
- func (b DB) Insert(data any) (sql.Result, error)
- func (b DB) Limit(limit int64) *builder
- func (b DB) Offset(offset int64) *builder
- func (b DB) OrderBy(column, direction string) *builder
- func (db *DB) Prepare(query string) (*sql.Stmt, error)
- func (db *DB) PrepareContext(ctx context.Context, query string) (*sql.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) QueryScan(dest any, query string, args ...any) error
- func (db *DB) QueryScanContext(ctx context.Context, dest any, query string, args ...any) error
- func (b DB) Reset()
- func (b DB) Scan(dest any) error
- func (b DB) Select(columns ...string) *builder
- func (db *DB) Table(table string) *builder
- func (db *DB) Transaction(txFunc func(*Tx) error) (err error)
- func (b DB) Update(data any) (sql.Result, error)
- func (b DB) Where(column, operator string, value any) *builder
- type DatabaseProvider
- type Execer
- type ExecerAndQueryer
- type Flavor
- type Option
- type Queryer
- type TokenType
- type Tx
- 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) Prepare(query string) (*sql.Stmt, error)
- func (tx *Tx) PrepareContext(ctx context.Context, query string) (*sql.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) QueryScan(dest any, query string, args ...any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DB ¶
func (*DB) ExecContext ¶
func (*DB) PrepareContext ¶
func (*DB) QueryContext ¶
func (*DB) QueryRowContext ¶
func (*DB) QueryScanContext ¶
type DatabaseProvider ¶
type ExecerAndQueryer ¶
type Flavor ¶
type Flavor int
Flavor is the flag to control the format of compiled sql.
const ( MySQL Flavor PostgreSQL SQLite )
Supported drivers.
type TokenType ¶
type TokenType int
TokenType represents a type of token in a SQL INSERT statement, whether column or value expression.
const ( // ColumnNameTokenType uses the column name from the struct tag specified by UseStructTag. // INSERT INTO tbl (foo, bar, ... baz) ColumnNameTokenType TokenType = 0 // QuestionMarkTokenType uses question marks as value-tokens. // VALUES (?, ?, ... ?) -- MySQL, SingleStore QuestionMarkTokenType TokenType = 1 // AtColumnNameTokenType uses @ followed by the column name from the struct tag specified by UseStructTag. // VALUES (@foo, @bar, ... @baz) -- MySQL, SingleStore AtColumnNameTokenType TokenType = 2 // OrdinalNumberTokenType uses % plus the value of an ordered sequence of integers starting at 1. // %1, %2, ... %n -- Postgres OrdinalNumberTokenType TokenType = 3 // ColonTokenType uses : followed by the column name from the struct tag specified by UseStructTag. // :foo, :bar, ... :baz -- Oracle ColonTokenType TokenType = 4 )
type Tx ¶
func (*Tx) ExecContext ¶
func (*Tx) PrepareContext ¶
func (*Tx) QueryContext ¶
func (*Tx) QueryRowContext ¶
Click to show internal directories.
Click to hide internal directories.