Documentation ¶
Index ¶
- Variables
- func GetColumnsByModel(mapper *reflectx.Mapper, model any, omitColumns ...string) []string
- func GetColumnsByType(mapper *reflectx.Mapper, typ reflect.Type, omitColumns ...string) []string
- func GetMapperByTagName(tagName string) *reflectx.Mapper
- type Builder
- type Column
- func (c Column) EQ(val any) Column
- func (c Column) Express() string
- func (c Column) GT(val any) Column
- func (c Column) GTEQ(val any) Column
- func (c Column) HasInSQL() bool
- func (c Column) In(vals ...any) Column
- func (c Column) LT(val any) Column
- func (c Column) LTEQ(val any) Column
- func (c Column) Like(val any) Column
- func (c Column) NotEQ(val any) Column
- func (c Column) NotIn(vals ...any) Column
- func (c Column) NotLike(val any) Column
- func (c Column) Use(use bool) Column
- type Condition
- type ConditionBuilder
- type Deleter
- func (d *Deleter) Exec() (int64, error)
- func (d *Deleter) ExecContext(ctx context.Context) (int64, error)
- func (d *Deleter) Execer(execer engine.Execer) *Deleter
- func (d *Deleter) Limit(limit int) *Deleter
- func (d *Deleter) SQL() (string, error)
- func (d *Deleter) SQLArgs() (string, []any, error)
- func (d *Deleter) Where(where ConditionBuilder) *Deleter
- type Field
- type Inserter
- func (ins *Inserter) Columns(columns ...string) *Inserter
- func (ins *Inserter) Exec() (lastID int64, affected int64, err error)
- func (ins *Inserter) ExecContext(ctx context.Context) (lastID int64, affected int64, err error)
- func (ins *Inserter) Execer(execer engine.Execer) *Inserter
- func (ins *Inserter) Fields(fields ...Field) *Inserter
- func (ins *Inserter) IsIgnoreInto(ignoreInto bool) *Inserter
- func (ins *Inserter) IsReplaceInto(replaceInto bool) *Inserter
- func (ins *Inserter) NameSQL() (string, error)
- func (ins *Inserter) NamedExec(model any) (lastID int64, affected int64, err error)
- func (ins *Inserter) NamedExecContext(ctx context.Context, model any) (lastID int64, affected int64, err error)
- func (ins *Inserter) OnDuplicateKeyUpdate(fields ...Field) *Inserter
- func (ins *Inserter) OnDuplicateKeyUpdateString(updateString string) *Inserter
- func (ins *Inserter) SQL() (string, error)
- func (ins *Inserter) SQLArgs() (string, []any, error)
- func (ins *Inserter) StructColumns(m any, tagName string, omitColumns ...string) *Inserter
- type Op
- type OrderBy
- type OrderType
- type Predicate
- type Selector
- func (s *Selector) Columns(columns ...string) *Selector
- func (s *Selector) CountSQL() (string, error)
- func (s *Selector) CountSQLArgs() (string, []any, error)
- func (s *Selector) Distinct() *Selector
- func (s *Selector) ForUpdate(isForUpdate bool) *Selector
- func (s *Selector) Get(dest any) (exist bool, err error)
- func (s *Selector) GetContext(ctx context.Context, dest any) (exist bool, err error)
- func (s *Selector) GroupBy(columns ...string) *Selector
- func (s *Selector) IfNullVal(col string, val string) *Selector
- func (s *Selector) IfNullVals(vals map[string]string) *Selector
- func (s *Selector) Limit(limit int64) *Selector
- func (s *Selector) Offset(offset int64) *Selector
- func (s *Selector) OrderBy(orderBy ...OrderBy) *Selector
- func (s *Selector) QueryString(queryString string) *Selector
- func (s *Selector) Queryer(queryer engine.Queryer) *Selector
- func (s *Selector) SQL() (string, error)
- func (s *Selector) SQLArgs() (string, []any, error)
- func (s *Selector) Select(dest any) error
- func (s *Selector) SelectContext(ctx context.Context, dest any) error
- func (s *Selector) StructColumns(model any, tagName string, omitColumns ...string) *Selector
- func (s *Selector) Where(where ConditionBuilder) *Selector
- type SimpleCondition
- type Updater
- func (u *Updater) Columns(columns ...string) *Updater
- func (u *Updater) Exec() (int64, error)
- func (u *Updater) ExecContext(ctx context.Context) (int64, error)
- func (u *Updater) Execer(execer engine.Execer) *Updater
- func (u *Updater) Fields(fields ...Field) *Updater
- func (u *Updater) Incr(column string, n int64) *Updater
- func (u *Updater) NameSQL() (string, error)
- func (u *Updater) NamedExec(data any) (int64, error)
- func (u *Updater) NamedExecContext(ctx context.Context, data any) (int64, error)
- func (u *Updater) SQL() (string, error)
- func (u *Updater) SQLArgs() (string, []any, error)
- func (u *Updater) Set(column string, val any) *Updater
- func (u *Updater) Where(where ConditionBuilder) *Updater
Constants ¶
This section is empty.
Variables ¶
var ( ErrTableNameRequire = errors.New("[sqlbuilder] tableName requires") ErrUpdateMissWhere = errors.New("[sqlbuilder] where express requires with update") ErrColumnsRequire = errors.New("[sqlbuilder] columns requires") ErrDeleteMissWhere = errors.New("[sqlbuilder] delete sql miss where") ErrExecerNotSet = errors.New("[sqlbuilder] execer not set") ErrQueryerNotSet = errors.New("[sqlbuilder] queryer not set") )
var ( OpLT = Op{Symbol: "<", Text: " < "} OpLTEQ = Op{Symbol: "<=", Text: " <= "} OpGT = Op{Symbol: ">", Text: " > "} OpGTEQ = Op{Symbol: ">=", Text: " >= "} OpEQ = Op{Symbol: "=", Text: " = "} OpNEQ = Op{Symbol: "!=", Text: " != "} OpAnd = Op{Symbol: "AND", Text: " AND "} OpOr = Op{Symbol: "OR", Text: " OR "} OpIn = Op{Symbol: "IN", Text: " IN "} OpNotIN = Op{Symbol: "NOT IN", Text: " NOT IN "} OpLike = Op{Symbol: "LIKE", Text: " LIKE "} OpNotLike = Op{Symbol: "NOT LIKE", Text: " NOT LIKE "} )
Functions ¶
func GetColumnsByModel ¶
GetColumnsByModel 解析 model 所有字段名
func GetColumnsByType ¶
GetColumnsByType 通过字段 tag 解析数据库字段
func GetMapperByTagName ¶
GetMapperByTagName 根据 tag name 返回对应 mapper
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
type Column ¶
type Column struct {
// contains filtered or unexported fields
}
Column 表字段
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
Condition 条件构造器实现
type ConditionBuilder ¶
type ConditionBuilder interface {
// contains filtered or unexported methods
}
ConditionBuilder 条件构造器
type Deleter ¶
type Deleter struct {
// contains filtered or unexported fields
}
Deleter delete 语句构造器
func (*Deleter) ExecContext ¶ added in v1.1.0
ExecContext 执行更新语句
func (*Deleter) Where ¶
func (d *Deleter) Where(where ConditionBuilder) *Deleter
Where 条件 condition 可以通过 sqlbuilder.C() 方法创建
type Field ¶ added in v1.1.0
type Field struct {
// contains filtered or unexported fields
}
Field 表更新字段
type Inserter ¶
type Inserter struct {
// contains filtered or unexported fields
}
Inserter insert 语句构造器
func (*Inserter) Exec ¶ added in v1.1.0
Exec 执行 insert 语句 执行 Exec 方法,需要通过 Fields 方法赋值,否则使用 NamedExec
func (*Inserter) ExecContext ¶ added in v1.1.0
ExecContext 执行更新语句 执行 Exec 方法,需要通过 Fields 方法赋值,否则使用 NamedExec
func (*Inserter) IsIgnoreInto ¶
IsIgnoreInto 是否使用 ignore into
func (*Inserter) IsReplaceInto ¶
IsReplaceInto 是否使用 replace into
func (*Inserter) NamedExecContext ¶ added in v1.1.0
func (ins *Inserter) NamedExecContext(ctx context.Context, model any) (lastID int64, affected int64, err error)
NamedExecContext 通过 NameSQL 执行更新语句,参数通过 data 填充
func (*Inserter) OnDuplicateKeyUpdate ¶ added in v1.1.0
OnDuplicateKeyUpdate 设置 on duplicate key update 字段
func (*Inserter) OnDuplicateKeyUpdateString ¶
OnDuplicateKeyUpdateString 设置 on duplicate key update 字段
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector select 语句构造器
func (*Selector) CountSQLArgs ¶
CountSQLArgs 构造 count 查询 sql 并返回对应参数
func (*Selector) GetContext ¶ added in v1.1.0
GetContext 查询单条数据
func (*Selector) IfNullVals ¶ added in v1.1.0
IfNullVals 设置字段为空时,返回的值 key 为数据库表字段名 value 为默认值表达式,如:空字符串为 "”"
func (*Selector) QueryString ¶
QueryString 自定义select字段,sql原样输出
func (*Selector) SelectContext ¶ added in v1.1.0
SelectContext 查询多条数据
func (*Selector) StructColumns ¶
StructColumns 通过任意model解析出表字段 tagName 解析数据库字段的 tag-name omitColumns 排除哪些字段
func (*Selector) Where ¶
func (s *Selector) Where(where ConditionBuilder) *Selector
Where 条件 condition 可以通过 sqlbuilder.C() 方法创建
type SimpleCondition ¶
type SimpleCondition struct {
// contains filtered or unexported fields
}
SimpleCondition 简单 where 条件构造
func (*SimpleCondition) And ¶
func (c *SimpleCondition) And(express string, args ...any) *SimpleCondition
And and 语句 express where 表达式
func (*SimpleCondition) Or ¶
func (c *SimpleCondition) Or(express string, args ...any) *SimpleCondition
Or or 语句 express where 表达式
func (*SimpleCondition) Predicates ¶
func (c *SimpleCondition) Predicates() []Predicate
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater update 语句构造器
func (*Updater) ExecContext ¶ added in v1.1.0
ExecContext 执行更新语句
func (*Updater) NamedExec ¶ added in v1.1.0
NamedExec 通过 NameSQL 执行更新语句,参数通过 data 填充 where 条件也必须是 name 风格
func (*Updater) NamedExecContext ¶ added in v1.1.0
NamedExecContext 通过 NameSQL 执行更新语句,参数通过 data 填充 where 条件也必须是 name 风格
func (*Updater) Where ¶
func (u *Updater) Where(where ConditionBuilder) *Updater
Where 条件 condition 可以通过 sqlbuilder.C() 方法创建