Documentation
¶
Overview ¶
Package sqlbuilder 提供一套通过字符串拼接来构成 SQL 语句的工具
sqlbuilder 提供了部分 *Hooker 的接口,用于自定义某一条语句的实现。 一般情况下, 如果有多个数据是遵循 SQL 标准的,只有个别有例外, 那么该例外的 Dialect 实现,可以同时实现 Hooker 接口, 自定义该语句的实现。
Index ¶
- Variables
- func Version(e core.Engine) (version string, err error)
- type AddColumnStmt
- func (stmt *AddColumnStmt) Column(name string, p core.PrimitiveType, ai, nullable, hasDefault bool, ...) *AddColumnStmt
- func (stmt *AddColumnStmt) DDLSQL() ([]string, error)
- func (stmt AddColumnStmt) Exec() error
- func (stmt AddColumnStmt) ExecContext(ctx context.Context) error
- func (stmt *AddColumnStmt) Reset() *AddColumnStmt
- func (stmt *AddColumnStmt) Table(table string) *AddColumnStmt
- type AddConstraintStmt
- func (stmt *AddConstraintStmt) Check(name, expr string) *AddConstraintStmt
- func (stmt *AddConstraintStmt) DDLSQL() ([]string, error)
- func (stmt AddConstraintStmt) Exec() error
- func (stmt AddConstraintStmt) ExecContext(ctx context.Context) error
- func (stmt *AddConstraintStmt) FK(name, col, refTable, refColumn, updateRule, deleteRule string) *AddConstraintStmt
- func (stmt *AddConstraintStmt) PK(col ...string) *AddConstraintStmt
- func (stmt *AddConstraintStmt) Reset() *AddConstraintStmt
- func (stmt *AddConstraintStmt) Table(t string) *AddConstraintStmt
- func (stmt *AddConstraintStmt) Unique(name string, col ...string) *AddConstraintStmt
- type AddConstraintStmtHooker
- type CreateIndexStmt
- func (stmt *CreateIndexStmt) Columns(col ...string) *CreateIndexStmt
- func (stmt *CreateIndexStmt) DDLSQL() ([]string, error)
- func (stmt CreateIndexStmt) Exec() error
- func (stmt CreateIndexStmt) ExecContext(ctx context.Context) error
- func (stmt *CreateIndexStmt) Name(index string) *CreateIndexStmt
- func (stmt *CreateIndexStmt) Reset() *CreateIndexStmt
- func (stmt *CreateIndexStmt) Table(tbl string) *CreateIndexStmt
- func (stmt *CreateIndexStmt) Type(t core.Index) *CreateIndexStmt
- type CreateTableStmt
- func (stmt *CreateTableStmt) AutoIncrement(col string, p core.PrimitiveType) *CreateTableStmt
- func (stmt *CreateTableStmt) Check(name string, expr string) *CreateTableStmt
- func (stmt *CreateTableStmt) Column(name string, p core.PrimitiveType, ai, nullable, hasDefault bool, ...) *CreateTableStmt
- func (stmt *CreateTableStmt) Columns(col ...*core.Column) *CreateTableStmt
- func (stmt *CreateTableStmt) DDLSQL() ([]string, error)
- func (stmt CreateTableStmt) Exec() error
- func (stmt CreateTableStmt) ExecContext(ctx context.Context) error
- func (stmt *CreateTableStmt) ForeignKey(name, col, refTable, refCol, updateRule, deleteRule string) *CreateTableStmt
- func (stmt *CreateTableStmt) Index(typ core.Index, name string, col ...string) *CreateTableStmt
- func (stmt *CreateTableStmt) PK(col ...string) *CreateTableStmt
- func (stmt *CreateTableStmt) Reset() *CreateTableStmt
- func (stmt *CreateTableStmt) Table(t string) *CreateTableStmt
- func (stmt *CreateTableStmt) Unique(name string, col ...string) *CreateTableStmt
- type CreateViewStmt
- func (stmt *CreateViewStmt) Column(col ...string) *CreateViewStmt
- func (stmt *CreateViewStmt) DDLSQL() ([]string, error)
- func (stmt CreateViewStmt) Exec() error
- func (stmt CreateViewStmt) ExecContext(ctx context.Context) error
- func (stmt *CreateViewStmt) From(sel *SelectStmt) *CreateViewStmt
- func (stmt *CreateViewStmt) Name(name string) *CreateViewStmt
- func (stmt *CreateViewStmt) Replace() *CreateViewStmt
- func (stmt *CreateViewStmt) Reset() *CreateViewStmt
- func (stmt *CreateViewStmt) Temporary() *CreateViewStmt
- type CreateViewStmtHooker
- type DDLSQLer
- type DeleteStmt
- func (stmt *DeleteStmt) And(cond string, args ...interface{}) *DeleteStmt
- func (stmt *DeleteStmt) AndBetween(col string, v1, v2 interface{}) *DeleteStmt
- func (stmt *DeleteStmt) AndGroup() *WhereStmt
- func (stmt *DeleteStmt) AndIn(col string, v ...interface{}) *DeleteStmt
- func (stmt *DeleteStmt) AndIsNotNull(col string) *DeleteStmt
- func (stmt *DeleteStmt) AndIsNull(col string) *DeleteStmt
- func (stmt *DeleteStmt) AndLike(col string, content interface{}) *DeleteStmt
- func (stmt *DeleteStmt) AndNotBetween(col string, v1, v2 interface{}) *DeleteStmt
- func (stmt *DeleteStmt) AndNotIn(col string, v ...interface{}) *DeleteStmt
- func (stmt *DeleteStmt) AndNotLike(col string, content interface{}) *DeleteStmt
- func (stmt DeleteStmt) CombineSQL() (query string, err error)
- func (stmt DeleteStmt) Exec() (sql.Result, error)
- func (stmt DeleteStmt) ExecContext(ctx context.Context) (sql.Result, error)
- func (stmt *DeleteStmt) Or(cond string, args ...interface{}) *DeleteStmt
- func (stmt *DeleteStmt) OrBetween(col string, v1, v2 interface{}) *DeleteStmt
- func (stmt *DeleteStmt) OrGroup() *WhereStmt
- func (stmt *DeleteStmt) OrIn(col string, v ...interface{}) *DeleteStmt
- func (stmt *DeleteStmt) OrIsNotNull(col string) *DeleteStmt
- func (stmt *DeleteStmt) OrIsNull(col string) *DeleteStmt
- func (stmt *DeleteStmt) OrLike(col string, content interface{}) *DeleteStmt
- func (stmt *DeleteStmt) OrNotBetween(col string, v1, v2 interface{}) *DeleteStmt
- func (stmt *DeleteStmt) OrNotIn(col string, v ...interface{}) *DeleteStmt
- func (stmt *DeleteStmt) OrNotLike(col string, content interface{}) *DeleteStmt
- func (stmt DeleteStmt) Prepare() (*core.Stmt, error)
- func (stmt DeleteStmt) PrepareContext(ctx context.Context) (*core.Stmt, error)
- func (stmt *DeleteStmt) Reset() *DeleteStmt
- func (stmt *DeleteStmt) SQL() (string, []interface{}, error)
- func (stmt *DeleteStmt) Table(table string) *DeleteStmt
- func (stmt *DeleteStmt) Where(cond string, args ...interface{}) *DeleteStmt
- func (stmt *DeleteStmt) WhereStmt() *WhereStmt
- type DropColumnStmt
- func (stmt *DropColumnStmt) Column(col string) *DropColumnStmt
- func (stmt *DropColumnStmt) DDLSQL() ([]string, error)
- func (stmt DropColumnStmt) Exec() error
- func (stmt DropColumnStmt) ExecContext(ctx context.Context) error
- func (stmt *DropColumnStmt) Reset() *DropColumnStmt
- func (stmt *DropColumnStmt) Table(table string) *DropColumnStmt
- type DropColumnStmtHooker
- type DropConstraintStmt
- func (stmt *DropConstraintStmt) Constraint(name string) *DropConstraintStmt
- func (stmt *DropConstraintStmt) DDLSQL() ([]string, error)
- func (stmt DropConstraintStmt) Exec() error
- func (stmt DropConstraintStmt) ExecContext(ctx context.Context) error
- func (stmt *DropConstraintStmt) PK() *DropConstraintStmt
- func (stmt *DropConstraintStmt) Reset() *DropConstraintStmt
- func (stmt *DropConstraintStmt) Table(table string) *DropConstraintStmt
- type DropConstraintStmtHooker
- type DropIndexStmt
- func (stmt *DropIndexStmt) DDLSQL() ([]string, error)
- func (stmt DropIndexStmt) Exec() error
- func (stmt DropIndexStmt) ExecContext(ctx context.Context) error
- func (stmt *DropIndexStmt) Name(col string) *DropIndexStmt
- func (stmt *DropIndexStmt) Reset() *DropIndexStmt
- func (stmt *DropIndexStmt) Table(tbl string) *DropIndexStmt
- type DropIndexStmtHooker
- type DropTableStmt
- type DropViewStmt
- type InsertDefaultValueHooker
- type InsertStmt
- func (stmt *InsertStmt) Columns(cols ...string) *InsertStmt
- func (stmt InsertStmt) CombineSQL() (query string, err error)
- func (stmt InsertStmt) Exec() (sql.Result, error)
- func (stmt InsertStmt) ExecContext(ctx context.Context) (sql.Result, error)
- func (stmt *InsertStmt) KeyValue(col string, val interface{}) *InsertStmt
- func (stmt *InsertStmt) LastInsertID(table, col string) (int64, error)
- func (stmt *InsertStmt) LastInsertIDContext(ctx context.Context, table, col string) (id int64, err error)
- func (stmt InsertStmt) Prepare() (*core.Stmt, error)
- func (stmt InsertStmt) PrepareContext(ctx context.Context) (*core.Stmt, error)
- func (stmt *InsertStmt) Reset() *InsertStmt
- func (stmt *InsertStmt) SQL() (string, []interface{}, error)
- func (stmt *InsertStmt) Select(sel *SelectStmt) *InsertStmt
- func (stmt *InsertStmt) Table(table string) *InsertStmt
- func (stmt *InsertStmt) Values(vals ...interface{}) *InsertStmt
- type SQLBuilder
- func (sql *SQLBuilder) AddColumn() *AddColumnStmt
- func (sql *SQLBuilder) AddConstraint() *AddConstraintStmt
- func (sql *SQLBuilder) CreateIndex() *CreateIndexStmt
- func (sql *SQLBuilder) CreateTable() *CreateTableStmt
- func (sql *SQLBuilder) CreateView() *CreateViewStmt
- func (sql *SQLBuilder) Delete() *DeleteStmt
- func (sql *SQLBuilder) DropColumn() *DropColumnStmt
- func (sql *SQLBuilder) DropConstraint() *DropConstraintStmt
- func (sql *SQLBuilder) DropIndex() *DropIndexStmt
- func (sql *SQLBuilder) DropTable() *DropTableStmt
- func (sql *SQLBuilder) Insert() *InsertStmt
- func (sql *SQLBuilder) Select() *SelectStmt
- func (sql *SQLBuilder) TruncateTable() *TruncateTableStmt
- func (sql *SQLBuilder) Update() *UpdateStmt
- func (sql *SQLBuilder) Where() *WhereStmt
- type SQLer
- type SelectStmt
- func (stmt *SelectStmt) And(cond string, args ...interface{}) *SelectStmt
- func (stmt *SelectStmt) AndBetween(col string, v1, v2 interface{}) *SelectStmt
- func (stmt *SelectStmt) AndGroup() *WhereStmt
- func (stmt *SelectStmt) AndIn(col string, v ...interface{}) *SelectStmt
- func (stmt *SelectStmt) AndIsNotNull(col string) *SelectStmt
- func (stmt *SelectStmt) AndIsNull(col string) *SelectStmt
- func (stmt *SelectStmt) AndLike(col string, content interface{}) *SelectStmt
- func (stmt *SelectStmt) AndNotBetween(col string, v1, v2 interface{}) *SelectStmt
- func (stmt *SelectStmt) AndNotIn(col string, v ...interface{}) *SelectStmt
- func (stmt *SelectStmt) AndNotLike(col string, content interface{}) *SelectStmt
- func (stmt *SelectStmt) Asc(col ...string) *SelectStmt
- func (stmt *SelectStmt) Column(col string) *SelectStmt
- func (stmt *SelectStmt) Columns(cols ...string) *SelectStmt
- func (stmt SelectStmt) CombineSQL() (query string, err error)
- func (stmt *SelectStmt) Count(expr string) *SelectStmt
- func (stmt *SelectStmt) Desc(col ...string) *SelectStmt
- func (stmt *SelectStmt) Distinct() *SelectStmt
- func (stmt *SelectStmt) ForUpdate() *SelectStmt
- func (stmt *SelectStmt) From(table string, alias ...string) *SelectStmt
- func (stmt *SelectStmt) Group(col string) *SelectStmt
- func (stmt *SelectStmt) Having(expr string, args ...interface{}) *SelectStmt
- func (stmt *SelectStmt) Insert() *InsertStmt
- func (stmt *SelectStmt) Join(typ, table, alias, on string) *SelectStmt
- func (stmt *SelectStmt) Limit(limit interface{}, offset ...interface{}) *SelectStmt
- func (stmt *SelectStmt) Or(cond string, args ...interface{}) *SelectStmt
- func (stmt *SelectStmt) OrBetween(col string, v1, v2 interface{}) *SelectStmt
- func (stmt *SelectStmt) OrGroup() *WhereStmt
- func (stmt *SelectStmt) OrIn(col string, v ...interface{}) *SelectStmt
- func (stmt *SelectStmt) OrIsNotNull(col string) *SelectStmt
- func (stmt *SelectStmt) OrIsNull(col string) *SelectStmt
- func (stmt *SelectStmt) OrLike(col string, content interface{}) *SelectStmt
- func (stmt *SelectStmt) OrNotBetween(col string, v1, v2 interface{}) *SelectStmt
- func (stmt *SelectStmt) OrNotIn(col string, v ...interface{}) *SelectStmt
- func (stmt *SelectStmt) OrNotLike(col string, content interface{}) *SelectStmt
- func (stmt SelectStmt) Prepare() (*core.Stmt, error)
- func (stmt SelectStmt) PrepareContext(ctx context.Context) (*core.Stmt, error)
- func (stmt SelectStmt) Query() (*sql.Rows, error)
- func (stmt SelectStmt) QueryContext(ctx context.Context) (*sql.Rows, error)
- func (stmt *SelectStmt) QueryFloat(colName string) (float64, error)
- func (stmt *SelectStmt) QueryInt(colName string) (int64, error)
- func (stmt *SelectStmt) QueryObject(strict bool, objs interface{}) (size int, err error)
- func (stmt *SelectStmt) QueryString(colName string) (v string, err error)
- func (stmt *SelectStmt) Reset() *SelectStmt
- func (stmt *SelectStmt) SQL() (string, []interface{}, error)
- func (stmt *SelectStmt) Union(all bool, sel ...*SelectStmt) *SelectStmt
- func (stmt *SelectStmt) View(name string) *CreateViewStmt
- func (stmt *SelectStmt) Where(cond string, args ...interface{}) *SelectStmt
- func (stmt *SelectStmt) WhereStmt() *WhereStmt
- type TruncateTableStmt
- func (stmt *TruncateTableStmt) DDLSQL() ([]string, error)
- func (stmt TruncateTableStmt) Exec() error
- func (stmt TruncateTableStmt) ExecContext(ctx context.Context) error
- func (stmt *TruncateTableStmt) Reset() *TruncateTableStmt
- func (stmt *TruncateTableStmt) Table(t, aiColumn string) *TruncateTableStmt
- type TruncateTableStmtHooker
- type UpdateStmt
- func (stmt *UpdateStmt) And(cond string, args ...interface{}) *UpdateStmt
- func (stmt *UpdateStmt) AndBetween(col string, v1, v2 interface{}) *UpdateStmt
- func (stmt *UpdateStmt) AndGroup() *WhereStmt
- func (stmt *UpdateStmt) AndIn(col string, v ...interface{}) *UpdateStmt
- func (stmt *UpdateStmt) AndIsNotNull(col string) *UpdateStmt
- func (stmt *UpdateStmt) AndIsNull(col string) *UpdateStmt
- func (stmt *UpdateStmt) AndLike(col string, content interface{}) *UpdateStmt
- func (stmt *UpdateStmt) AndNotBetween(col string, v1, v2 interface{}) *UpdateStmt
- func (stmt *UpdateStmt) AndNotIn(col string, v ...interface{}) *UpdateStmt
- func (stmt *UpdateStmt) AndNotLike(col string, content interface{}) *UpdateStmt
- func (stmt UpdateStmt) CombineSQL() (query string, err error)
- func (stmt *UpdateStmt) Decrease(col string, val interface{}) *UpdateStmt
- func (stmt UpdateStmt) Exec() (sql.Result, error)
- func (stmt UpdateStmt) ExecContext(ctx context.Context) (sql.Result, error)
- func (stmt *UpdateStmt) Increase(col string, val interface{}) *UpdateStmt
- func (stmt *UpdateStmt) OCC(col string, val interface{}) *UpdateStmt
- func (stmt *UpdateStmt) Or(cond string, args ...interface{}) *UpdateStmt
- func (stmt *UpdateStmt) OrBetween(col string, v1, v2 interface{}) *UpdateStmt
- func (stmt *UpdateStmt) OrGroup() *WhereStmt
- func (stmt *UpdateStmt) OrIn(col string, v ...interface{}) *UpdateStmt
- func (stmt *UpdateStmt) OrIsNotNull(col string) *UpdateStmt
- func (stmt *UpdateStmt) OrIsNull(col string) *UpdateStmt
- func (stmt *UpdateStmt) OrLike(col string, content interface{}) *UpdateStmt
- func (stmt *UpdateStmt) OrNotBetween(col string, v1, v2 interface{}) *UpdateStmt
- func (stmt *UpdateStmt) OrNotIn(col string, v ...interface{}) *UpdateStmt
- func (stmt *UpdateStmt) OrNotLike(col string, content interface{}) *UpdateStmt
- func (stmt UpdateStmt) Prepare() (*core.Stmt, error)
- func (stmt UpdateStmt) PrepareContext(ctx context.Context) (*core.Stmt, error)
- func (stmt *UpdateStmt) Reset() *UpdateStmt
- func (stmt *UpdateStmt) SQL() (string, []interface{}, error)
- func (stmt *UpdateStmt) Set(col string, val interface{}) *UpdateStmt
- func (stmt *UpdateStmt) Table(table string) *UpdateStmt
- func (stmt *UpdateStmt) Where(cond string, args ...interface{}) *UpdateStmt
- func (stmt *UpdateStmt) WhereStmt() *WhereStmt
- type WhereStmt
- func (stmt *WhereStmt) And(cond string, args ...interface{}) *WhereStmt
- func (stmt *WhereStmt) AndBetween(col string, v1, v2 interface{}) *WhereStmt
- func (stmt *WhereStmt) AndGroup() *WhereStmt
- func (stmt *WhereStmt) AndIn(col string, v ...interface{}) *WhereStmt
- func (stmt *WhereStmt) AndIsNotNull(col string) *WhereStmt
- func (stmt *WhereStmt) AndIsNull(col string) *WhereStmt
- func (stmt *WhereStmt) AndLike(col string, content interface{}) *WhereStmt
- func (stmt *WhereStmt) AndNotBetween(col string, v1, v2 interface{}) *WhereStmt
- func (stmt *WhereStmt) AndNotIn(col string, v ...interface{}) *WhereStmt
- func (stmt *WhereStmt) AndNotLike(col string, content interface{}) *WhereStmt
- func (stmt *WhereStmt) Delete(e core.Engine) *DeleteStmt
- func (stmt *WhereStmt) EndGroup() (parent *WhereStmt)
- func (stmt *WhereStmt) Or(cond string, args ...interface{}) *WhereStmt
- func (stmt *WhereStmt) OrBetween(col string, v1, v2 interface{}) *WhereStmt
- func (stmt *WhereStmt) OrGroup() *WhereStmt
- func (stmt *WhereStmt) OrIn(col string, v ...interface{}) *WhereStmt
- func (stmt *WhereStmt) OrIsNotNull(col string) *WhereStmt
- func (stmt *WhereStmt) OrIsNull(col string) *WhereStmt
- func (stmt *WhereStmt) OrLike(col string, content interface{}) *WhereStmt
- func (stmt *WhereStmt) OrNotBetween(col string, v1, v2 interface{}) *WhereStmt
- func (stmt *WhereStmt) OrNotIn(col string, v ...interface{}) *WhereStmt
- func (stmt *WhereStmt) OrNotLike(col string, content interface{}) *WhereStmt
- func (stmt *WhereStmt) Reset()
- func (stmt *WhereStmt) SQL() (string, []interface{}, error)
- func (stmt *WhereStmt) Select(e core.Engine) *SelectStmt
- func (stmt *WhereStmt) Update(e core.Engine) *UpdateStmt
- type WhereStmter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTableIsEmpty 未指定表名,任何 SQL 语句中, // 若未指定表名时,会返回此错误 ErrTableIsEmpty = errors.New("表名为空") // ErrValueIsEmpty 在 Update 和 Insert 语句中, // 若未指定任何值,则返回此错误 ErrValueIsEmpty = errors.New("值为空") // ErrColumnsIsEmpty 在 Insert 和 Select 语句中, // 若未指定任何列表,则返回此错误 ErrColumnsIsEmpty = errors.New("未指定列") // ErrConstraintIsEmpty 约束名不能为空,某些需要操作约束的 SQL 会返回此值。 ErrConstraintIsEmpty = errors.New("约束名不能为空") // ErrDupColumn 在 Update 中可能存在重复设置的列名。 ErrDupColumn = errors.New("重复的列名") // ErrArgsNotMatch 在生成的 SQL 语句中,传递的参数与语句的占位符数量不匹配。 ErrArgsNotMatch = errors.New("列与值的数量不匹配") // ErrUnknownConstraint 该约束类型不支持,或是当前环境下无法使用 ErrUnknownConstraint = errors.New("不支持的约束类型") // ErrNotImplemented 部分数据库如果没有实现的功能,可以返回该错误 ErrNotImplemented = errors.New("未实现该功能") // ErrConstraintType 约束类型错误 ErrConstraintType = errors.New("约束类型错误,已经设置为其它约束") // ErrUnionColumnNotMatch 在 Union 中,各个 select 中的列长度不相同。 ErrUnionColumnNotMatch = errors.New("union 列长度不相同") )
var ErrNoData = errors.New("不存在符合和条件的数据")
ErrNoData 在 Select.QueryInt 等函数中, 如果没有符合条件的数据,则返回此错误。
Functions ¶
Types ¶
type AddColumnStmt ¶
type AddColumnStmt struct {
// contains filtered or unexported fields
}
AddColumnStmt 添加列
func (*AddColumnStmt) Column ¶
func (stmt *AddColumnStmt) Column(name string, p core.PrimitiveType, ai, nullable, hasDefault bool, def interface{}, length ...int) *AddColumnStmt
Column 添加列
参数信息可参考 CreateTableStmt.Column
func (*AddColumnStmt) DDLSQL ¶
func (stmt *AddColumnStmt) DDLSQL() ([]string, error)
DDLSQL 获取 SQL 语句以及对应的参数
func (AddColumnStmt) ExecContext ¶
func (*AddColumnStmt) Table ¶
func (stmt *AddColumnStmt) Table(table string) *AddColumnStmt
Table 指定表名。 重复指定,会覆盖之前的。
type AddConstraintStmt ¶
type AddConstraintStmt struct { TableName string Name string Type core.Constraint // 约束的值,根据 Type 的不同,略有不同: // check 下表示的 check 表达式,仅有一个元素; // fk 下最多可以有 5 个值,第 1 个元素为关联的列,2、3 元素引用的表和列, // 4,5 元素为 UPDATE 和 DELETE 的规则定义; // 其它模式下为该约束关联的列名称。 Data []string // contains filtered or unexported fields }
AddConstraintStmt 添加约束
func (*AddConstraintStmt) Check ¶
func (stmt *AddConstraintStmt) Check(name, expr string) *AddConstraintStmt
Check Check 约束
func (*AddConstraintStmt) DDLSQL ¶
func (stmt *AddConstraintStmt) DDLSQL() ([]string, error)
DDLSQL 生成 SQL 语句
func (AddConstraintStmt) ExecContext ¶
func (*AddConstraintStmt) FK ¶
func (stmt *AddConstraintStmt) FK(name, col, refTable, refColumn, updateRule, deleteRule string) *AddConstraintStmt
FK 外键约束
func (*AddConstraintStmt) PK ¶
func (stmt *AddConstraintStmt) PK(col ...string) *AddConstraintStmt
PK 指定主键约束
func (*AddConstraintStmt) Reset ¶
func (stmt *AddConstraintStmt) Reset() *AddConstraintStmt
Reset 重置内容
func (*AddConstraintStmt) Table ¶
func (stmt *AddConstraintStmt) Table(t string) *AddConstraintStmt
Table 指定表名
func (*AddConstraintStmt) Unique ¶
func (stmt *AddConstraintStmt) Unique(name string, col ...string) *AddConstraintStmt
Unique 指定唯一约束
type AddConstraintStmtHooker ¶
type AddConstraintStmtHooker interface {
AddConstraintStmtHook(*AddConstraintStmt) ([]string, error)
}
AddConstraintStmtHooker AddConstraintStmt.DDLSQL 的钩子函数
type CreateIndexStmt ¶
type CreateIndexStmt struct {
// contains filtered or unexported fields
}
CreateIndexStmt 创建索引的语句
func CreateIndex ¶
func CreateIndex(e core.Engine) *CreateIndexStmt
CreateIndex 声明一条 CreateIndexStmt 语句
func (*CreateIndexStmt) Columns ¶
func (stmt *CreateIndexStmt) Columns(col ...string) *CreateIndexStmt
Columns 列名
func (*CreateIndexStmt) DDLSQL ¶
func (stmt *CreateIndexStmt) DDLSQL() ([]string, error)
DDLSQL 生成 SQL 语句
func (CreateIndexStmt) ExecContext ¶
func (*CreateIndexStmt) Name ¶
func (stmt *CreateIndexStmt) Name(index string) *CreateIndexStmt
Name 指定索引名
func (*CreateIndexStmt) Table ¶
func (stmt *CreateIndexStmt) Table(tbl string) *CreateIndexStmt
Table 指定表名
func (*CreateIndexStmt) Type ¶
func (stmt *CreateIndexStmt) Type(t core.Index) *CreateIndexStmt
Type 指定索引类型
type CreateTableStmt ¶
type CreateTableStmt struct {
// contains filtered or unexported fields
}
CreateTableStmt 创建表的语句
func CreateTable ¶
func CreateTable(e core.Engine) *CreateTableStmt
CreateTable 创建表的语句
执行创建表操作,可能包含了创建索引等多个语句, 如果 e 是一个事务类型,且 e.Dialect() 是支持事务 DDL 的, 那么在执行时,会当作一个事务处理,否则为多个语句依次执行。
func (*CreateTableStmt) AutoIncrement ¶
func (stmt *CreateTableStmt) AutoIncrement(col string, p core.PrimitiveType) *CreateTableStmt
AutoIncrement 指定自增列
自增列必定是主键。如果指定了自增,则主键必定不启作用。 功能与 Column() 中将 ai 设置 true 是一样的。
col 列名;
func (*CreateTableStmt) Check ¶
func (stmt *CreateTableStmt) Check(name string, expr string) *CreateTableStmt
Check check 约束
func (*CreateTableStmt) Column ¶
func (stmt *CreateTableStmt) Column(name string, p core.PrimitiveType, ai, nullable, hasDefault bool, def interface{}, length ...int) *CreateTableStmt
Column 添加列
name 列的名称; p Go 中的类型,该类型会被转换成相应的数据库类型; ai 是否自增列; nullable 表示该列是否可以为 NULL; hasDefault 表示是否拥有默认值,如果为 true,则 v 同时会被当作默认值; def 默认值; length 表示长度信息。
func (*CreateTableStmt) Columns ¶
func (stmt *CreateTableStmt) Columns(col ...*core.Column) *CreateTableStmt
Columns 添加列
func (*CreateTableStmt) DDLSQL ¶
func (stmt *CreateTableStmt) DDLSQL() ([]string, error)
DDLSQL 获取 SQL 的语句及参数部分
func (CreateTableStmt) ExecContext ¶
func (*CreateTableStmt) ForeignKey ¶
func (stmt *CreateTableStmt) ForeignKey(name, col, refTable, refCol, updateRule, deleteRule string) *CreateTableStmt
ForeignKey 指定外键
func (*CreateTableStmt) Index ¶
func (stmt *CreateTableStmt) Index(typ core.Index, name string, col ...string) *CreateTableStmt
Index 添加索引
func (*CreateTableStmt) PK ¶
func (stmt *CreateTableStmt) PK(col ...string) *CreateTableStmt
PK 指定主键约束
自增会自动转换为主键
func (*CreateTableStmt) Table ¶
func (stmt *CreateTableStmt) Table(t string) *CreateTableStmt
Table 指定表名
func (*CreateTableStmt) Unique ¶
func (stmt *CreateTableStmt) Unique(name string, col ...string) *CreateTableStmt
Unique 添加唯一约束
type CreateViewStmt ¶
type CreateViewStmt struct { SelectQuery string ViewName string Columns []string IsTemporary bool IsReplace bool // contains filtered or unexported fields }
CreateViewStmt 创建视图的语句
func (*CreateViewStmt) Column ¶
func (stmt *CreateViewStmt) Column(col ...string) *CreateViewStmt
Column 指定视图的列,如果未指定,则会直接采用 Select 中的列信息
func (*CreateViewStmt) DDLSQL ¶
func (stmt *CreateViewStmt) DDLSQL() ([]string, error)
DDLSQL 返回创建视图的 SQL 语句
func (CreateViewStmt) ExecContext ¶
func (*CreateViewStmt) From ¶
func (stmt *CreateViewStmt) From(sel *SelectStmt) *CreateViewStmt
From 指定 Select 语句
func (*CreateViewStmt) Name ¶
func (stmt *CreateViewStmt) Name(name string) *CreateViewStmt
Name 指定视图名称
func (*CreateViewStmt) Replace ¶
func (stmt *CreateViewStmt) Replace() *CreateViewStmt
Replace 如果已经存在,则更新视图内容
func (*CreateViewStmt) Temporary ¶
func (stmt *CreateViewStmt) Temporary() *CreateViewStmt
Temporary 临时视图
type CreateViewStmtHooker ¶
type CreateViewStmtHooker interface {
CreateViewStmtHook(*CreateViewStmt) ([]string, error)
}
CreateViewStmtHooker CreateViewStmt.DDLSQL 的钩子函数
type DeleteStmt ¶
type DeleteStmt struct {
// contains filtered or unexported fields
}
DeleteStmt 表示删除操作的 SQL 语句
func (*DeleteStmt) And ¶
func (stmt *DeleteStmt) And(cond string, args ...interface{}) *DeleteStmt
And 添加一条 and 语句
func (*DeleteStmt) AndBetween ¶
func (stmt *DeleteStmt) AndBetween(col string, v1, v2 interface{}) *DeleteStmt
AndBetween 指定 WHERE ... AND col BETWEEN v1 AND v2
func (*DeleteStmt) AndIn ¶
func (stmt *DeleteStmt) AndIn(col string, v ...interface{}) *DeleteStmt
AndIn 指定 WHERE ... AND col IN(v...)
func (*DeleteStmt) AndIsNotNull ¶
func (stmt *DeleteStmt) AndIsNotNull(col string) *DeleteStmt
AndIsNotNull 指定 WHERE ... AND col IS NOT NULL
func (*DeleteStmt) AndIsNull ¶
func (stmt *DeleteStmt) AndIsNull(col string) *DeleteStmt
AndIsNull 指定 WHERE ... AND col IS NULL
func (*DeleteStmt) AndLike ¶
func (stmt *DeleteStmt) AndLike(col string, content interface{}) *DeleteStmt
AndLike 指定 WHERE ... AND col LIKE content
func (*DeleteStmt) AndNotBetween ¶
func (stmt *DeleteStmt) AndNotBetween(col string, v1, v2 interface{}) *DeleteStmt
AndNotBetween 指定 WHERE ... AND col NOT BETWEEN v1 AND v2
func (*DeleteStmt) AndNotIn ¶
func (stmt *DeleteStmt) AndNotIn(col string, v ...interface{}) *DeleteStmt
AndNotIn 指定 WHERE ... AND col NOT IN(v...)
func (*DeleteStmt) AndNotLike ¶
func (stmt *DeleteStmt) AndNotLike(col string, content interface{}) *DeleteStmt
AndNotLike 指定 WHERE ... AND col NOT LIKE content
func (DeleteStmt) CombineSQL ¶
CombineSQL 将 SQLer.SQL 中返回的参数替换掉 query 中的占位符, 形成一条完整的查询语句。
func (DeleteStmt) ExecContext ¶
func (*DeleteStmt) Or ¶
func (stmt *DeleteStmt) Or(cond string, args ...interface{}) *DeleteStmt
Or 添加一条 OR 语句
func (*DeleteStmt) OrBetween ¶
func (stmt *DeleteStmt) OrBetween(col string, v1, v2 interface{}) *DeleteStmt
OrBetween 指定 WHERE ... OR col BETWEEN v1 AND v2
func (*DeleteStmt) OrIn ¶
func (stmt *DeleteStmt) OrIn(col string, v ...interface{}) *DeleteStmt
OrIn 指定 WHERE ... OR col IN(v...)
func (*DeleteStmt) OrIsNotNull ¶
func (stmt *DeleteStmt) OrIsNotNull(col string) *DeleteStmt
OrIsNotNull 指定 WHERE ... OR col IS NOT NULL
func (*DeleteStmt) OrIsNull ¶
func (stmt *DeleteStmt) OrIsNull(col string) *DeleteStmt
OrIsNull 指定 WHERE ... OR col IS NULL
func (*DeleteStmt) OrLike ¶
func (stmt *DeleteStmt) OrLike(col string, content interface{}) *DeleteStmt
OrLike 指定 WHERE ... OR col LIKE content
func (*DeleteStmt) OrNotBetween ¶
func (stmt *DeleteStmt) OrNotBetween(col string, v1, v2 interface{}) *DeleteStmt
OrNotBetween 指定 WHERE ... OR col BETWEEN v1 AND v2
func (*DeleteStmt) OrNotIn ¶
func (stmt *DeleteStmt) OrNotIn(col string, v ...interface{}) *DeleteStmt
OrNotIn 指定 WHERE ... OR col IN(v...)
func (*DeleteStmt) OrNotLike ¶
func (stmt *DeleteStmt) OrNotLike(col string, content interface{}) *DeleteStmt
OrNotLike 指定 WHERE ... OR col NOT LIKE content
func (DeleteStmt) Prepare ¶
Prepare 预编译语句
预编译语句,参数最好采用 sql.NamedArg 类型。 在生成语句时,参数顺序会发生变化,如果采用 ? 的形式, 用户需要自己处理参数顺序问题,而 sql.NamedArg 没有这些问题。
func (DeleteStmt) PrepareContext ¶
func (*DeleteStmt) SQL ¶
func (stmt *DeleteStmt) SQL() (string, []interface{}, error)
SQL 获取 SQL 语句,以及其参数对应的具体值
func (*DeleteStmt) Where ¶
func (stmt *DeleteStmt) Where(cond string, args ...interface{}) *DeleteStmt
Where DeleteStmt.And 的别名
func (*DeleteStmt) WhereStmt ¶
func (stmt *DeleteStmt) WhereStmt() *WhereStmt
WhereStmt 实现 WhereStmter 接口
type DropColumnStmt ¶
type DropColumnStmt struct { TableName string ColumnName string // contains filtered or unexported fields }
DropColumnStmt 删除列
func (*DropColumnStmt) Column ¶
func (stmt *DropColumnStmt) Column(col string) *DropColumnStmt
Column 指定需要删除的列 重复指定,会覆盖之前的。
func (*DropColumnStmt) DDLSQL ¶
func (stmt *DropColumnStmt) DDLSQL() ([]string, error)
DDLSQL 获取 SQL 语句以及对应的参数
func (DropColumnStmt) ExecContext ¶
func (*DropColumnStmt) Table ¶
func (stmt *DropColumnStmt) Table(table string) *DropColumnStmt
Table 指定表名。 重复指定,会覆盖之前的。
type DropColumnStmtHooker ¶
type DropColumnStmtHooker interface {
DropColumnStmtHook(*DropColumnStmt) ([]string, error)
}
DropColumnStmtHooker DropColumnStmt.DDLSQL 的钩子函数
type DropConstraintStmt ¶
type DropConstraintStmt struct { TableName string Name string IsPK bool // contains filtered or unexported fields }
DropConstraintStmt 删除约束
func DropConstraint ¶
func DropConstraint(e core.Engine) *DropConstraintStmt
DropConstraint 声明一条删除表约束的语句
func (*DropConstraintStmt) Constraint ¶
func (stmt *DropConstraintStmt) Constraint(name string) *DropConstraintStmt
Constraint 指定需要删除的约束名
NOTE: 如果需要删除主键,请使用 core.PKName 产生主键名称 如果你的主键名称不是根据 core.PKName() 生成的,那么在删除时,还需要调用 PK 方法。
func (*DropConstraintStmt) DDLSQL ¶
func (stmt *DropConstraintStmt) DDLSQL() ([]string, error)
DDLSQL 获取 SQL 语句以及对应的参数
func (DropConstraintStmt) ExecContext ¶
func (*DropConstraintStmt) PK ¶
func (stmt *DropConstraintStmt) PK() *DropConstraintStmt
PK 当前删除的是否为主键
func (*DropConstraintStmt) Reset ¶
func (stmt *DropConstraintStmt) Reset() *DropConstraintStmt
Reset 重置
func (*DropConstraintStmt) Table ¶
func (stmt *DropConstraintStmt) Table(table string) *DropConstraintStmt
Table 指定表名
重复指定,会覆盖之前的。
type DropConstraintStmtHooker ¶
type DropConstraintStmtHooker interface {
DropConstraintStmtHook(*DropConstraintStmt) ([]string, error)
}
DropConstraintStmtHooker DropConstraintStmt.DDLSQL 的钩子函数
type DropIndexStmt ¶
type DropIndexStmt struct { TableName string IndexName string // contains filtered or unexported fields }
DropIndexStmt 删除索引
func (*DropIndexStmt) DDLSQL ¶
func (stmt *DropIndexStmt) DDLSQL() ([]string, error)
DDLSQL 生成 SQL 语句
func (DropIndexStmt) ExecContext ¶
func (*DropIndexStmt) Table ¶
func (stmt *DropIndexStmt) Table(tbl string) *DropIndexStmt
Table 指定表名
type DropIndexStmtHooker ¶
type DropIndexStmtHooker interface {
DropIndexStmtHook(*DropIndexStmt) ([]string, error)
}
DropIndexStmtHooker DropIndexStmt.DDLSQL 的勾子函数
type DropTableStmt ¶
type DropTableStmt struct {
// contains filtered or unexported fields
}
DropTableStmt 删除表语句
func (*DropTableStmt) DDLSQL ¶
func (stmt *DropTableStmt) DDLSQL() ([]string, error)
DDLSQL 获取 SQL 语句以及对应的参数
func (DropTableStmt) ExecContext ¶
func (*DropTableStmt) Table ¶
func (stmt *DropTableStmt) Table(table ...string) *DropTableStmt
Table 指定表名。
多次指定,则会删除多个表
type DropViewStmt ¶
type DropViewStmt struct {
// contains filtered or unexported fields
}
DropViewStmt 删除视图
func (*DropViewStmt) DDLSQL ¶
func (stmt *DropViewStmt) DDLSQL() ([]string, error)
DDLSQL 返回删除视图的 SQL 语句
func (DropViewStmt) ExecContext ¶
func (*DropViewStmt) Name ¶
func (stmt *DropViewStmt) Name(name string) *DropViewStmt
Name 指定需要删除的视图名称
type InsertDefaultValueHooker ¶
type InsertDefaultValueHooker interface {
InsertDefaultValueHook(tableName string) (string, []interface{}, error)
}
InsertDefaultValueHooker 插入值全部为默认值时的钩子处理函数
type InsertStmt ¶
type InsertStmt struct {
// contains filtered or unexported fields
}
InsertStmt 表示插入操作的 SQL 语句
func (*InsertStmt) Columns ¶
func (stmt *InsertStmt) Columns(cols ...string) *InsertStmt
Columns 指定插入的列,多次指定,之前的会被覆盖。
func (InsertStmt) CombineSQL ¶
CombineSQL 将 SQLer.SQL 中返回的参数替换掉 query 中的占位符, 形成一条完整的查询语句。
func (InsertStmt) ExecContext ¶
func (*InsertStmt) KeyValue ¶
func (stmt *InsertStmt) KeyValue(col string, val interface{}) *InsertStmt
KeyValue 指定键值对
当通过 Values() 指定多行数据时,再使用 KeyValue 会出错
func (*InsertStmt) LastInsertID ¶
func (stmt *InsertStmt) LastInsertID(table, col string) (int64, error)
LastInsertID 执行 SQL 语句
并根据表名和自增列 ID 返回当前行的自增 ID 值。
NOTE: 对于指定了自增值的,其结果是未知的。
func (*InsertStmt) LastInsertIDContext ¶
func (stmt *InsertStmt) LastInsertIDContext(ctx context.Context, table, col string) (id int64, err error)
LastInsertIDContext 执行 SQL 语句
并根据表名和自增列 ID 返回当前行的自增 ID 值。
func (InsertStmt) Prepare ¶
Prepare 预编译语句
预编译语句,参数最好采用 sql.NamedArg 类型。 在生成语句时,参数顺序会发生变化,如果采用 ? 的形式, 用户需要自己处理参数顺序问题,而 sql.NamedArg 没有这些问题。
func (InsertStmt) PrepareContext ¶
func (*InsertStmt) SQL ¶
func (stmt *InsertStmt) SQL() (string, []interface{}, error)
SQL 获取 SQL 的语句及参数部分
func (*InsertStmt) Select ¶
func (stmt *InsertStmt) Select(sel *SelectStmt) *InsertStmt
Select 当前插入数据从 Select 中获取
构建 insert into (...) select .... 语句
func (*InsertStmt) Values ¶
func (stmt *InsertStmt) Values(vals ...interface{}) *InsertStmt
Values 指定需要插入的值
NOTE: vals 传入时,并不会被解压
type SQLBuilder ¶
type SQLBuilder struct {
// contains filtered or unexported fields
}
SQLBuilder 提供了 sqlbuilder 下的各类语句的创建方法。
func (*SQLBuilder) AddColumn ¶
func (sql *SQLBuilder) AddColumn() *AddColumnStmt
AddColumn 声明一条添加列的语句
func (*SQLBuilder) AddConstraint ¶
func (sql *SQLBuilder) AddConstraint() *AddConstraintStmt
AddConstraint 声明添加约束的语句
func (*SQLBuilder) CreateIndex ¶
func (sql *SQLBuilder) CreateIndex() *CreateIndexStmt
CreateIndex 生成创建索引的语句
func (*SQLBuilder) CreateTable ¶
func (sql *SQLBuilder) CreateTable() *CreateTableStmt
CreateTable 生成创建表的语句
func (*SQLBuilder) DropColumn ¶
func (sql *SQLBuilder) DropColumn() *DropColumnStmt
DropColumn 声明一条删除列的语句
func (*SQLBuilder) DropConstraint ¶
func (sql *SQLBuilder) DropConstraint() *DropConstraintStmt
DropConstraint 声明一条删除表约束的语句
func (*SQLBuilder) DropIndex ¶
func (sql *SQLBuilder) DropIndex() *DropIndexStmt
DropIndex 生成删除索引的语句
func (*SQLBuilder) TruncateTable ¶
func (sql *SQLBuilder) TruncateTable() *TruncateTableStmt
TruncateTable 生成清空表的语句,同时重置 AI 计算
type SQLer ¶
type SQLer interface { // 将当前实例转换成 SQL 语句返回 // // query 表示 SQL 语句,而 args 表示语句各个参数占位符对应的参数值。 SQL() (query string, args []interface{}, err error) }
SQLer 定义 SQL 语句的基本接口
type SelectStmt ¶
type SelectStmt struct {
// contains filtered or unexported fields
}
SelectStmt 查询语句
func (*SelectStmt) And ¶
func (stmt *SelectStmt) And(cond string, args ...interface{}) *SelectStmt
And 添加一条 and 语句
func (*SelectStmt) AndBetween ¶
func (stmt *SelectStmt) AndBetween(col string, v1, v2 interface{}) *SelectStmt
AndBetween 指定 WHERE ... AND col BETWEEN v1 AND v2
func (*SelectStmt) AndIn ¶
func (stmt *SelectStmt) AndIn(col string, v ...interface{}) *SelectStmt
AndIn 指定 WHERE ... AND col IN(v...)
func (*SelectStmt) AndIsNotNull ¶
func (stmt *SelectStmt) AndIsNotNull(col string) *SelectStmt
AndIsNotNull 指定 WHERE ... AND col IS NOT NULL
func (*SelectStmt) AndIsNull ¶
func (stmt *SelectStmt) AndIsNull(col string) *SelectStmt
AndIsNull 指定 WHERE ... AND col IS NULL
func (*SelectStmt) AndLike ¶
func (stmt *SelectStmt) AndLike(col string, content interface{}) *SelectStmt
AndLike 指定 WHERE ... AND col LIKE content
func (*SelectStmt) AndNotBetween ¶
func (stmt *SelectStmt) AndNotBetween(col string, v1, v2 interface{}) *SelectStmt
AndNotBetween 指定 WHERE ... AND col NOT BETWEEN v1 AND v2
func (*SelectStmt) AndNotIn ¶
func (stmt *SelectStmt) AndNotIn(col string, v ...interface{}) *SelectStmt
AndNotIn 指定 WHERE ... AND col NOT IN(v...)
func (*SelectStmt) AndNotLike ¶
func (stmt *SelectStmt) AndNotLike(col string, content interface{}) *SelectStmt
AndNotLike 指定 WHERE ... AND col NOT LIKE content
func (*SelectStmt) Asc ¶
func (stmt *SelectStmt) Asc(col ...string) *SelectStmt
Asc 正序查询
col 为分组的列名,格式可以单纯的列名,或是带表名的列:
col table.col
table 和 col 都可以是关键字,系统会自动处理。
func (*SelectStmt) Column ¶
func (stmt *SelectStmt) Column(col string) *SelectStmt
Column 指定列,一次只能指定一列。
col 表示列名,可以是以下形式:
* col table.col table.* sum({table}.{col}) as col1
如果列名是关键字,可以使用 {} 包含。
func (*SelectStmt) Columns ¶
func (stmt *SelectStmt) Columns(cols ...string) *SelectStmt
Columns 指定列名,可以指定多列。
相当于按参数顺序依次调用 Select.Column,如果存在别名, 可以使用 col AS alias 的方式指定每一个参数。
如果列名是关键字,可以使用 {} 包含。
func (SelectStmt) CombineSQL ¶
CombineSQL 将 SQLer.SQL 中返回的参数替换掉 query 中的占位符, 形成一条完整的查询语句。
func (*SelectStmt) Count ¶
func (stmt *SelectStmt) Count(expr string) *SelectStmt
Count 指定 Count 表达式,如果指定了 count 表达式,则会造成 limit 失效。
如果设置为空值,则取消 count,恢复普通的 select
func (*SelectStmt) Desc ¶
func (stmt *SelectStmt) Desc(col ...string) *SelectStmt
Desc 倒序查询
col 为分组的列名,格式可以单纯的列名,或是带表名的列:
col table.col
table 和 col 都可以是关键字,系统会自动处理。
func (*SelectStmt) Distinct ¶
func (stmt *SelectStmt) Distinct() *SelectStmt
Distinct 声明一条 Select 语句的 Distinct
若指定了此值,则 Select() 所指定的列,均为 Distinct 之后的列。
func (*SelectStmt) ForUpdate ¶
func (stmt *SelectStmt) ForUpdate() *SelectStmt
ForUpdate 添加 FOR UPDATE 语句部分
func (*SelectStmt) From ¶
func (stmt *SelectStmt) From(table string, alias ...string) *SelectStmt
From 指定表名
table 为表名,如果需要指定别名,可以通过 alias 指定。
func (*SelectStmt) Group ¶
func (stmt *SelectStmt) Group(col string) *SelectStmt
Group 添加 GROUP BY 语句
col 为分组的列名,格式可以单纯的列名,或是带表名的列:
col table.col
table 和 col 都可以是关键字,系统会自动处理。
func (*SelectStmt) Having ¶
func (stmt *SelectStmt) Having(expr string, args ...interface{}) *SelectStmt
Having 指定 having 语句
func (*SelectStmt) Insert ¶
func (stmt *SelectStmt) Insert() *InsertStmt
Insert 将当前查询结果作为 Insert 的值
构建 insert into (...) select .... 语句
func (*SelectStmt) Join ¶
func (stmt *SelectStmt) Join(typ, table, alias, on string) *SelectStmt
Join 添加一条 Join 语句
func (*SelectStmt) Limit ¶
func (stmt *SelectStmt) Limit(limit interface{}, offset ...interface{}) *SelectStmt
Limit 生成 SQL 的 Limit 语句
func (*SelectStmt) Or ¶
func (stmt *SelectStmt) Or(cond string, args ...interface{}) *SelectStmt
Or 添加一条 OR 语句
func (*SelectStmt) OrBetween ¶
func (stmt *SelectStmt) OrBetween(col string, v1, v2 interface{}) *SelectStmt
OrBetween 指定 WHERE ... OR col BETWEEN v1 AND v2
func (*SelectStmt) OrIn ¶
func (stmt *SelectStmt) OrIn(col string, v ...interface{}) *SelectStmt
OrIn 指定 WHERE ... OR col IN(v...)
func (*SelectStmt) OrIsNotNull ¶
func (stmt *SelectStmt) OrIsNotNull(col string) *SelectStmt
OrIsNotNull 指定 WHERE ... OR col IS NOT NULL
func (*SelectStmt) OrIsNull ¶
func (stmt *SelectStmt) OrIsNull(col string) *SelectStmt
OrIsNull 指定 WHERE ... OR col IS NULL
func (*SelectStmt) OrLike ¶
func (stmt *SelectStmt) OrLike(col string, content interface{}) *SelectStmt
OrLike 指定 WHERE ... OR col LIKE content
func (*SelectStmt) OrNotBetween ¶
func (stmt *SelectStmt) OrNotBetween(col string, v1, v2 interface{}) *SelectStmt
OrNotBetween 指定 WHERE ... OR col BETWEEN v1 AND v2
func (*SelectStmt) OrNotIn ¶
func (stmt *SelectStmt) OrNotIn(col string, v ...interface{}) *SelectStmt
OrNotIn 指定 WHERE ... OR col IN(v...)
func (*SelectStmt) OrNotLike ¶
func (stmt *SelectStmt) OrNotLike(col string, content interface{}) *SelectStmt
OrNotLike 指定 WHERE ... OR col NOT LIKE content
func (SelectStmt) PrepareContext ¶
func (SelectStmt) QueryContext ¶
func (*SelectStmt) QueryFloat ¶
func (stmt *SelectStmt) QueryFloat(colName string) (float64, error)
QueryFloat 查询指定列的第一行数据,并将其转换成 float64
func (*SelectStmt) QueryInt ¶
func (stmt *SelectStmt) QueryInt(colName string) (int64, error)
QueryInt 查询指定列的第一行数据,并将其转换成 int64
func (*SelectStmt) QueryObject ¶
func (stmt *SelectStmt) QueryObject(strict bool, objs interface{}) (size int, err error)
QueryObject 将符合当前条件的所有记录依次写入 objs 中。
关于 objs 的值类型,可以参考 github.com/issue9/orm/fetch.Object 函数的相关介绍。
func (*SelectStmt) QueryString ¶
func (stmt *SelectStmt) QueryString(colName string) (v string, err error)
QueryString 查询指定列的第一行数据,并将其转换成 string
func (*SelectStmt) SQL ¶
func (stmt *SelectStmt) SQL() (string, []interface{}, error)
SQL 获取 SQL 语句及对应的参数
func (*SelectStmt) Union ¶
func (stmt *SelectStmt) Union(all bool, sel ...*SelectStmt) *SelectStmt
Union 语句
all 表示是否执行 Union all 语法; sel 表示需要进行并接的 Select 语句,传入 sel 之后, 后续对 sel 的操作依赖会影响到语句的最终生成。
func (*SelectStmt) View ¶
func (stmt *SelectStmt) View(name string) *CreateViewStmt
View 将当前查询语句转换为视图
func (*SelectStmt) Where ¶
func (stmt *SelectStmt) Where(cond string, args ...interface{}) *SelectStmt
Where SelectStmt.And 的别名
func (*SelectStmt) WhereStmt ¶
func (stmt *SelectStmt) WhereStmt() *WhereStmt
WhereStmt 实现 WhereStmter 接口
type TruncateTableStmt ¶
type TruncateTableStmt struct { TableName string AIColumnName string // contains filtered or unexported fields }
TruncateTableStmt 清空表,并重置 AI
func (*TruncateTableStmt) DDLSQL ¶
func (stmt *TruncateTableStmt) DDLSQL() ([]string, error)
DDLSQL 获取 SQL 的语句及参数部分
func (TruncateTableStmt) ExecContext ¶
func (*TruncateTableStmt) Reset ¶
func (stmt *TruncateTableStmt) Reset() *TruncateTableStmt
Reset 重置内容
func (*TruncateTableStmt) Table ¶
func (stmt *TruncateTableStmt) Table(t, aiColumn string) *TruncateTableStmt
Table 指定表名
aiColumn 表示自增列;
type TruncateTableStmtHooker ¶
type TruncateTableStmtHooker interface {
TruncateTableStmtHook(*TruncateTableStmt) ([]string, error)
}
TruncateTableStmtHooker TruncateTableStmt.DDLSQL 的钩子函数
type UpdateStmt ¶
type UpdateStmt struct {
// contains filtered or unexported fields
}
UpdateStmt 更新语句
func (*UpdateStmt) And ¶
func (stmt *UpdateStmt) And(cond string, args ...interface{}) *UpdateStmt
And 添加一条 and 语句
func (*UpdateStmt) AndBetween ¶
func (stmt *UpdateStmt) AndBetween(col string, v1, v2 interface{}) *UpdateStmt
AndBetween 指定 WHERE ... AND col BETWEEN v1 AND v2
func (*UpdateStmt) AndIn ¶
func (stmt *UpdateStmt) AndIn(col string, v ...interface{}) *UpdateStmt
AndIn 指定 WHERE ... AND col IN(v...)
func (*UpdateStmt) AndIsNotNull ¶
func (stmt *UpdateStmt) AndIsNotNull(col string) *UpdateStmt
AndIsNotNull 指定 WHERE ... AND col IS NOT NULL
func (*UpdateStmt) AndIsNull ¶
func (stmt *UpdateStmt) AndIsNull(col string) *UpdateStmt
AndIsNull 指定 WHERE ... AND col IS NULL
func (*UpdateStmt) AndLike ¶
func (stmt *UpdateStmt) AndLike(col string, content interface{}) *UpdateStmt
AndLike 指定 WHERE ... AND col LIKE content
func (*UpdateStmt) AndNotBetween ¶
func (stmt *UpdateStmt) AndNotBetween(col string, v1, v2 interface{}) *UpdateStmt
AndNotBetween 指定 WHERE ... AND col NOT BETWEEN v1 AND v2
func (*UpdateStmt) AndNotIn ¶
func (stmt *UpdateStmt) AndNotIn(col string, v ...interface{}) *UpdateStmt
AndNotIn 指定 WHERE ... AND col NOT IN(v...)
func (*UpdateStmt) AndNotLike ¶
func (stmt *UpdateStmt) AndNotLike(col string, content interface{}) *UpdateStmt
AndNotLike 指定 WHERE ... AND col NOT LIKE content
func (UpdateStmt) CombineSQL ¶
CombineSQL 将 SQLer.SQL 中返回的参数替换掉 query 中的占位符, 形成一条完整的查询语句。
func (*UpdateStmt) Decrease ¶
func (stmt *UpdateStmt) Decrease(col string, val interface{}) *UpdateStmt
Decrease 给钱减少值
func (UpdateStmt) ExecContext ¶
func (*UpdateStmt) Increase ¶
func (stmt *UpdateStmt) Increase(col string, val interface{}) *UpdateStmt
Increase 给列增加值
func (*UpdateStmt) OCC ¶
func (stmt *UpdateStmt) OCC(col string, val interface{}) *UpdateStmt
OCC 指定一个用于乐观锁的字段
val 表示乐观锁原始的值,更新时如果值不等于 val,将更新失败。
func (*UpdateStmt) Or ¶
func (stmt *UpdateStmt) Or(cond string, args ...interface{}) *UpdateStmt
Or 添加一条 OR 语句
func (*UpdateStmt) OrBetween ¶
func (stmt *UpdateStmt) OrBetween(col string, v1, v2 interface{}) *UpdateStmt
OrBetween 指定 WHERE ... OR col BETWEEN v1 AND v2
func (*UpdateStmt) OrIn ¶
func (stmt *UpdateStmt) OrIn(col string, v ...interface{}) *UpdateStmt
OrIn 指定 WHERE ... OR col IN(v...)
func (*UpdateStmt) OrIsNotNull ¶
func (stmt *UpdateStmt) OrIsNotNull(col string) *UpdateStmt
OrIsNotNull 指定 WHERE ... OR col IS NOT NULL
func (*UpdateStmt) OrIsNull ¶
func (stmt *UpdateStmt) OrIsNull(col string) *UpdateStmt
OrIsNull 指定 WHERE ... OR col IS NULL
func (*UpdateStmt) OrLike ¶
func (stmt *UpdateStmt) OrLike(col string, content interface{}) *UpdateStmt
OrLike 指定 WHERE ... OR col LIKE content
func (*UpdateStmt) OrNotBetween ¶
func (stmt *UpdateStmt) OrNotBetween(col string, v1, v2 interface{}) *UpdateStmt
OrNotBetween 指定 WHERE ... OR col BETWEEN v1 AND v2
func (*UpdateStmt) OrNotIn ¶
func (stmt *UpdateStmt) OrNotIn(col string, v ...interface{}) *UpdateStmt
OrNotIn 指定 WHERE ... OR col IN(v...)
func (*UpdateStmt) OrNotLike ¶
func (stmt *UpdateStmt) OrNotLike(col string, content interface{}) *UpdateStmt
OrNotLike 指定 WHERE ... OR col NOT LIKE content
func (UpdateStmt) Prepare ¶
Prepare 预编译语句
预编译语句,参数最好采用 sql.NamedArg 类型。 在生成语句时,参数顺序会发生变化,如果采用 ? 的形式, 用户需要自己处理参数顺序问题,而 sql.NamedArg 没有这些问题。
func (UpdateStmt) PrepareContext ¶
func (*UpdateStmt) SQL ¶
func (stmt *UpdateStmt) SQL() (string, []interface{}, error)
SQL 获取 SQL 语句以及对应的参数
func (*UpdateStmt) Set ¶
func (stmt *UpdateStmt) Set(col string, val interface{}) *UpdateStmt
Set 设置值,若 col 相同,则会覆盖
val 可以是 sql.NamedArg 类型
func (*UpdateStmt) Where ¶
func (stmt *UpdateStmt) Where(cond string, args ...interface{}) *UpdateStmt
Where UpdateStmt.And 的别名
func (*UpdateStmt) WhereStmt ¶
func (stmt *UpdateStmt) WhereStmt() *WhereStmt
WhereStmt 实现 WhereStmter 接口
type WhereStmt ¶
type WhereStmt struct {
// contains filtered or unexported fields
}
WhereStmt SQL 语句的 where 部分
func (*WhereStmt) AndBetween ¶
AndBetween 指定 WHERE ... AND col BETWEEN v1 AND v2
func (*WhereStmt) AndIsNotNull ¶
AndIsNotNull 指定 WHERE ... AND col IS NOT NULL
func (*WhereStmt) AndNotBetween ¶
AndNotBetween 指定 WHERE ... AND col NOT BETWEEN v1 AND v2
func (*WhereStmt) AndNotLike ¶
AndNotLike 指定 WHERE ... AND col NOT LIKE content
func (*WhereStmt) Delete ¶
func (stmt *WhereStmt) Delete(e core.Engine) *DeleteStmt
Delete 删除指定条件的内容
func (*WhereStmt) OrIsNotNull ¶
OrIsNotNull 指定 WHERE ... OR col IS NOT NULL
func (*WhereStmt) OrNotBetween ¶
OrNotBetween 指定 WHERE ... OR col BETWEEN v1 AND v2
type WhereStmter ¶
type WhereStmter interface {
WhereStmt() *WhereStmt
}
WhereStmter 带 Where 语句的 SQL