Documentation
¶
Index ¶
- Variables
- func BindDriver(driverName string, binder Binder)
- func EndsLike(s string, escape ...rune) string
- func EscapeLike(s string, escape ...rune) string
- func EscapeString(s string) string
- func In(col string, val any) (sql string, args []any)
- func JSONScan(value, dest any) error
- func JSONValue(value any) (driver.Value, error)
- func MustExec(e Execer, query string, args ...any) sql.Result
- func MustExecContext(ctx context.Context, e ContextExecer, query string, args ...any) sql.Result
- func MustStmtExec(e StmtExecer, args ...any) sql.Result
- func MustStmtExecContext(ctx context.Context, e ContextStmtExecer, query string, args ...any) sql.Result
- func NotIn(col string, val any) (sql string, args []any)
- func Question(n int) string
- func Questions(n int) []string
- func QuoteDriver(driverName string, quoter Quoter)
- func StartsLike(s string, escape ...rune) string
- func StringLike(s string, escape ...rune) string
- func Transaction(db Beginer, fc func(tx *sql.Tx) error) (err error)
- func Transactionx(ctx context.Context, db BeginTxer, opts *sql.TxOptions, ...) (err error)
- type BeginTxer
- type Beginer
- type Binder
- type Builder
- func (b *Builder) Btw(col string, vmin, vmax any) *Builder
- func (b *Builder) Build() (string, []any)
- func (b *Builder) Columns(cols ...string) *Builder
- func (b *Builder) Columnx(col string, args ...any) *Builder
- func (b *Builder) Count(cols ...string) *Builder
- func (b *Builder) CountDistinct(cols ...string) *Builder
- func (b *Builder) Delete(tb string) *Builder
- func (b *Builder) Distinct() *Builder
- func (b *Builder) Eq(col string, val any) *Builder
- func (b *Builder) ForUpdate(forUpdate ...bool) *Builder
- func (b *Builder) From(tb string, args ...any) *Builder
- func (b *Builder) Gt(col string, val any) *Builder
- func (b *Builder) Gte(col string, val any) *Builder
- func (b *Builder) ILike(col string, val any) *Builder
- func (b *Builder) In(col string, val any) *Builder
- func (b *Builder) Insert(tb string) *Builder
- func (b *Builder) IsNull(col string) *Builder
- func (b *Builder) Join(query string, args ...any) *Builder
- func (b *Builder) Like(col string, val any) *Builder
- func (b *Builder) Limit(limit int) *Builder
- func (b *Builder) Lt(col string, val any) *Builder
- func (b *Builder) Lte(col string, val any) *Builder
- func (b *Builder) Name(col string) *Builder
- func (b *Builder) Names(cols ...string) *Builder
- func (b *Builder) Nbtw(col string, vmin, vmax any) *Builder
- func (b *Builder) Neq(col string, val any) *Builder
- func (b *Builder) NotILike(col string, val any) *Builder
- func (b *Builder) NotIn(col string, val any) *Builder
- func (b *Builder) NotLike(col string, val any) *Builder
- func (b *Builder) NotNull(col string) *Builder
- func (b *Builder) Offset(offset int) *Builder
- func (b *Builder) Omits(cols ...string) *Builder
- func (b *Builder) Order(col string, desc ...bool) *Builder
- func (b *Builder) Orders(order string, defaults ...string) *Builder
- func (b *Builder) Params() []any
- func (b *Builder) Reset() *Builder
- func (b *Builder) Returns(cols ...string) *Builder
- func (b *Builder) SQL() string
- func (b *Builder) Select(cols ...string) *Builder
- func (b *Builder) Setc(col string, arg any) *Builder
- func (b *Builder) Setx(col string, val string, args ...any) *Builder
- func (b *Builder) Update(tb string) *Builder
- func (b *Builder) Values(vals ...string) *Builder
- func (b *Builder) Where(q string, args ...any) *Builder
- type ContextExecer
- type ContextPinger
- type ContextPreparer
- type ContextQueryer
- type ContextRowQueryer
- type ContextStmtExecer
- type ContextStmtQueryer
- type Execer
- type JSONArray
- type JSONInt64Array
- type JSONIntArray
- type JSONObject
- type JSONStringArray
- type JSONStringObject
- type Pinger
- type Preparer
- type Queryer
- type Quote
- type Quoter
- type Rebind
- type RowQueryer
- type Sql
- type SqlReader
- type Sqlc
- type StmtExecer
- type StmtQueryer
- type Txer
Constants ¶
This section is empty.
Variables ¶
var ( QuoteDefault = Quoter{'"', '"'} QuoteBackticks = Quoter{'`', '`'} QuoteBrackets = Quoter{'[', ']'} )
Functions ¶
func BindDriver ¶ added in v1.0.26
BindDriver sets the Binder for driverName to binder.
func EndsLike ¶
StartsLike build a string for like suffix '%' + s The default escape char is backslach '\\'.
func EscapeLike ¶
EscapeLike escape sql like string. The default escape char is backslach '\\'.
func EscapeString ¶
At present, this method only turns single-quotes into doubled single-quotes ( <code>"McHale's Navy"</code> => <code>"McHale”s Navy"</code>). It does not handle the cases of percent (%) or underscore (_) for use in LIKE clauses. </p> see http://www.jguru.com/faq/view.jsp?EID=8881
func MustExec ¶ added in v1.0.26
MustExec execs the query using e and panics if there was an error. Any placeholder parameters are replaced with supplied args.
func MustExecContext ¶ added in v1.0.26
MustExecContext execs the query using e and panics if there was an error. Any placeholder parameters are replaced with supplied args.
func MustStmtExec ¶ added in v1.0.26
func MustStmtExec(e StmtExecer, args ...any) sql.Result
MustStmtExec execs the statement query using e and panics if there was an error. Any placeholder parameters are replaced with supplied args.
func MustStmtExecContext ¶ added in v1.0.26
func MustStmtExecContext(ctx context.Context, e ContextStmtExecer, query string, args ...any) sql.Result
MustStmtExecContext execs the statement query using e and panics if there was an error. Any placeholder parameters are replaced with supplied args.
func QuoteDriver ¶ added in v1.0.15
QuoteDriver sets the Quoter for driverName to quoter.
func StartsLike ¶
StartsLike build a string for like prefix s + '%' The default escape char is backslach '\\'.
func StringLike ¶
StringLike build a string for like '%' + s + '%' The default escape char is backslach '\\'.
func Transaction ¶ added in v1.0.26
Transaction start a transaction as a block, return error will rollback, otherwise to commit. Transaction executes an arbitrary number of commands in fc within a transaction. On success the changes are committed; if an error occurs they are rolled back.
func Transactionx ¶ added in v1.0.26
func Transactionx(ctx context.Context, db BeginTxer, opts *sql.TxOptions, fc func(tx *sql.Tx) error) (err error)
Transactionx start a transaction as a block, return error will rollback, otherwise to commit. Transaction executes an arbitrary number of commands in fc within a transaction. On success the changes are committed; if an error occurs they are rolled back.
Types ¶
type Binder ¶ added in v1.0.26
type Binder int
func GetBinder ¶ added in v1.0.26
GetBinder returns the binder for a given database given a drivername.
func (Binder) Explain ¶ added in v1.0.26
Explain generate SQL string with given parameters, the generated SQL is expected to be used in logger, execute it might introduce a SQL injection vulnerability
func (Binder) Placeholder ¶ added in v1.0.26
Placeholder generate a place holder mark with No. n.
type Builder ¶ added in v1.0.15
Builder a simple sql builder NOTE: the arguments are strict to it's order
func (*Builder) CountDistinct ¶ added in v1.0.26
Count shortcut for SELECT COUNT(distinct *)
func (*Builder) Join ¶ added in v1.0.26
Join specify Join query and conditions
sqb.Join("JOIN emails ON emails.user_id = users.id AND emails.email = ?", "abc@example.org")
func (*Builder) Name ¶ added in v1.0.27
Name add named column and value. Example:
sqb.Insert("a").Name("id") // INSERT INTO a (id) VALUES (:id)
sqb.Update("a").Name("value").Where("id = :id") // UPDATE a SET value = :value WHERE id = :id
func (*Builder) Names ¶ added in v1.0.26
Names add named columns and values. Example:
sqb.Insert("a").Names("id", "name", "value") // INSERT INTO a (id, name) VALUES (:id, :name)
sqb.Update("a").Names("name", "value").Where("id = :id") // UPDATE a SET name = :name, value = :value WHERE id = :id
func (*Builder) Select ¶ added in v1.0.15
Select add select columns if `cols` is not specified, default select "*"
type ContextExecer ¶ added in v1.0.26
type ContextPinger ¶ added in v1.0.26
type ContextPreparer ¶ added in v1.0.26
type ContextQueryer ¶ added in v1.0.26
type ContextRowQueryer ¶ added in v1.0.26
type ContextStmtExecer ¶ added in v1.0.26
type ContextStmtQueryer ¶ added in v1.0.26
type JSONInt64Array ¶ added in v1.0.27
type JSONInt64Array []int64
func (*JSONInt64Array) Scan ¶ added in v1.0.27
func (jia *JSONInt64Array) Scan(value any) error
func (JSONInt64Array) String ¶ added in v1.2.8
func (jia JSONInt64Array) String() string
type JSONIntArray ¶ added in v1.0.27
type JSONIntArray []int
func (*JSONIntArray) Scan ¶ added in v1.0.27
func (jia *JSONIntArray) Scan(value any) error
func (JSONIntArray) String ¶ added in v1.2.8
func (jia JSONIntArray) String() string
type JSONObject ¶ added in v1.0.27
func (*JSONObject) Scan ¶ added in v1.0.27
func (jo *JSONObject) Scan(value any) error
func (JSONObject) String ¶ added in v1.2.8
func (jo JSONObject) String() string
type JSONStringArray ¶ added in v1.0.27
type JSONStringArray []string
func (*JSONStringArray) Scan ¶ added in v1.0.27
func (jsa *JSONStringArray) Scan(value any) error
func (JSONStringArray) String ¶ added in v1.2.8
func (jsa JSONStringArray) String() string
type JSONStringObject ¶ added in v1.0.27
func (*JSONStringObject) Scan ¶ added in v1.0.27
func (jso *JSONStringObject) Scan(value any) error
func (JSONStringObject) String ¶ added in v1.2.8
func (jso JSONStringObject) String() string
type Quoter ¶ added in v1.0.15
type Quoter []rune
func GetQuoter ¶ added in v1.0.15
GetQuoteer returns the quoter for a given database given a drivername.
type RowQueryer ¶ added in v1.0.26
type SqlReader ¶ added in v1.0.17
type SqlReader struct {
// contains filtered or unexported fields
}
func NewSqlReader ¶ added in v1.0.17
type Sqlc ¶ added in v1.0.26
type Sqlc interface {
ContextQueryer
ContextExecer
ContextPreparer
}
Sqlc the context interface for sql.DB, sql.Tx