sqlbuilder

package
v3.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sqlbuilder 提供一套通过字符串拼接来构成 SQL 语句的工具

sqlbuilder 提供了部分 *Hooker 的接口,用于自定义某一条语句的实现。 一般情况下, 如果有多个数据是遵循 SQL 标准的,只有个别有例外, 那么该例外的 Dialect 实现,可以同时实现 Hooker 接口, 自定义该语句的实现。

Index

Constants

This section is empty.

Variables

View Source
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 列长度不相同")
)
View Source
var ErrNoData = errors.New("不存在符合和条件的数据")

ErrNoData 在 Select.QueryInt 等函数中, 如果没有符合条件的数据,则返回此错误。

Functions

func Version

func Version(e core.Engine) (version string, err error)

Version 查询数据库服务器的版本信息

Types

type AddColumnStmt

type AddColumnStmt struct {
	// contains filtered or unexported fields
}

AddColumnStmt 添加列

func AddColumn

func AddColumn(e core.Engine) *AddColumnStmt

AddColumn 声明一条添加列的语句

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) Exec

func (stmt AddColumnStmt) Exec() error

func (AddColumnStmt) ExecContext

func (stmt AddColumnStmt) ExecContext(ctx context.Context) error

func (*AddColumnStmt) Reset

func (stmt *AddColumnStmt) Reset() *AddColumnStmt

Reset 重置

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 AddConstraint

func AddConstraint(e core.Engine) *AddConstraintStmt

AddConstraint 声明添加约束的语句

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) Exec

func (stmt AddConstraintStmt) Exec() error

func (AddConstraintStmt) ExecContext

func (stmt AddConstraintStmt) ExecContext(ctx context.Context) error

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) Exec

func (stmt CreateIndexStmt) Exec() error

func (CreateIndexStmt) ExecContext

func (stmt CreateIndexStmt) ExecContext(ctx context.Context) error

func (*CreateIndexStmt) Name

func (stmt *CreateIndexStmt) Name(index string) *CreateIndexStmt

Name 指定索引名

func (*CreateIndexStmt) Reset

func (stmt *CreateIndexStmt) Reset() *CreateIndexStmt

Reset 重置

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) Exec

func (stmt CreateTableStmt) Exec() error

func (CreateTableStmt) ExecContext

func (stmt CreateTableStmt) ExecContext(ctx context.Context) error

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) Reset

func (stmt *CreateTableStmt) Reset() *CreateTableStmt

Reset 重置内容

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 CreateView

func CreateView(e core.Engine) *CreateViewStmt

CreateView 创建视图

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) Exec

func (stmt CreateViewStmt) Exec() error

func (CreateViewStmt) ExecContext

func (stmt CreateViewStmt) ExecContext(ctx context.Context) error

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) Reset

func (stmt *CreateViewStmt) Reset() *CreateViewStmt

Reset 重置对象

func (*CreateViewStmt) Temporary

func (stmt *CreateViewStmt) Temporary() *CreateViewStmt

Temporary 临时视图

type CreateViewStmtHooker

type CreateViewStmtHooker interface {
	CreateViewStmtHook(*CreateViewStmt) ([]string, error)
}

CreateViewStmtHooker CreateViewStmt.DDLSQL 的钩子函数

type DDLSQLer

type DDLSQLer interface {
	DDLSQL() ([]string, error)
}

DDLSQLer SQL 中 DDL 语句的基本接口

大部分数据的 DDL 操作是有多条语句组成,比如 CREATE TABLE 可能包含了额外的定义信息。

type DeleteStmt

type DeleteStmt struct {
	// contains filtered or unexported fields
}

DeleteStmt 表示删除操作的 SQL 语句

func Delete

func Delete(e core.Engine) *DeleteStmt

Delete 声明一条删除语句

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) AndGroup

func (stmt *DeleteStmt) AndGroup() *WhereStmt

AndGroup 开始一个子条件语句

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

func (stmt DeleteStmt) CombineSQL() (query string, err error)

CombineSQL 将 SQLer.SQL 中返回的参数替换掉 query 中的占位符, 形成一条完整的查询语句。

func (DeleteStmt) Exec

func (stmt DeleteStmt) Exec() (sql.Result, error)

func (DeleteStmt) ExecContext

func (stmt DeleteStmt) ExecContext(ctx context.Context) (sql.Result, error)

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) OrGroup

func (stmt *DeleteStmt) OrGroup() *WhereStmt

OrGroup 开始一个子条件语句

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

func (stmt DeleteStmt) Prepare() (*core.Stmt, error)

Prepare 预编译语句

预编译语句,参数最好采用 sql.NamedArg 类型。 在生成语句时,参数顺序会发生变化,如果采用 ? 的形式, 用户需要自己处理参数顺序问题,而 sql.NamedArg 没有这些问题。

func (DeleteStmt) PrepareContext

func (stmt DeleteStmt) PrepareContext(ctx context.Context) (*core.Stmt, error)

func (*DeleteStmt) Reset

func (stmt *DeleteStmt) Reset() *DeleteStmt

Reset 重置语句

func (*DeleteStmt) SQL

func (stmt *DeleteStmt) SQL() (string, []interface{}, error)

SQL 获取 SQL 语句,以及其参数对应的具体值

func (*DeleteStmt) Table

func (stmt *DeleteStmt) Table(table string) *DeleteStmt

Table 指定表名

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 DropColumn

func DropColumn(e core.Engine) *DropColumnStmt

DropColumn 声明一条删除列的语句

func (*DropColumnStmt) Column

func (stmt *DropColumnStmt) Column(col string) *DropColumnStmt

Column 指定需要删除的列 重复指定,会覆盖之前的。

func (*DropColumnStmt) DDLSQL

func (stmt *DropColumnStmt) DDLSQL() ([]string, error)

DDLSQL 获取 SQL 语句以及对应的参数

func (DropColumnStmt) Exec

func (stmt DropColumnStmt) Exec() error

func (DropColumnStmt) ExecContext

func (stmt DropColumnStmt) ExecContext(ctx context.Context) error

func (*DropColumnStmt) Reset

func (stmt *DropColumnStmt) Reset() *DropColumnStmt

Reset 重置

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) Exec

func (stmt DropConstraintStmt) Exec() error

func (DropConstraintStmt) ExecContext

func (stmt DropConstraintStmt) ExecContext(ctx context.Context) error

func (*DropConstraintStmt) PK

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 DropIndex

func DropIndex(e core.Engine) *DropIndexStmt

DropIndex 声明一条 DropIndexStmt 语句

func (*DropIndexStmt) DDLSQL

func (stmt *DropIndexStmt) DDLSQL() ([]string, error)

DDLSQL 生成 SQL 语句

func (DropIndexStmt) Exec

func (stmt DropIndexStmt) Exec() error

func (DropIndexStmt) ExecContext

func (stmt DropIndexStmt) ExecContext(ctx context.Context) error

func (*DropIndexStmt) Name

func (stmt *DropIndexStmt) Name(col string) *DropIndexStmt

Name 指定索引名

func (*DropIndexStmt) Reset

func (stmt *DropIndexStmt) Reset() *DropIndexStmt

Reset 重置

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 DropTable

func DropTable(e core.Engine) *DropTableStmt

DropTable 声明一条删除表的语句

func (*DropTableStmt) DDLSQL

func (stmt *DropTableStmt) DDLSQL() ([]string, error)

DDLSQL 获取 SQL 语句以及对应的参数

func (DropTableStmt) Exec

func (stmt DropTableStmt) Exec() error

func (DropTableStmt) ExecContext

func (stmt DropTableStmt) ExecContext(ctx context.Context) error

func (*DropTableStmt) Reset

func (stmt *DropTableStmt) Reset() *DropTableStmt

Reset 重置

func (*DropTableStmt) Table

func (stmt *DropTableStmt) Table(table ...string) *DropTableStmt

Table 指定表名。

多次指定,则会删除多个表

type DropViewStmt

type DropViewStmt struct {
	// contains filtered or unexported fields
}

DropViewStmt 删除视图

func DropView

func DropView(e core.Engine) *DropViewStmt

DropView 创建视图

func (*DropViewStmt) DDLSQL

func (stmt *DropViewStmt) DDLSQL() ([]string, error)

DDLSQL 返回删除视图的 SQL 语句

func (DropViewStmt) Exec

func (stmt DropViewStmt) Exec() error

func (DropViewStmt) ExecContext

func (stmt DropViewStmt) ExecContext(ctx context.Context) error

func (*DropViewStmt) Name

func (stmt *DropViewStmt) Name(name string) *DropViewStmt

Name 指定需要删除的视图名称

func (*DropViewStmt) Reset

func (stmt *DropViewStmt) Reset() *DropViewStmt

Reset 重置对象

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 Insert

func Insert(e core.Engine) *InsertStmt

Insert 声明一条插入语句

func (*InsertStmt) Columns

func (stmt *InsertStmt) Columns(cols ...string) *InsertStmt

Columns 指定插入的列,多次指定,之前的会被覆盖。

func (InsertStmt) CombineSQL

func (stmt InsertStmt) CombineSQL() (query string, err error)

CombineSQL 将 SQLer.SQL 中返回的参数替换掉 query 中的占位符, 形成一条完整的查询语句。

func (InsertStmt) Exec

func (stmt InsertStmt) Exec() (sql.Result, error)

func (InsertStmt) ExecContext

func (stmt InsertStmt) ExecContext(ctx context.Context) (sql.Result, error)

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

func (stmt InsertStmt) Prepare() (*core.Stmt, error)

Prepare 预编译语句

预编译语句,参数最好采用 sql.NamedArg 类型。 在生成语句时,参数顺序会发生变化,如果采用 ? 的形式, 用户需要自己处理参数顺序问题,而 sql.NamedArg 没有这些问题。

func (InsertStmt) PrepareContext

func (stmt InsertStmt) PrepareContext(ctx context.Context) (*core.Stmt, error)

func (*InsertStmt) Reset

func (stmt *InsertStmt) Reset() *InsertStmt

Reset 重置语句

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) Table

func (stmt *InsertStmt) Table(table string) *InsertStmt

Table 指定表名

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 New

func New(e core.Engine) *SQLBuilder

New 声明 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) CreateView

func (sql *SQLBuilder) CreateView() *CreateViewStmt

CreateView 创建视图

func (*SQLBuilder) Delete

func (sql *SQLBuilder) Delete() *DeleteStmt

Delete 生成删除语句

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) DropTable

func (sql *SQLBuilder) DropTable() *DropTableStmt

DropTable 生成删除表的语句

func (*SQLBuilder) Insert

func (sql *SQLBuilder) Insert() *InsertStmt

Insert 生成插入语句

func (*SQLBuilder) Select

func (sql *SQLBuilder) Select() *SelectStmt

Select 生成插入语句

func (*SQLBuilder) TruncateTable

func (sql *SQLBuilder) TruncateTable() *TruncateTableStmt

TruncateTable 生成清空表的语句,同时重置 AI 计算

func (*SQLBuilder) Update

func (sql *SQLBuilder) Update() *UpdateStmt

Update 生成更新语句

func (*SQLBuilder) Where

func (sql *SQLBuilder) Where() *WhereStmt

Where 生成 Where 语句

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 Select

func Select(e core.Engine) *SelectStmt

Select 声明一条 Select 语句

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) AndGroup

func (stmt *SelectStmt) AndGroup() *WhereStmt

AndGroup 开始一个子条件语句

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

func (stmt SelectStmt) CombineSQL() (query string, err error)

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) OrGroup

func (stmt *SelectStmt) OrGroup() *WhereStmt

OrGroup 开始一个子条件语句

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) Prepare

func (stmt SelectStmt) Prepare() (*core.Stmt, error)

func (SelectStmt) PrepareContext

func (stmt SelectStmt) PrepareContext(ctx context.Context) (*core.Stmt, error)

func (SelectStmt) Query

func (stmt SelectStmt) Query() (*sql.Rows, error)

func (SelectStmt) QueryContext

func (stmt SelectStmt) QueryContext(ctx context.Context) (*sql.Rows, error)

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) Reset

func (stmt *SelectStmt) Reset() *SelectStmt

Reset 重置语句

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 TruncateTable

func TruncateTable(e core.Engine) *TruncateTableStmt

TruncateTable 生成清空表语句

func (*TruncateTableStmt) DDLSQL

func (stmt *TruncateTableStmt) DDLSQL() ([]string, error)

DDLSQL 获取 SQL 的语句及参数部分

func (TruncateTableStmt) Exec

func (stmt TruncateTableStmt) Exec() error

func (TruncateTableStmt) ExecContext

func (stmt TruncateTableStmt) ExecContext(ctx context.Context) error

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 Update

func Update(e core.Engine) *UpdateStmt

Update 声明一条 UPDATE 的 SQL 语句

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) AndGroup

func (stmt *UpdateStmt) AndGroup() *WhereStmt

AndGroup 开始一个子条件语句

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

func (stmt UpdateStmt) CombineSQL() (query string, err error)

CombineSQL 将 SQLer.SQL 中返回的参数替换掉 query 中的占位符, 形成一条完整的查询语句。

func (*UpdateStmt) Decrease

func (stmt *UpdateStmt) Decrease(col string, val interface{}) *UpdateStmt

Decrease 给钱减少值

func (UpdateStmt) Exec

func (stmt UpdateStmt) Exec() (sql.Result, error)

func (UpdateStmt) ExecContext

func (stmt UpdateStmt) ExecContext(ctx context.Context) (sql.Result, error)

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) OrGroup

func (stmt *UpdateStmt) OrGroup() *WhereStmt

OrGroup 开始一个子条件语句

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

func (stmt UpdateStmt) Prepare() (*core.Stmt, error)

Prepare 预编译语句

预编译语句,参数最好采用 sql.NamedArg 类型。 在生成语句时,参数顺序会发生变化,如果采用 ? 的形式, 用户需要自己处理参数顺序问题,而 sql.NamedArg 没有这些问题。

func (UpdateStmt) PrepareContext

func (stmt UpdateStmt) PrepareContext(ctx context.Context) (*core.Stmt, error)

func (*UpdateStmt) Reset

func (stmt *UpdateStmt) Reset() *UpdateStmt

Reset 重置语句

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) Table

func (stmt *UpdateStmt) Table(table string) *UpdateStmt

Table 指定表名

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 Where

func Where() *WhereStmt

Where 生成 Where 语句

func (*WhereStmt) And

func (stmt *WhereStmt) And(cond string, args ...interface{}) *WhereStmt

And 添加一条 and 语句

func (*WhereStmt) AndBetween

func (stmt *WhereStmt) AndBetween(col string, v1, v2 interface{}) *WhereStmt

AndBetween 指定 WHERE ... AND col BETWEEN v1 AND v2

func (*WhereStmt) AndGroup

func (stmt *WhereStmt) AndGroup() *WhereStmt

AndGroup 开始一个子条件语句

func (*WhereStmt) AndIn

func (stmt *WhereStmt) AndIn(col string, v ...interface{}) *WhereStmt

AndIn 指定 WHERE ... AND col IN(v...)

func (*WhereStmt) AndIsNotNull

func (stmt *WhereStmt) AndIsNotNull(col string) *WhereStmt

AndIsNotNull 指定 WHERE ... AND col IS NOT NULL

func (*WhereStmt) AndIsNull

func (stmt *WhereStmt) AndIsNull(col string) *WhereStmt

AndIsNull 指定 WHERE ... AND col IS NULL

func (*WhereStmt) AndLike

func (stmt *WhereStmt) AndLike(col string, content interface{}) *WhereStmt

AndLike 指定 WHERE ... AND col LIKE content

func (*WhereStmt) AndNotBetween

func (stmt *WhereStmt) AndNotBetween(col string, v1, v2 interface{}) *WhereStmt

AndNotBetween 指定 WHERE ... AND col NOT BETWEEN v1 AND v2

func (*WhereStmt) AndNotIn

func (stmt *WhereStmt) AndNotIn(col string, v ...interface{}) *WhereStmt

AndNotIn 指定 WHERE ... AND col NOT IN(v...)

func (*WhereStmt) AndNotLike

func (stmt *WhereStmt) AndNotLike(col string, content interface{}) *WhereStmt

AndNotLike 指定 WHERE ... AND col NOT LIKE content

func (*WhereStmt) Delete

func (stmt *WhereStmt) Delete(e core.Engine) *DeleteStmt

Delete 删除指定条件的内容

func (*WhereStmt) EndGroup

func (stmt *WhereStmt) EndGroup() (parent *WhereStmt)

EndGroup 结束当前组的条件输出,返回上一层。如果没有上一层,则 panic

func (*WhereStmt) Or

func (stmt *WhereStmt) Or(cond string, args ...interface{}) *WhereStmt

Or 添加一条 OR 语句

func (*WhereStmt) OrBetween

func (stmt *WhereStmt) OrBetween(col string, v1, v2 interface{}) *WhereStmt

OrBetween 指定 WHERE ... OR col BETWEEN v1 AND v2

func (*WhereStmt) OrGroup

func (stmt *WhereStmt) OrGroup() *WhereStmt

OrGroup 开始一个子条件语句

func (*WhereStmt) OrIn

func (stmt *WhereStmt) OrIn(col string, v ...interface{}) *WhereStmt

OrIn 指定 WHERE ... OR col IN(v...)

func (*WhereStmt) OrIsNotNull

func (stmt *WhereStmt) OrIsNotNull(col string) *WhereStmt

OrIsNotNull 指定 WHERE ... OR col IS NOT NULL

func (*WhereStmt) OrIsNull

func (stmt *WhereStmt) OrIsNull(col string) *WhereStmt

OrIsNull 指定 WHERE ... OR col IS NULL

func (*WhereStmt) OrLike

func (stmt *WhereStmt) OrLike(col string, content interface{}) *WhereStmt

OrLike 指定 WHERE ... OR col LIKE content

func (*WhereStmt) OrNotBetween

func (stmt *WhereStmt) OrNotBetween(col string, v1, v2 interface{}) *WhereStmt

OrNotBetween 指定 WHERE ... OR col BETWEEN v1 AND v2

func (*WhereStmt) OrNotIn

func (stmt *WhereStmt) OrNotIn(col string, v ...interface{}) *WhereStmt

OrNotIn 指定 WHERE ... OR col IN(v...)

func (*WhereStmt) OrNotLike

func (stmt *WhereStmt) OrNotLike(col string, content interface{}) *WhereStmt

OrNotLike 指定 WHERE ... OR col NOT LIKE content

func (*WhereStmt) Reset

func (stmt *WhereStmt) Reset()

Reset 重置内容

func (*WhereStmt) SQL

func (stmt *WhereStmt) SQL() (string, []interface{}, error)

SQL 生成 SQL 语句和对应的参数返回

func (*WhereStmt) Select

func (stmt *WhereStmt) Select(e core.Engine) *SelectStmt

Select 生成 select 语句

func (*WhereStmt) Update

func (stmt *WhereStmt) Update(e core.Engine) *UpdateStmt

Update 更新指定条件内容

type WhereStmter

type WhereStmter interface {
	WhereStmt() *WhereStmt
}

WhereStmter 带 Where 语句的 SQL

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL