Documentation ¶
Index ¶
- Variables
- func AND(clauses ...SQLClause) *whereClause
- func Alias(clause interface{}, alias string) *aliasClause
- func Case(what ...interface{}) *caseClause
- func Exec(ctx context.Context, session Session, query string, args ...interface{}) (result sql.Result, err error)
- func OR(clauses ...SQLClause) *whereClause
- func OnConflictKeyUpdate(columns ...string) *onConflictDoUpdateClause
- func OnDuplicateKeyUpdate() *onDuplicateKeyUpdateClause
- func Open(driver, url string, maxOpen, maxIdle int) (db *sql.DB, err error)
- func Query[T any](ctx context.Context, session Session, query string, args ...interface{}) (dst T, err error)
- func Scan[T any](rows *sql.Rows) (dst T, err error)
- func UsePlaceholder(d Placeholder)
- type Buffer
- type Builder
- type Clause
- type Clauses
- type DB
- func (db *DB) Begin() (*Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *DB) Close() error
- func (db *DB) DB() *sql.DB
- func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, 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) PrepareStatement(ctx context.Context, key, query string) error
- func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*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) Statement(ctx context.Context, query string) (*sql.Stmt, error)
- type Database
- type DeleteBuilder
- func (db *DeleteBuilder) Alias(alias ...string) *DeleteBuilder
- func (db *DeleteBuilder) Exec(s Session) (sql.Result, error)
- func (db *DeleteBuilder) ExecContext(ctx context.Context, s Session) (result sql.Result, err error)
- func (b *DeleteBuilder) GetPlaceholder() Placeholder
- func (db *DeleteBuilder) Join(join, table, suffix string, args ...interface{}) *DeleteBuilder
- func (db *DeleteBuilder) LeftJoin(table, suffix string, args ...interface{}) *DeleteBuilder
- func (db *DeleteBuilder) Limit(limit int64) *DeleteBuilder
- func (db *DeleteBuilder) Offset(offset int64) *DeleteBuilder
- func (db *DeleteBuilder) Options(options ...string) *DeleteBuilder
- func (db *DeleteBuilder) OrderBy(clause ...string) *DeleteBuilder
- func (db *DeleteBuilder) Prefix(clause string, args ...interface{}) *DeleteBuilder
- func (db *DeleteBuilder) RightJoin(table, suffix string, args ...interface{}) *DeleteBuilder
- func (db *DeleteBuilder) SQL() (string, []interface{}, error)
- func (db *DeleteBuilder) Suffix(clause interface{}, args ...interface{}) *DeleteBuilder
- func (db *DeleteBuilder) Table(table string, args ...string) *DeleteBuilder
- func (db *DeleteBuilder) Type() string
- func (db *DeleteBuilder) USING(clause string) *DeleteBuilder
- func (db *DeleteBuilder) UsePlaceholder(p Placeholder) *DeleteBuilder
- func (db *DeleteBuilder) Where(clause interface{}, args ...interface{}) *DeleteBuilder
- func (db *DeleteBuilder) Write(w Writer) (err error)
- type Eq
- type ExceptBuilder
- func (eb *ExceptBuilder) Except(clauses ...SQLClause) *ExceptBuilder
- func (eb *ExceptBuilder) ExceptAll(clauses ...SQLClause) *ExceptBuilder
- func (b *ExceptBuilder) GetPlaceholder() Placeholder
- func (eb *ExceptBuilder) Limit(limit int64) *ExceptBuilder
- func (eb *ExceptBuilder) Offset(offset int64) *ExceptBuilder
- func (eb *ExceptBuilder) OrderBy(clause ...string) *ExceptBuilder
- func (eb *ExceptBuilder) SQL() (string, []interface{}, error)
- func (eb *ExceptBuilder) Type() string
- func (eb *ExceptBuilder) UsePlaceholder(p Placeholder) *ExceptBuilder
- func (eb *ExceptBuilder) Write(w Writer) (err error)
- type InsertBuilder
- func (ib *InsertBuilder) Column(column string) *InsertBuilder
- func (ib *InsertBuilder) Columns(columns ...string) *InsertBuilder
- func (ib *InsertBuilder) Exec(s Session) (sql.Result, error)
- func (ib *InsertBuilder) ExecContext(ctx context.Context, s Session) (result sql.Result, err error)
- func (b *InsertBuilder) GetPlaceholder() Placeholder
- func (ib *InsertBuilder) Options(options ...string) *InsertBuilder
- func (ib *InsertBuilder) Prefix(clause string, args ...interface{}) *InsertBuilder
- func (ib *InsertBuilder) Returning(columns ...string) *InsertBuilder
- func (ib *InsertBuilder) SET(column string, value interface{}) *InsertBuilder
- func (ib *InsertBuilder) SQL() (string, []interface{}, error)
- func (ib *InsertBuilder) Scan(s Session, dst interface{}) (err error)
- func (ib *InsertBuilder) ScanContext(ctx context.Context, s Session, dst interface{}) (err error)
- func (ib *InsertBuilder) ScanRow(s Session, dst ...interface{}) (err error)
- func (ib *InsertBuilder) ScanRowContext(ctx context.Context, s Session, dst ...interface{}) (err error)
- func (ib *InsertBuilder) Select(sb *SelectBuilder) *InsertBuilder
- func (ib *InsertBuilder) Suffix(clause interface{}, args ...interface{}) *InsertBuilder
- func (ib *InsertBuilder) Table(table string) *InsertBuilder
- func (ib *InsertBuilder) Type() string
- func (ib *InsertBuilder) UsePlaceholder(p Placeholder) *InsertBuilder
- func (ib *InsertBuilder) Values(values ...interface{}) *InsertBuilder
- func (ib *InsertBuilder) Write(w Writer) (err error)
- type IntersectBuilder
- func (b *IntersectBuilder) GetPlaceholder() Placeholder
- func (ib *IntersectBuilder) Intersect(clauses ...SQLClause) *IntersectBuilder
- func (ib *IntersectBuilder) IntersectAll(clauses ...SQLClause) *IntersectBuilder
- func (ib *IntersectBuilder) Limit(limit int64) *IntersectBuilder
- func (ib *IntersectBuilder) Offset(offset int64) *IntersectBuilder
- func (ib *IntersectBuilder) OrderBy(clause ...string) *IntersectBuilder
- func (ib *IntersectBuilder) SQL() (string, []interface{}, error)
- func (ib *IntersectBuilder) Type() string
- func (ib *IntersectBuilder) UsePlaceholder(p Placeholder) *IntersectBuilder
- func (ib *IntersectBuilder) Write(w Writer) (err error)
- type Mapper
- type NotEq
- type Placeholder
- type Preparer
- type RawBuilder
- func (rb *RawBuilder) Append(clause string, args ...interface{}) *RawBuilder
- func (rb *RawBuilder) Exec(s Session) (sql.Result, error)
- func (rb *RawBuilder) ExecContext(ctx context.Context, s Session) (result sql.Result, err error)
- func (rb *RawBuilder) Format(format string, args ...interface{}) *RawBuilder
- func (b *RawBuilder) GetPlaceholder() Placeholder
- func (rb *RawBuilder) Params(args ...interface{}) *RawBuilder
- func (rb *RawBuilder) Query(s Session) (*sql.Rows, error)
- func (rb *RawBuilder) QueryContext(ctx context.Context, s Session) (*sql.Rows, error)
- func (rb *RawBuilder) SQL() (string, []interface{}, error)
- func (rb *RawBuilder) Scan(s Session, dst interface{}) (err error)
- func (rb *RawBuilder) ScanContext(ctx context.Context, s Session, dst interface{}) (err error)
- func (rb *RawBuilder) ScanRow(s Session, dst ...interface{}) (err error)
- func (rb *RawBuilder) ScanRowContext(ctx context.Context, s Session, dst ...interface{}) (err error)
- func (rb *RawBuilder) Type() string
- func (rb *RawBuilder) UsePlaceholder(p Placeholder) *RawBuilder
- func (rb *RawBuilder) Write(w Writer) error
- type SQLClause
- type SQLValue
- type SelectBuilder
- func (sb *SelectBuilder) Count(alias string) *SelectBuilder
- func (sb *SelectBuilder) From(table string, args ...string) *SelectBuilder
- func (sb *SelectBuilder) FromClause(clause SQLClause) *SelectBuilder
- func (b *SelectBuilder) GetPlaceholder() Placeholder
- func (sb *SelectBuilder) GroupBy(groupBys ...string) *SelectBuilder
- func (sb *SelectBuilder) Having(clause interface{}, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) Join(join, table, suffix string, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) LeftJoin(table, suffix string, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) Limit(limit int64) *SelectBuilder
- func (sb *SelectBuilder) Offset(offset int64) *SelectBuilder
- func (sb *SelectBuilder) Options(options ...string) *SelectBuilder
- func (sb *SelectBuilder) OrderBy(clause ...string) *SelectBuilder
- func (sb *SelectBuilder) Prefix(clause string, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) Query(s Session) (*sql.Rows, error)
- func (sb *SelectBuilder) QueryContext(ctx context.Context, s Session) (*sql.Rows, error)
- func (sb *SelectBuilder) RightJoin(table, suffix string, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) SQL() (string, []interface{}, error)
- func (sb *SelectBuilder) Scan(s Session, dst interface{}) (err error)
- func (sb *SelectBuilder) ScanContext(ctx context.Context, s Session, dst interface{}) (err error)
- func (sb *SelectBuilder) ScanRow(s Session, dst ...interface{}) (err error)
- func (sb *SelectBuilder) ScanRowContext(ctx context.Context, s Session, dst ...interface{}) (err error)
- func (sb *SelectBuilder) Select(column interface{}, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) Selects(columns ...string) *SelectBuilder
- func (sb *SelectBuilder) Suffix(clause interface{}, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) Type() string
- func (sb *SelectBuilder) UsePlaceholder(p Placeholder) *SelectBuilder
- func (sb *SelectBuilder) Where(clause interface{}, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) Write(w Writer) (err error)
- type Session
- type Transaction
- type Tx
- func (tx *Tx) Commit() error
- func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (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 ...interface{}) (*sql.Rows, error)
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*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) Rollback() error
- func (tx *Tx) Statement(ctx context.Context, query string) (*sql.Stmt, error)
- func (tx *Tx) Tx() *sql.Tx
- type UnionBuilder
- func (b *UnionBuilder) GetPlaceholder() Placeholder
- func (ub *UnionBuilder) Limit(limit int64) *UnionBuilder
- func (ub *UnionBuilder) Offset(offset int64) *UnionBuilder
- func (ub *UnionBuilder) OrderBy(clause ...string) *UnionBuilder
- func (ub *UnionBuilder) SQL() (string, []interface{}, error)
- func (ub *UnionBuilder) Type() string
- func (ub *UnionBuilder) Union(clauses ...SQLClause) *UnionBuilder
- func (ub *UnionBuilder) UnionAll(clauses ...SQLClause) *UnionBuilder
- func (ub *UnionBuilder) UsePlaceholder(p Placeholder) *UnionBuilder
- func (ub *UnionBuilder) Write(w Writer) (err error)
- type UpdateBuilder
- func (ub *UpdateBuilder) Exec(s Session) (sql.Result, error)
- func (ub *UpdateBuilder) ExecContext(ctx context.Context, s Session) (result sql.Result, err error)
- func (b *UpdateBuilder) GetPlaceholder() Placeholder
- func (ub *UpdateBuilder) Join(join, table, suffix string, args ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) LeftJoin(table, suffix string, args ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) Limit(limit int64) *UpdateBuilder
- func (ub *UpdateBuilder) Offset(offset int64) *UpdateBuilder
- func (ub *UpdateBuilder) Options(options ...string) *UpdateBuilder
- func (ub *UpdateBuilder) OrderBy(clause ...string) *UpdateBuilder
- func (ub *UpdateBuilder) Prefix(clause string, args ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) RightJoin(table, suffix string, args ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) SET(column string, value interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) SETS(kvs ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) SQL() (string, []interface{}, error)
- func (ub *UpdateBuilder) SetMap(data map[string]interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) Suffix(clause interface{}, args ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) Table(table string, args ...string) *UpdateBuilder
- func (ub *UpdateBuilder) Type() string
- func (ub *UpdateBuilder) UsePlaceholder(p Placeholder) *UpdateBuilder
- func (ub *UpdateBuilder) Where(clause interface{}, args ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) Write(w Writer) (err error)
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( QuestionPlaceholder = &question{} DollarPlaceholder = &dollar{ pool: sync.Pool{New: func() interface{} { return &bytes.Buffer{} }}, } )
var ErrNoRows = sql.ErrNoRows
var ErrStmtExists = errors.New("statement exists")
var ErrTxDone = sql.ErrTxDone
Functions ¶
func OnConflictKeyUpdate ¶ added in v1.1.7
func OnConflictKeyUpdate(columns ...string) *onConflictDoUpdateClause
func OnDuplicateKeyUpdate ¶
func OnDuplicateKeyUpdate() *onDuplicateKeyUpdateClause
func UsePlaceholder ¶ added in v1.2.4
func UsePlaceholder(d Placeholder)
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) ExecContext ¶ added in v1.2.4
func (*DB) Prepare ¶ added in v1.2.4
Prepare 作用同 sql.DB 的 Prepare 方法。
本方法返回的 sql.Stmt 不会被缓存,不再使用之后需要调用其 Close 方法将其关闭。
func (*DB) PrepareContext ¶ added in v1.2.4
PrepareContext 作用同 sql.DB 的 PrepareContext 方法。
本方法返回的 sql.Stmt 不会被缓存,不再使用之后需要调用其 Close 方法将其关闭。
func (*DB) PrepareStatement ¶ added in v1.2.7
PrepareStatement 预先创建一个 sql.Stmt 并将其缓存,后续可以使用 key 获取该 sql.Stmt。
var db = dbs.New(...)
db.PrepareStatement(ctx, "key", "SELECT ...")
var stmt, _ = db.Statement(ctx, "key")
stmt.Query("参数1", "参数2")
或者
db.Query("key", "参数1", "参数2")
func (*DB) QueryContext ¶ added in v1.2.4
func (*DB) QueryRowContext ¶ added in v1.2.4
type DeleteBuilder ¶
type DeleteBuilder struct {
// contains filtered or unexported fields
}
func NewDeleteBuilder ¶
func NewDeleteBuilder() *DeleteBuilder
func (*DeleteBuilder) Alias ¶
func (db *DeleteBuilder) Alias(alias ...string) *DeleteBuilder
func (*DeleteBuilder) ExecContext ¶
func (*DeleteBuilder) GetPlaceholder ¶ added in v1.2.4
func (b *DeleteBuilder) GetPlaceholder() Placeholder
func (*DeleteBuilder) Join ¶
func (db *DeleteBuilder) Join(join, table, suffix string, args ...interface{}) *DeleteBuilder
func (*DeleteBuilder) LeftJoin ¶
func (db *DeleteBuilder) LeftJoin(table, suffix string, args ...interface{}) *DeleteBuilder
func (*DeleteBuilder) Limit ¶
func (db *DeleteBuilder) Limit(limit int64) *DeleteBuilder
func (*DeleteBuilder) Offset ¶
func (db *DeleteBuilder) Offset(offset int64) *DeleteBuilder
func (*DeleteBuilder) Options ¶
func (db *DeleteBuilder) Options(options ...string) *DeleteBuilder
func (*DeleteBuilder) OrderBy ¶
func (db *DeleteBuilder) OrderBy(clause ...string) *DeleteBuilder
func (*DeleteBuilder) Prefix ¶
func (db *DeleteBuilder) Prefix(clause string, args ...interface{}) *DeleteBuilder
func (*DeleteBuilder) RightJoin ¶
func (db *DeleteBuilder) RightJoin(table, suffix string, args ...interface{}) *DeleteBuilder
func (*DeleteBuilder) SQL ¶ added in v1.2.1
func (db *DeleteBuilder) SQL() (string, []interface{}, error)
func (*DeleteBuilder) Suffix ¶
func (db *DeleteBuilder) Suffix(clause interface{}, args ...interface{}) *DeleteBuilder
func (*DeleteBuilder) Table ¶
func (db *DeleteBuilder) Table(table string, args ...string) *DeleteBuilder
func (*DeleteBuilder) Type ¶
func (db *DeleteBuilder) Type() string
func (*DeleteBuilder) USING ¶
func (db *DeleteBuilder) USING(clause string) *DeleteBuilder
func (*DeleteBuilder) UsePlaceholder ¶ added in v1.2.4
func (db *DeleteBuilder) UsePlaceholder(p Placeholder) *DeleteBuilder
func (*DeleteBuilder) Where ¶
func (db *DeleteBuilder) Where(clause interface{}, args ...interface{}) *DeleteBuilder
func (*DeleteBuilder) Write ¶ added in v1.2.1
func (db *DeleteBuilder) Write(w Writer) (err error)
type ExceptBuilder ¶ added in v1.2.6
type ExceptBuilder struct {
// contains filtered or unexported fields
}
func NewExceptBuilder ¶ added in v1.2.6
func NewExceptBuilder() *ExceptBuilder
func (*ExceptBuilder) Except ¶ added in v1.2.6
func (eb *ExceptBuilder) Except(clauses ...SQLClause) *ExceptBuilder
func (*ExceptBuilder) ExceptAll ¶ added in v1.2.6
func (eb *ExceptBuilder) ExceptAll(clauses ...SQLClause) *ExceptBuilder
func (*ExceptBuilder) GetPlaceholder ¶ added in v1.2.6
func (b *ExceptBuilder) GetPlaceholder() Placeholder
func (*ExceptBuilder) Limit ¶ added in v1.2.6
func (eb *ExceptBuilder) Limit(limit int64) *ExceptBuilder
func (*ExceptBuilder) Offset ¶ added in v1.2.6
func (eb *ExceptBuilder) Offset(offset int64) *ExceptBuilder
func (*ExceptBuilder) OrderBy ¶ added in v1.2.6
func (eb *ExceptBuilder) OrderBy(clause ...string) *ExceptBuilder
func (*ExceptBuilder) SQL ¶ added in v1.2.6
func (eb *ExceptBuilder) SQL() (string, []interface{}, error)
func (*ExceptBuilder) Type ¶ added in v1.2.6
func (eb *ExceptBuilder) Type() string
func (*ExceptBuilder) UsePlaceholder ¶ added in v1.2.6
func (eb *ExceptBuilder) UsePlaceholder(p Placeholder) *ExceptBuilder
func (*ExceptBuilder) Write ¶ added in v1.2.6
func (eb *ExceptBuilder) Write(w Writer) (err error)
type InsertBuilder ¶
type InsertBuilder struct {
// contains filtered or unexported fields
}
func Insert ¶
func Insert(columns ...string) *InsertBuilder
func NewInsertBuilder ¶
func NewInsertBuilder() *InsertBuilder
func (*InsertBuilder) Column ¶
func (ib *InsertBuilder) Column(column string) *InsertBuilder
func (*InsertBuilder) Columns ¶
func (ib *InsertBuilder) Columns(columns ...string) *InsertBuilder
func (*InsertBuilder) ExecContext ¶
func (*InsertBuilder) GetPlaceholder ¶ added in v1.2.4
func (b *InsertBuilder) GetPlaceholder() Placeholder
func (*InsertBuilder) Options ¶
func (ib *InsertBuilder) Options(options ...string) *InsertBuilder
func (*InsertBuilder) Prefix ¶
func (ib *InsertBuilder) Prefix(clause string, args ...interface{}) *InsertBuilder
func (*InsertBuilder) Returning ¶ added in v1.2.7
func (ib *InsertBuilder) Returning(columns ...string) *InsertBuilder
func (*InsertBuilder) SET ¶
func (ib *InsertBuilder) SET(column string, value interface{}) *InsertBuilder
func (*InsertBuilder) SQL ¶ added in v1.2.1
func (ib *InsertBuilder) SQL() (string, []interface{}, error)
func (*InsertBuilder) Scan ¶ added in v1.2.7
func (ib *InsertBuilder) Scan(s Session, dst interface{}) (err error)
func (*InsertBuilder) ScanContext ¶ added in v1.2.7
func (ib *InsertBuilder) ScanContext(ctx context.Context, s Session, dst interface{}) (err error)
func (*InsertBuilder) ScanRow ¶ added in v1.2.7
func (ib *InsertBuilder) ScanRow(s Session, dst ...interface{}) (err error)
func (*InsertBuilder) ScanRowContext ¶ added in v1.2.7
func (ib *InsertBuilder) ScanRowContext(ctx context.Context, s Session, dst ...interface{}) (err error)
func (*InsertBuilder) Select ¶
func (ib *InsertBuilder) Select(sb *SelectBuilder) *InsertBuilder
func (*InsertBuilder) Suffix ¶
func (ib *InsertBuilder) Suffix(clause interface{}, args ...interface{}) *InsertBuilder
func (*InsertBuilder) Table ¶
func (ib *InsertBuilder) Table(table string) *InsertBuilder
func (*InsertBuilder) Type ¶
func (ib *InsertBuilder) Type() string
func (*InsertBuilder) UsePlaceholder ¶ added in v1.2.4
func (ib *InsertBuilder) UsePlaceholder(p Placeholder) *InsertBuilder
func (*InsertBuilder) Values ¶
func (ib *InsertBuilder) Values(values ...interface{}) *InsertBuilder
func (*InsertBuilder) Write ¶ added in v1.2.1
func (ib *InsertBuilder) Write(w Writer) (err error)
type IntersectBuilder ¶ added in v1.2.6
type IntersectBuilder struct {
// contains filtered or unexported fields
}
func NewIntersectBuilder ¶ added in v1.2.6
func NewIntersectBuilder() *IntersectBuilder
func (*IntersectBuilder) GetPlaceholder ¶ added in v1.2.6
func (b *IntersectBuilder) GetPlaceholder() Placeholder
func (*IntersectBuilder) Intersect ¶ added in v1.2.6
func (ib *IntersectBuilder) Intersect(clauses ...SQLClause) *IntersectBuilder
func (*IntersectBuilder) IntersectAll ¶ added in v1.2.6
func (ib *IntersectBuilder) IntersectAll(clauses ...SQLClause) *IntersectBuilder
func (*IntersectBuilder) Limit ¶ added in v1.2.6
func (ib *IntersectBuilder) Limit(limit int64) *IntersectBuilder
func (*IntersectBuilder) Offset ¶ added in v1.2.6
func (ib *IntersectBuilder) Offset(offset int64) *IntersectBuilder
func (*IntersectBuilder) OrderBy ¶ added in v1.2.6
func (ib *IntersectBuilder) OrderBy(clause ...string) *IntersectBuilder
func (*IntersectBuilder) SQL ¶ added in v1.2.6
func (ib *IntersectBuilder) SQL() (string, []interface{}, error)
func (*IntersectBuilder) Type ¶ added in v1.2.6
func (ib *IntersectBuilder) Type() string
func (*IntersectBuilder) UsePlaceholder ¶ added in v1.2.6
func (ib *IntersectBuilder) UsePlaceholder(p Placeholder) *IntersectBuilder
func (*IntersectBuilder) Write ¶ added in v1.2.6
func (ib *IntersectBuilder) Write(w Writer) (err error)
type Placeholder ¶ added in v1.2.4
func GetPlaceholder ¶ added in v1.2.4
func GetPlaceholder() Placeholder
type RawBuilder ¶
type RawBuilder struct {
// contains filtered or unexported fields
}
RawBuilder 原始 SQL 语句构造器,不会自动添加任何的关键字,主要是为了便于 SQL 语句及参数的管理。
func NewBuilder ¶
func NewBuilder(clause string, args ...interface{}) *RawBuilder
func (*RawBuilder) Append ¶
func (rb *RawBuilder) Append(clause string, args ...interface{}) *RawBuilder
func (*RawBuilder) ExecContext ¶
func (*RawBuilder) Format ¶
func (rb *RawBuilder) Format(format string, args ...interface{}) *RawBuilder
func (*RawBuilder) GetPlaceholder ¶ added in v1.2.4
func (b *RawBuilder) GetPlaceholder() Placeholder
func (*RawBuilder) Params ¶
func (rb *RawBuilder) Params(args ...interface{}) *RawBuilder
func (*RawBuilder) QueryContext ¶
func (*RawBuilder) SQL ¶ added in v1.2.1
func (rb *RawBuilder) SQL() (string, []interface{}, error)
func (*RawBuilder) Scan ¶
func (rb *RawBuilder) Scan(s Session, dst interface{}) (err error)
func (*RawBuilder) ScanContext ¶
func (rb *RawBuilder) ScanContext(ctx context.Context, s Session, dst interface{}) (err error)
func (*RawBuilder) ScanRow ¶
func (rb *RawBuilder) ScanRow(s Session, dst ...interface{}) (err error)
func (*RawBuilder) ScanRowContext ¶
func (rb *RawBuilder) ScanRowContext(ctx context.Context, s Session, dst ...interface{}) (err error)
func (*RawBuilder) Type ¶
func (rb *RawBuilder) Type() string
func (*RawBuilder) UsePlaceholder ¶ added in v1.2.4
func (rb *RawBuilder) UsePlaceholder(p Placeholder) *RawBuilder
func (*RawBuilder) Write ¶ added in v1.2.1
func (rb *RawBuilder) Write(w Writer) error
type SelectBuilder ¶
type SelectBuilder struct {
// contains filtered or unexported fields
}
func NewSelectBuilder ¶
func NewSelectBuilder() *SelectBuilder
func Select ¶
func Select(columns ...string) *SelectBuilder
func (*SelectBuilder) Count ¶
func (sb *SelectBuilder) Count(alias string) *SelectBuilder
func (*SelectBuilder) From ¶
func (sb *SelectBuilder) From(table string, args ...string) *SelectBuilder
func (*SelectBuilder) FromClause ¶ added in v1.2.6
func (sb *SelectBuilder) FromClause(clause SQLClause) *SelectBuilder
func (*SelectBuilder) GetPlaceholder ¶ added in v1.2.4
func (b *SelectBuilder) GetPlaceholder() Placeholder
func (*SelectBuilder) GroupBy ¶
func (sb *SelectBuilder) GroupBy(groupBys ...string) *SelectBuilder
func (*SelectBuilder) Having ¶
func (sb *SelectBuilder) Having(clause interface{}, args ...interface{}) *SelectBuilder
func (*SelectBuilder) Join ¶
func (sb *SelectBuilder) Join(join, table, suffix string, args ...interface{}) *SelectBuilder
func (*SelectBuilder) LeftJoin ¶
func (sb *SelectBuilder) LeftJoin(table, suffix string, args ...interface{}) *SelectBuilder
func (*SelectBuilder) Limit ¶
func (sb *SelectBuilder) Limit(limit int64) *SelectBuilder
func (*SelectBuilder) Offset ¶
func (sb *SelectBuilder) Offset(offset int64) *SelectBuilder
func (*SelectBuilder) Options ¶
func (sb *SelectBuilder) Options(options ...string) *SelectBuilder
func (*SelectBuilder) OrderBy ¶
func (sb *SelectBuilder) OrderBy(clause ...string) *SelectBuilder
func (*SelectBuilder) Prefix ¶
func (sb *SelectBuilder) Prefix(clause string, args ...interface{}) *SelectBuilder
func (*SelectBuilder) QueryContext ¶
func (*SelectBuilder) RightJoin ¶
func (sb *SelectBuilder) RightJoin(table, suffix string, args ...interface{}) *SelectBuilder
func (*SelectBuilder) SQL ¶ added in v1.2.1
func (sb *SelectBuilder) SQL() (string, []interface{}, error)
func (*SelectBuilder) Scan ¶
func (sb *SelectBuilder) Scan(s Session, dst interface{}) (err error)
Scan 读取数据到一个结构体中。
var user *User
var sb = dbs.NewSelectBuilder()
sb.Scan(db, &user)
func (*SelectBuilder) ScanContext ¶
func (sb *SelectBuilder) ScanContext(ctx context.Context, s Session, dst interface{}) (err error)
ScanContext 读取数据到一个结构体中。
var user *User
var sb = dbs.NewSelectBuilder()
sb.ScanContext(ctx, db, &user)
func (*SelectBuilder) ScanRow ¶
func (sb *SelectBuilder) ScanRow(s Session, dst ...interface{}) (err error)
ScanRow 读取数据到基本数据类型的变量中,类似于 database/buf 包中结构体 Rows 的 Scan() 方法。
var name string
var age int
var sb = dbs.NewSelectBuilder()
sb.ScanRow(db, &name, &age)
func (*SelectBuilder) ScanRowContext ¶
func (sb *SelectBuilder) ScanRowContext(ctx context.Context, s Session, dst ...interface{}) (err error)
ScanRowContext 读取数据到基本数据类型的变量中,类似于 database/buf 包中结构体 Rows 的 Scan() 方法。
var name string
var age int
var sb = dbs.NewSelectBuilder()
sb.ScanRowContext(ctx, db, &name, &age)
func (*SelectBuilder) Select ¶
func (sb *SelectBuilder) Select(column interface{}, args ...interface{}) *SelectBuilder
func (*SelectBuilder) Selects ¶
func (sb *SelectBuilder) Selects(columns ...string) *SelectBuilder
func (*SelectBuilder) Suffix ¶
func (sb *SelectBuilder) Suffix(clause interface{}, args ...interface{}) *SelectBuilder
func (*SelectBuilder) Type ¶
func (sb *SelectBuilder) Type() string
func (*SelectBuilder) UsePlaceholder ¶ added in v1.2.4
func (sb *SelectBuilder) UsePlaceholder(p Placeholder) *SelectBuilder
func (*SelectBuilder) Where ¶
func (sb *SelectBuilder) Where(clause interface{}, args ...interface{}) *SelectBuilder
func (*SelectBuilder) Write ¶ added in v1.2.1
func (sb *SelectBuilder) Write(w Writer) (err error)
type Session ¶ added in v1.0.4
type Session interface { Prepare(query string) (*sql.Stmt, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) Exec(query string, args ...interface{}) (sql.Result, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...any) *sql.Row QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }
type Transaction ¶ added in v1.2.4
type Tx ¶ added in v1.2.4
type Tx struct {
// contains filtered or unexported fields
}
func (*Tx) ExecContext ¶ added in v1.2.4
func (*Tx) Prepare ¶ added in v1.2.4
Prepare 作用同 sql.Tx 的 Prepare 方法。
本方法返回的 sql.Stmt 不会被缓存,不再使用之后需要调用其 Close 方法将其关闭。
func (*Tx) PrepareContext ¶ added in v1.2.4
PrepareContext 作用同 sql.Tx 的 PrepareContext 方法。
本方法返回的 sql.Stmt 不会被缓存,不再使用之后需要调用其 Close 方法将其关闭。
func (*Tx) QueryContext ¶ added in v1.2.4
func (*Tx) QueryRowContext ¶ added in v1.2.4
type UnionBuilder ¶ added in v1.2.6
type UnionBuilder struct {
// contains filtered or unexported fields
}
func NewUnionBuilder ¶ added in v1.2.6
func NewUnionBuilder() *UnionBuilder
func (*UnionBuilder) GetPlaceholder ¶ added in v1.2.6
func (b *UnionBuilder) GetPlaceholder() Placeholder
func (*UnionBuilder) Limit ¶ added in v1.2.6
func (ub *UnionBuilder) Limit(limit int64) *UnionBuilder
func (*UnionBuilder) Offset ¶ added in v1.2.6
func (ub *UnionBuilder) Offset(offset int64) *UnionBuilder
func (*UnionBuilder) OrderBy ¶ added in v1.2.6
func (ub *UnionBuilder) OrderBy(clause ...string) *UnionBuilder
func (*UnionBuilder) SQL ¶ added in v1.2.6
func (ub *UnionBuilder) SQL() (string, []interface{}, error)
func (*UnionBuilder) Type ¶ added in v1.2.6
func (ub *UnionBuilder) Type() string
func (*UnionBuilder) Union ¶ added in v1.2.6
func (ub *UnionBuilder) Union(clauses ...SQLClause) *UnionBuilder
func (*UnionBuilder) UnionAll ¶ added in v1.2.6
func (ub *UnionBuilder) UnionAll(clauses ...SQLClause) *UnionBuilder
func (*UnionBuilder) UsePlaceholder ¶ added in v1.2.6
func (ub *UnionBuilder) UsePlaceholder(p Placeholder) *UnionBuilder
func (*UnionBuilder) Write ¶ added in v1.2.6
func (ub *UnionBuilder) Write(w Writer) (err error)
type UpdateBuilder ¶
type UpdateBuilder struct {
// contains filtered or unexported fields
}
func NewUpdateBuilder ¶
func NewUpdateBuilder() *UpdateBuilder
func Update ¶
func Update(table string, args ...string) *UpdateBuilder
func (*UpdateBuilder) ExecContext ¶
func (*UpdateBuilder) GetPlaceholder ¶ added in v1.2.4
func (b *UpdateBuilder) GetPlaceholder() Placeholder
func (*UpdateBuilder) Join ¶
func (ub *UpdateBuilder) Join(join, table, suffix string, args ...interface{}) *UpdateBuilder
func (*UpdateBuilder) LeftJoin ¶
func (ub *UpdateBuilder) LeftJoin(table, suffix string, args ...interface{}) *UpdateBuilder
func (*UpdateBuilder) Limit ¶
func (ub *UpdateBuilder) Limit(limit int64) *UpdateBuilder
func (*UpdateBuilder) Offset ¶
func (ub *UpdateBuilder) Offset(offset int64) *UpdateBuilder
func (*UpdateBuilder) Options ¶
func (ub *UpdateBuilder) Options(options ...string) *UpdateBuilder
func (*UpdateBuilder) OrderBy ¶
func (ub *UpdateBuilder) OrderBy(clause ...string) *UpdateBuilder
func (*UpdateBuilder) Prefix ¶
func (ub *UpdateBuilder) Prefix(clause string, args ...interface{}) *UpdateBuilder
func (*UpdateBuilder) RightJoin ¶
func (ub *UpdateBuilder) RightJoin(table, suffix string, args ...interface{}) *UpdateBuilder
func (*UpdateBuilder) SET ¶
func (ub *UpdateBuilder) SET(column string, value interface{}) *UpdateBuilder
func (*UpdateBuilder) SETS ¶
func (ub *UpdateBuilder) SETS(kvs ...interface{}) *UpdateBuilder
SETS 批量设置需要更新的字段及其值
var name = "my name"
SETS("name", name, "age", 10)
func (*UpdateBuilder) SQL ¶ added in v1.2.1
func (ub *UpdateBuilder) SQL() (string, []interface{}, error)
func (*UpdateBuilder) SetMap ¶
func (ub *UpdateBuilder) SetMap(data map[string]interface{}) *UpdateBuilder
func (*UpdateBuilder) Suffix ¶
func (ub *UpdateBuilder) Suffix(clause interface{}, args ...interface{}) *UpdateBuilder
func (*UpdateBuilder) Table ¶
func (ub *UpdateBuilder) Table(table string, args ...string) *UpdateBuilder
func (*UpdateBuilder) Type ¶
func (ub *UpdateBuilder) Type() string
func (*UpdateBuilder) UsePlaceholder ¶ added in v1.2.4
func (ub *UpdateBuilder) UsePlaceholder(p Placeholder) *UpdateBuilder
func (*UpdateBuilder) Where ¶
func (ub *UpdateBuilder) Where(clause interface{}, args ...interface{}) *UpdateBuilder
func (*UpdateBuilder) Write ¶ added in v1.2.1
func (ub *UpdateBuilder) Write(w Writer) (err error)