Versions in this module Expand all Collapse all v1 v1.0.0 Oct 4, 2023 Changes in this version + var BuilderFuncMap = map[string]BuilderFunc + var CompositePKError = errors.New("composite primary key is not supported") + var DbTag = "db" + var DefaultLikeEscape = []string + var MissingPKError = errors.New("missing primary key declaration") + func DefaultFieldMapFunc(f string) string + func GetTableName(a interface{}) string + type AndOrExp struct + func (e *AndOrExp) Build(db *DB, params Params) string + type BaseBuilder struct + func NewBaseBuilder(db *DB, executor Executor) *BaseBuilder + func (b *BaseBuilder) AddColumn(table, col, typ string) *Query + func (b *BaseBuilder) AddForeignKey(table, name string, cols, refCols []string, refTable string, options ...string) *Query + func (b *BaseBuilder) AddPrimaryKey(table, name string, cols ...string) *Query + func (b *BaseBuilder) AlterColumn(table, col, typ string) *Query + func (b *BaseBuilder) CreateIndex(table, name string, cols ...string) *Query + func (b *BaseBuilder) CreateTable(table string, cols map[string]string, options ...string) *Query + func (b *BaseBuilder) CreateUniqueIndex(table, name string, cols ...string) *Query + func (b *BaseBuilder) DB() *DB + func (b *BaseBuilder) Delete(table string, where Expression) *Query + func (b *BaseBuilder) DropColumn(table, col string) *Query + func (b *BaseBuilder) DropForeignKey(table, name string) *Query + func (b *BaseBuilder) DropIndex(table, name string) *Query + func (b *BaseBuilder) DropPrimaryKey(table, name string) *Query + func (b *BaseBuilder) DropTable(table string) *Query + func (b *BaseBuilder) Executor() Executor + func (b *BaseBuilder) GeneratePlaceholder(int) string + func (b *BaseBuilder) Insert(table string, cols Params) *Query + func (b *BaseBuilder) NewQuery(sql string) *Query + func (b *BaseBuilder) Quote(s string) string + func (b *BaseBuilder) QuoteSimpleColumnName(s string) string + func (b *BaseBuilder) QuoteSimpleTableName(s string) string + func (b *BaseBuilder) RenameColumn(table, oldName, newName string) *Query + func (b *BaseBuilder) RenameTable(oldName, newName string) *Query + func (b *BaseBuilder) TruncateTable(table string) *Query + func (b *BaseBuilder) Update(table string, cols Params, where Expression) *Query + func (b *BaseBuilder) Upsert(table string, cols Params, constraints ...string) *Query + type BaseQueryBuilder struct + func NewBaseQueryBuilder(db *DB) *BaseQueryBuilder + func (q *BaseQueryBuilder) BuildFrom(tables []string) string + func (q *BaseQueryBuilder) BuildGroupBy(cols []string) string + func (q *BaseQueryBuilder) BuildHaving(e Expression, params Params) string + func (q *BaseQueryBuilder) BuildJoin(joins []JoinInfo, params Params) string + func (q *BaseQueryBuilder) BuildLimit(limit int64, offset int64) string + func (q *BaseQueryBuilder) BuildOrderBy(cols []string) string + func (q *BaseQueryBuilder) BuildOrderByAndLimit(sql string, cols []string, limit int64, offset int64) string + func (q *BaseQueryBuilder) BuildSelect(cols []string, distinct bool, option string) string + func (q *BaseQueryBuilder) BuildUnion(unions []UnionInfo, params Params) string + func (q *BaseQueryBuilder) BuildWhere(e Expression, params Params) string + func (q *BaseQueryBuilder) DB() *DB + type BetweenExp struct + func (e *BetweenExp) Build(db *DB, params Params) string + type Builder interface + AddColumn func(table, col, typ string) *Query + AddForeignKey func(table, name string, cols, refCols []string, refTable string, options ...string) *Query + AddPrimaryKey func(table, name string, cols ...string) *Query + AlterColumn func(table, col, typ string) *Query + CreateIndex func(table, name string, cols ...string) *Query + CreateTable func(table string, cols map[string]string, options ...string) *Query + CreateUniqueIndex func(table, name string, cols ...string) *Query + Delete func(table string, where Expression) *Query + DropColumn func(table, col string) *Query + DropForeignKey func(table, name string) *Query + DropIndex func(table, name string) *Query + DropPrimaryKey func(table, name string) *Query + DropTable func(table string) *Query + GeneratePlaceholder func(int) string + Insert func(table string, cols Params) *Query + Model func(interface{}) *ModelQuery + NewQuery func(string) *Query + QueryBuilder func() QueryBuilder + Quote func(string) string + QuoteSimpleColumnName func(string) string + QuoteSimpleTableName func(string) string + RenameColumn func(table, oldName, newName string) *Query + RenameTable func(oldName, newName string) *Query + Select func(...string) *SelectQuery + TruncateTable func(table string) *Query + Update func(table string, cols Params, where Expression) *Query + Upsert func(table string, cols Params, constraints ...string) *Query + func NewMssqlBuilder(db *DB, executor Executor) Builder + func NewMysqlBuilder(db *DB, executor Executor) Builder + func NewOciBuilder(db *DB, executor Executor) Builder + func NewPgsqlBuilder(db *DB, executor Executor) Builder + func NewSqliteBuilder(db *DB, executor Executor) Builder + func NewStandardBuilder(db *DB, executor Executor) Builder + type BuilderFunc func(*DB, Executor) Builder + type DB struct + ExecLogFunc ExecLogFunc + FieldMapper FieldMapFunc + LogFunc LogFunc + PerfFunc PerfFunc + QueryLogFunc QueryLogFunc + TableMapper TableMapFunc + func MustOpen(driverName, dsn string) (*DB, error) + func NewFromDB(sqlDB *sql.DB, driverName string) *DB + func Open(driverName, dsn string) (*DB, error) + func (db *DB) Begin() (*Tx, error) + func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) + func (db *DB) Clone() *DB + func (db *DB) Close() error + func (db *DB) Context() context.Context + func (db *DB) DB() *sql.DB + func (db *DB) DriverName() string + func (db *DB) QuoteColumnName(s string) string + func (db *DB) QuoteTableName(s string) string + func (db *DB) Transactional(f func(*Tx) error) (err error) + func (db *DB) TransactionalContext(ctx context.Context, opts *sql.TxOptions, f func(*Tx) error) (err error) + func (db *DB) WithContext(ctx context.Context) *DB + func (db *DB) Wrap(sqlTx *sql.Tx) *Tx + type Errors []error + func (errs Errors) Error() string + type ExecLogFunc func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) + type Executor interface + Exec func(query string, args ...interface{}) (sql.Result, error) + ExecContext func(ctx context.Context, query string, args ...interface{}) (sql.Result, error) + Prepare func(query string) (*sql.Stmt, error) + Query func(query string, args ...interface{}) (*sql.Rows, error) + QueryContext func(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) + type ExistsExp struct + func (e *ExistsExp) Build(db *DB, params Params) string + type Exp struct + func (e *Exp) Build(db *DB, params Params) string + type Expression interface + Build func(*DB, Params) string + func And(exps ...Expression) Expression + func Between(col string, from, to interface{}) Expression + func Exists(exp Expression) Expression + func In(col string, values ...interface{}) Expression + func NewExp(e string, params ...Params) Expression + func Not(e Expression) Expression + func NotBetween(col string, from, to interface{}) Expression + func NotExists(exp Expression) Expression + func NotIn(col string, values ...interface{}) Expression + func Or(exps ...Expression) Expression + type FieldMapFunc func(string) string + type HashExp map[string]interface + func (e HashExp) Build(db *DB, params Params) string + type InExp struct + func (e *InExp) Build(db *DB, params Params) string + type JoinInfo struct + Join string + On Expression + Table string + type LikeExp struct + Like string + func Like(col string, values ...string) *LikeExp + func NotLike(col string, values ...string) *LikeExp + func OrLike(col string, values ...string) *LikeExp + func OrNotLike(col string, values ...string) *LikeExp + func (e *LikeExp) Build(db *DB, params Params) string + func (e *LikeExp) Escape(chars ...string) *LikeExp + func (e *LikeExp) Match(left, right bool) *LikeExp + type LogFunc func(format string, a ...interface{}) + type ModelQuery struct + func NewModelQuery(model interface{}, fieldMapFunc FieldMapFunc, db *DB, builder Builder) *ModelQuery + func (q *ModelQuery) Context() context.Context + func (q *ModelQuery) Delete() error + func (q *ModelQuery) Exclude(attrs ...string) *ModelQuery + func (q *ModelQuery) Insert(attrs ...string) error + func (q *ModelQuery) Update(attrs ...string) error + func (q *ModelQuery) WithContext(ctx context.Context) *ModelQuery + type MssqlBuilder struct + func (b *MssqlBuilder) AlterColumn(table, col, typ string) *Query + func (b *MssqlBuilder) Model(model interface{}) *ModelQuery + func (b *MssqlBuilder) QueryBuilder() QueryBuilder + func (b *MssqlBuilder) QuoteSimpleColumnName(s string) string + func (b *MssqlBuilder) QuoteSimpleTableName(s string) string + func (b *MssqlBuilder) RenameColumn(table, oldName, newName string) *Query + func (b *MssqlBuilder) RenameTable(oldName, newName string) *Query + func (b *MssqlBuilder) Select(cols ...string) *SelectQuery + type MssqlQueryBuilder struct + func (q *MssqlQueryBuilder) BuildOrderByAndLimit(sql string, cols []string, limit int64, offset int64) string + type MysqlBuilder struct + func (b *MysqlBuilder) DropForeignKey(table, name string) *Query + func (b *MysqlBuilder) DropPrimaryKey(table, name string) *Query + func (b *MysqlBuilder) Model(model interface{}) *ModelQuery + func (b *MysqlBuilder) QueryBuilder() QueryBuilder + func (b *MysqlBuilder) QuoteSimpleColumnName(s string) string + func (b *MysqlBuilder) QuoteSimpleTableName(s string) string + func (b *MysqlBuilder) RenameColumn(table, oldName, newName string) *Query + func (b *MysqlBuilder) Select(cols ...string) *SelectQuery + func (b *MysqlBuilder) Upsert(table string, cols Params, constraints ...string) *Query + type NotExp struct + func (e *NotExp) Build(db *DB, params Params) string + type NullStringMap map[string]sql.NullString + type OciBuilder struct + func (b *OciBuilder) AlterColumn(table, col, typ string) *Query + func (b *OciBuilder) DropIndex(table, name string) *Query + func (b *OciBuilder) GeneratePlaceholder(i int) string + func (b *OciBuilder) Model(model interface{}) *ModelQuery + func (b *OciBuilder) QueryBuilder() QueryBuilder + func (b *OciBuilder) RenameTable(oldName, newName string) *Query + func (b *OciBuilder) Select(cols ...string) *SelectQuery + type OciQueryBuilder struct + func (q *OciQueryBuilder) BuildOrderByAndLimit(sql string, cols []string, limit int64, offset int64) string + type Params map[string]interface + type PerfFunc func(ns int64, sql string, execute bool) + type PgsqlBuilder struct + func (b *PgsqlBuilder) AlterColumn(table, col, typ string) *Query + func (b *PgsqlBuilder) DropIndex(table, name string) *Query + func (b *PgsqlBuilder) GeneratePlaceholder(i int) string + func (b *PgsqlBuilder) Model(model interface{}) *ModelQuery + func (b *PgsqlBuilder) QueryBuilder() QueryBuilder + func (b *PgsqlBuilder) RenameTable(oldName, newName string) *Query + func (b *PgsqlBuilder) Select(cols ...string) *SelectQuery + func (b *PgsqlBuilder) Upsert(table string, cols Params, constraints ...string) *Query + type Query struct + ExecLogFunc ExecLogFunc + FieldMapper FieldMapFunc + LastError error + LogFunc LogFunc + PerfFunc PerfFunc + QueryLogFunc QueryLogFunc + func NewQuery(db *DB, executor Executor, sql string) *Query + func (q *Query) All(slice interface{}) error + func (q *Query) Bind(params Params) *Query + func (q *Query) Close() error + func (q *Query) Column(a interface{}) error + func (q *Query) Context() context.Context + func (q *Query) Execute() (result sql.Result, err error) + func (q *Query) One(a interface{}) error + func (q *Query) Params() Params + func (q *Query) Prepare() *Query + func (q *Query) Row(a ...interface{}) error + func (q *Query) Rows() (rows *Rows, err error) + func (q *Query) SQL() string + func (q *Query) WithContext(ctx context.Context) *Query + type QueryBuilder interface + BuildFrom func(tables []string) string + BuildGroupBy func(cols []string) string + BuildHaving func(Expression, Params) string + BuildJoin func([]JoinInfo, Params) string + BuildOrderByAndLimit func(string, []string, int64, int64) string + BuildSelect func(cols []string, distinct bool, option string) string + BuildUnion func([]UnionInfo, Params) string + BuildWhere func(Expression, Params) string + type QueryLogFunc func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) + type Rows struct + func (r *Rows) ScanMap(a NullStringMap) error + func (r *Rows) ScanStruct(a interface{}) error + type SelectQuery struct + FieldMapper FieldMapFunc + TableMapper TableMapFunc + func NewSelectQuery(builder Builder, db *DB) *SelectQuery + func (q *SelectQuery) Context() context.Context + func (q *SelectQuery) WithContext(ctx context.Context) *SelectQuery + func (s *SelectQuery) All(slice interface{}) error + func (s *SelectQuery) AndBind(params Params) *SelectQuery + func (s *SelectQuery) AndGroupBy(cols ...string) *SelectQuery + func (s *SelectQuery) AndHaving(e Expression) *SelectQuery + func (s *SelectQuery) AndOrderBy(cols ...string) *SelectQuery + func (s *SelectQuery) AndSelect(cols ...string) *SelectQuery + func (s *SelectQuery) AndWhere(e Expression) *SelectQuery + func (s *SelectQuery) Bind(params Params) *SelectQuery + func (s *SelectQuery) Build() *Query + func (s *SelectQuery) Column(a interface{}) error + func (s *SelectQuery) Distinct(v bool) *SelectQuery + func (s *SelectQuery) From(tables ...string) *SelectQuery + func (s *SelectQuery) GroupBy(cols ...string) *SelectQuery + func (s *SelectQuery) Having(e Expression) *SelectQuery + func (s *SelectQuery) InnerJoin(table string, on Expression) *SelectQuery + func (s *SelectQuery) Join(typ string, table string, on Expression) *SelectQuery + func (s *SelectQuery) LeftJoin(table string, on Expression) *SelectQuery + func (s *SelectQuery) Limit(limit int64) *SelectQuery + func (s *SelectQuery) Model(pk, model interface{}) error + func (s *SelectQuery) Offset(offset int64) *SelectQuery + func (s *SelectQuery) One(a interface{}) error + func (s *SelectQuery) OrHaving(e Expression) *SelectQuery + func (s *SelectQuery) OrWhere(e Expression) *SelectQuery + func (s *SelectQuery) OrderBy(cols ...string) *SelectQuery + func (s *SelectQuery) RightJoin(table string, on Expression) *SelectQuery + func (s *SelectQuery) Row(a ...interface{}) error + func (s *SelectQuery) Rows() (*Rows, error) + func (s *SelectQuery) Select(cols ...string) *SelectQuery + func (s *SelectQuery) SelectOption(option string) *SelectQuery + func (s *SelectQuery) Union(q *Query) *SelectQuery + func (s *SelectQuery) UnionAll(q *Query) *SelectQuery + func (s *SelectQuery) Where(e Expression) *SelectQuery + type SqliteBuilder struct + func (b *SqliteBuilder) AddForeignKey(table, name string, cols, refCols []string, refTable string, options ...string) *Query + func (b *SqliteBuilder) AddPrimaryKey(table, name string, cols ...string) *Query + func (b *SqliteBuilder) AlterColumn(table, col, typ string) *Query + func (b *SqliteBuilder) DropColumn(table, col string) *Query + func (b *SqliteBuilder) DropForeignKey(table, name string) *Query + func (b *SqliteBuilder) DropIndex(table, name string) *Query + func (b *SqliteBuilder) DropPrimaryKey(table, name string) *Query + func (b *SqliteBuilder) Model(model interface{}) *ModelQuery + func (b *SqliteBuilder) QueryBuilder() QueryBuilder + func (b *SqliteBuilder) QuoteSimpleColumnName(s string) string + func (b *SqliteBuilder) QuoteSimpleTableName(s string) string + func (b *SqliteBuilder) RenameColumn(table, oldName, newName string) *Query + func (b *SqliteBuilder) Select(cols ...string) *SelectQuery + func (b *SqliteBuilder) TruncateTable(table string) *Query + type StandardBuilder struct + func (b *StandardBuilder) Model(model interface{}) *ModelQuery + func (b *StandardBuilder) QueryBuilder() QueryBuilder + func (b *StandardBuilder) Select(cols ...string) *SelectQuery + type TableMapFunc func(a interface{}) string + type TableModel interface + TableName func() string + type Tx struct + func (t *Tx) Commit() error + func (t *Tx) Rollback() error + type UnionInfo struct + All bool + Query *Query + type VarTypeError string + func (s VarTypeError) Error() string