Documentation
¶
Index ¶
- type Column
- type Context
- func (db *Context) AddSelect(columns ...string) *Context
- func (db *Context) CrossJoin(table any, argOrFn ...any) *Context
- func (db *Context) GroupBy(columns ...string) *Context
- func (db *Context) GroupByRaw(columns ...string) *Context
- func (db *Context) Having(column any, argsOrClosure ...any) *Context
- func (db *Context) HavingRaw(raw string, argsOrClosure ...any) *Context
- func (db *Context) Join(table any, argOrFn ...any) *Context
- func (db *Context) LeftJoin(table any, argOrFn ...any) *Context
- func (db *Context) Limit(limit int) *Context
- func (db *Context) LockForUpdate() *Context
- func (db *Context) Offset(offset int) *Context
- func (db *Context) OrHaving(column any, argsOrClosure ...any) *Context
- func (db *Context) OrHavingRaw(raw string, argsOrClosure ...any) *Context
- func (db *Context) OrWhere(column any, argsOrclosure ...any) *Context
- func (db *Context) OrWhereBuilder(column string, operation string, sub IBuilder) *Context
- func (db *Context) OrWhereNested(handler WhereNestedHandler) *Context
- func (db *Context) OrWhereRaw(raw string, bindings ...any) *Context
- func (db *Context) OrWhereSub(column string, operation string, sub WhereSubHandler) *Context
- func (db *Context) OrderBy(column string, directions ...string) *Context
- func (db *Context) OrderByRaw(column string) *Context
- func (db *Context) Page(num int) *Context
- func (db *Context) RightJoin(table any, argOrFn ...any) *Context
- func (db *Context) Select(columns ...string) *Context
- func (db *Context) SelectRaw(raw string, binds ...any) *Context
- func (db *Context) SharedLock() *Context
- func (db *Context) Table(table any, alias ...string) *Context
- func (db *Context) Where(column any, argsOrclosure ...any) *Context
- func (db *Context) WhereBuilder(column string, operation string, sub IBuilder) *Context
- func (db *Context) WhereNested(handler WhereNestedHandler) *Context
- func (db *Context) WhereRaw(raw string, bindings ...any) *Context
- func (db *Context) WhereSub(column string, operation string, sub WhereSubHandler) *Context
- type GroupClause
- type HavingClause
- type IBuilder
- type IJoinOn
- type IWhere
- type JoinClause
- func (db *JoinClause) CrossJoin(table any, argOrFn ...any) *JoinClause
- func (db *JoinClause) Join(table any, argOrFn ...any) *JoinClause
- func (db *JoinClause) JoinOn(table any, fn func(on IJoinOn)) *JoinClause
- func (db *JoinClause) LeftJoin(table any, argOrFn ...any) *JoinClause
- func (db *JoinClause) RightJoin(table any, argOrFn ...any) *JoinClause
- type LimitOffsetClause
- type OrderByClause
- type OrderByItem
- type SelectClause
- type TableClause
- type TypeGroupItem
- type TypeJoinOn
- type TypeJoinOnCondition
- type TypeJoinOnConditionItem
- type TypeJoinStandard
- type TypeJoinSub
- type TypeLock
- type TypeToSqlIncDecCase
- type TypeToSqlInsertCase
- type TypeToSqlUpdateCase
- type TypeWhereBetween
- type TypeWhereExists
- type TypeWhereIn
- type TypeWhereNested
- type TypeWhereRaw
- type TypeWhereStandard
- type TypeWhereSubHandler
- type TypeWhereSubQuery
- type UnionClause
- type UnionItem
- type WhereClause
- func (w *WhereClause) OrWhere(column any, args ...any) IWhere
- func (w *WhereClause) OrWhereBetween(column string, values any) IWhere
- func (w *WhereClause) OrWhereBuilder(column string, operation string, sub IBuilder) IWhere
- func (w *WhereClause) OrWhereIn(column string, values any) IWhere
- func (w *WhereClause) OrWhereLike(column string, value string) IWhere
- func (w *WhereClause) OrWhereNested(handler WhereNestedHandler) IWhere
- func (w *WhereClause) OrWhereNot(column any, args ...any) IWhere
- func (w *WhereClause) OrWhereNotBetween(column string, values any) IWhere
- func (w *WhereClause) OrWhereNotIn(column string, values any) IWhere
- func (w *WhereClause) OrWhereNotLike(column string, value string) IWhere
- func (w *WhereClause) OrWhereNotNull(column string) IWhere
- func (w *WhereClause) OrWhereNull(column string) IWhere
- func (w *WhereClause) OrWhereRaw(sqlSeg string, bindingsAndBoolean ...any) IWhere
- func (w *WhereClause) OrWhereSub(column string, operation string, sub WhereSubHandler) IWhere
- func (w *WhereClause) Where(column any, args ...any) IWhere
- func (w *WhereClause) WhereBetween(column string, values any) IWhere
- func (w *WhereClause) WhereBuilder(column string, operation string, build IBuilder) IWhere
- func (w *WhereClause) WhereExists(clause IBuilder) IWhere
- func (w *WhereClause) WhereIn(column string, values any) IWhere
- func (w *WhereClause) WhereLike(column string, value string) IWhere
- func (w *WhereClause) WhereNested(handler WhereNestedHandler) IWhere
- func (w *WhereClause) WhereNot(column any, args ...any) IWhere
- func (w *WhereClause) WhereNotBetween(column string, values any) IWhere
- func (w *WhereClause) WhereNotExists(clause IBuilder) IWhere
- func (w *WhereClause) WhereNotIn(column string, values any) IWhere
- func (w *WhereClause) WhereNotLike(column string, value string) IWhere
- func (w *WhereClause) WhereNotNull(column string) IWhere
- func (w *WhereClause) WhereNull(column string) IWhere
- func (w *WhereClause) WhereRaw(raw string, bindingsAndBoolean ...any) IWhere
- func (w *WhereClause) WhereSub(column string, operation string, sub WhereSubHandler) IWhere
- type WhereNestedHandler
- type WhereSubHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct { Name string Alias string // 可选别名 IsRaw bool // 是否是原生SQL片段 Binds []any // 绑定数据 }
Column 表示SELECT语句中的列信息。
type Context ¶
type Context struct { TableClause TableClause SelectClause SelectClause JoinClause JoinClause WhereClause WhereClause GroupClause GroupClause HavingClause HavingClause OrderByClause OrderByClause LimitOffsetClause LimitOffsetClause UnionClause UnionClause PessimisticLocking TypeLock Prefix string }
func NewContext ¶
func (*Context) GroupByRaw ¶
func (*Context) LockForUpdate ¶
func (*Context) OrHavingRaw ¶
func (*Context) OrWhereBuilder ¶
func (*Context) OrWhereNested ¶
func (db *Context) OrWhereNested(handler WhereNestedHandler) *Context
func (*Context) OrWhereSub ¶
func (db *Context) OrWhereSub(column string, operation string, sub WhereSubHandler) *Context
func (*Context) OrderByRaw ¶
func (*Context) SharedLock ¶
func (*Context) WhereBuilder ¶
func (*Context) WhereNested ¶
func (db *Context) WhereNested(handler WhereNestedHandler) *Context
type GroupClause ¶
type GroupClause struct {
Groups []TypeGroupItem
}
func (*GroupClause) GroupBy ¶
func (db *GroupClause) GroupBy(columns ...string)
GroupBy 添加 GROUP BY 子句
func (*GroupClause) GroupByRaw ¶
func (db *GroupClause) GroupByRaw(columns ...string)
type HavingClause ¶
type HavingClause struct {
WhereClause
}
HavingClause 类似于WhereClause,但应用于HAVING子句。
type IBuilder ¶
type IBuilder interface { ToSql() (sql4prepare string, binds []any, err error) ToSqlSelect() (sql4prepare string, binds []any) ToSqlTable() (sql4prepare string, values []any, err error) ToSqlJoin() (sql4prepare string, binds []any, err error) ToSqlWhere() (sql4prepare string, values []any, err error) ToSqlOrderBy() (sql4prepare string) ToSqlLimitOffset() (sqlSegment string, binds []any) ToSqlInsert(obj any, args ...TypeToSqlInsertCase) (sqlSegment string, binds []any, err error) ToSqlDelete(obj any, mustColumn ...string) (sqlSegment string, binds []any, err error) ToSqlUpdate(obj any, mustColumn ...string) (sqlSegment string, binds []any, err error) ToSqlIncDec(symbol string, data map[string]any) (sql4prepare string, values []any, err error) }
type IWhere ¶
type IWhere interface { Where(column any, args ...any) IWhere OrWhere(column any, args ...any) IWhere WhereRaw(raw string, bindingsAndBoolean ...any) IWhere OrWhereRaw(sqlSeg string, bindingsAndBoolean ...any) IWhere WhereBetween(column string, values any) IWhere OrWhereBetween(column string, values any) IWhere WhereNotBetween(column string, values any) IWhere OrWhereNotBetween(column string, values any) IWhere WhereIn(column string, values any) IWhere OrWhereIn(column string, values any) IWhere WhereNotIn(column string, values any) IWhere OrWhereNotIn(column string, values any) IWhere WhereNull(column string) IWhere OrWhereNull(column string) IWhere WhereNotNull(column string) IWhere OrWhereNotNull(column string) IWhere WhereLike(column string, value string) IWhere OrWhereLike(column string, value string) IWhere WhereNotLike(column string, value string) IWhere OrWhereNotLike(column string, value string) IWhere WhereBuilder(column string, operation string, build IBuilder) IWhere OrWhereBuilder(column string, operation string, sub IBuilder) IWhere WhereSub(column string, operation string, sub WhereSubHandler) IWhere OrWhereSub(column string, operation string, sub WhereSubHandler) IWhere WhereNested(handler WhereNestedHandler) IWhere OrWhereNested(handler WhereNestedHandler) IWhere WhereExists(clause IBuilder) IWhere WhereNotExists(clause IBuilder) IWhere }
type JoinClause ¶
JoinClause 描述JOIN操作
func (*JoinClause) CrossJoin ¶
func (db *JoinClause) CrossJoin(table any, argOrFn ...any) *JoinClause
CrossJoin 描述CROSS JOIN操作
func (*JoinClause) Join ¶
func (db *JoinClause) Join(table any, argOrFn ...any) *JoinClause
func (*JoinClause) JoinOn ¶
func (db *JoinClause) JoinOn(table any, fn func(on IJoinOn)) *JoinClause
func (*JoinClause) LeftJoin ¶
func (db *JoinClause) LeftJoin(table any, argOrFn ...any) *JoinClause
LeftJoin 描述LEFT JOIN操作
func (*JoinClause) RightJoin ¶
func (db *JoinClause) RightJoin(table any, argOrFn ...any) *JoinClause
RightJoin 描述RIGHT JOIN操作
type LimitOffsetClause ¶
LimitOffsetClause 存储LIMIT和OFFSET信息。
type OrderByClause ¶
type OrderByClause struct {
Columns []OrderByItem
}
OrderByClause 存储排序信息。
func (*OrderByClause) OrderBy ¶
func (db *OrderByClause) OrderBy(column string, directions ...string)
OrderBy adds an ORDER BY clause to the query.
func (*OrderByClause) OrderByRaw ¶
func (db *OrderByClause) OrderByRaw(column string)
OrderByRaw adds a Raw ORDER BY clause to the query.
type OrderByItem ¶
type SelectClause ¶
SelectClause 存储SELECT子句相关信息。
func (*SelectClause) AddSelect ¶
func (db *SelectClause) AddSelect(columns ...string) *SelectClause
func (*SelectClause) Select ¶
func (db *SelectClause) Select(columns ...string) *SelectClause
Select specifies the columns to retrieve. Select("a","b") Select("a.id as aid","b.id bid") Select("id,nickname name")
func (*SelectClause) SelectRaw ¶
func (db *SelectClause) SelectRaw(raw string, binds ...any) *SelectClause
SelectRaw 允许直接在查询中插入原始SQL片段作为选择列。
type TableClause ¶
TableClause table clause
func (*TableClause) Table ¶
func (db *TableClause) Table(table any, alias ...string)
Table sets the table name for the query.
type TypeGroupItem ¶
type TypeJoinOn ¶
type TypeJoinOn struct { TableClause OnClause func(IJoinOn) Type string // JOIN类型(INNER, LEFT, RIGHT等) }
type TypeJoinOnCondition ¶
type TypeJoinOnCondition struct {
Conditions []TypeJoinOnConditionItem
}
type TypeJoinOnConditionItem ¶
type TypeJoinStandard ¶
type TypeJoinStandard struct { TableClause Type string // JOIN类型(INNER, LEFT, RIGHT等) Column1 string Operator string Column2 string }
type TypeToSqlIncDecCase ¶
type TypeToSqlInsertCase ¶
type TypeToSqlUpdateCase ¶
type TypeWhereBetween ¶
type TypeWhereExists ¶
type TypeWhereIn ¶
type TypeWhereNested ¶
type TypeWhereNested struct { LogicalOp string WhereNested WhereNestedHandler }
type TypeWhereRaw ¶
type TypeWhereStandard ¶
type TypeWhereSubHandler ¶
type TypeWhereSubHandler struct { LogicalOp string Column string Operator string Sub WhereSubHandler }
type TypeWhereSubQuery ¶
type UnionClause ¶
type UnionClause struct {
Unions []UnionItem
}
func (*UnionClause) Union ¶
func (u *UnionClause) Union(b ...IBuilder) *UnionClause
func (*UnionClause) UnionAll ¶
func (u *UnionClause) UnionAll(b ...IBuilder) *UnionClause
type WhereClause ¶
WhereClause 存储所有WHERE条件 ///////////////////start
func (*WhereClause) OrWhere ¶
func (w *WhereClause) OrWhere(column any, args ...any) IWhere
OrWhere clause
func (*WhereClause) OrWhereBetween ¶
func (w *WhereClause) OrWhereBetween(column string, values any) IWhere
func (*WhereClause) OrWhereBuilder ¶
func (w *WhereClause) OrWhereBuilder(column string, operation string, sub IBuilder) IWhere
func (*WhereClause) OrWhereLike ¶
func (w *WhereClause) OrWhereLike(column string, value string) IWhere
func (*WhereClause) OrWhereNested ¶
func (w *WhereClause) OrWhereNested(handler WhereNestedHandler) IWhere
func (*WhereClause) OrWhereNot ¶
func (w *WhereClause) OrWhereNot(column any, args ...any) IWhere
func (*WhereClause) OrWhereNotBetween ¶
func (w *WhereClause) OrWhereNotBetween(column string, values any) IWhere
func (*WhereClause) OrWhereNotIn ¶
func (w *WhereClause) OrWhereNotIn(column string, values any) IWhere
func (*WhereClause) OrWhereNotLike ¶
func (w *WhereClause) OrWhereNotLike(column string, value string) IWhere
func (*WhereClause) OrWhereNotNull ¶
func (w *WhereClause) OrWhereNotNull(column string) IWhere
func (*WhereClause) OrWhereNull ¶
func (w *WhereClause) OrWhereNull(column string) IWhere
func (*WhereClause) OrWhereRaw ¶
func (w *WhereClause) OrWhereRaw(sqlSeg string, bindingsAndBoolean ...any) IWhere
OrWhereRaw clause
func (*WhereClause) OrWhereSub ¶
func (w *WhereClause) OrWhereSub(column string, operation string, sub WhereSubHandler) IWhere
func (*WhereClause) Where ¶
func (w *WhereClause) Where(column any, args ...any) IWhere
Where Add a basic where clause to the query.
where($column, $operator = null, $value = null, $boolean = 'and')
Parameters:
array|Closure|Expression|string $column mixed $operator mixed $value string $boolean
Returns:
iface.WhereClause
Examples:
Where("id=1") Where("id=?",1), 不支持 Where("id",1) Where("id","=",1) Where("id","=",1,"AND") Where("id","=",(select id from table limit 1)) Where("id","in",(select id from table), "AND") Where(func(wh builder.WhereClause){wh.Where().OrWhere().WhereRaw()...}) Where(["id=1"]) Where(["id","=",1]) Where(["id",1]) Where([ ["id",1],["name","=","John"],["age",">",3] ])
func (*WhereClause) WhereBetween ¶
func (w *WhereClause) WhereBetween(column string, values any) IWhere
WhereBetween 在指定列的值位于给定范围内时添加一个"where"条件。
relation: and/or column: 列名。 values: 区间范围数组。 not: 是否取反,默认为 false。
func (*WhereClause) WhereBuilder ¶
func (w *WhereClause) WhereBuilder(column string, operation string, build IBuilder) IWhere
func (*WhereClause) WhereExists ¶
func (w *WhereClause) WhereExists(clause IBuilder) IWhere
WhereExists 使用WHERE EXISTS子查询条件。
clause: Database 语句,或者实现了 IBuilder.ToSql() 接口的对象
func (*WhereClause) WhereIn ¶
func (w *WhereClause) WhereIn(column string, values any) IWhere
WhereIn 在指定列的值存在于给定的集合内时添加一个"where"条件。
relation: and/or column: 要检查的列名。 values: 集合值。 not: 是否取反,默认为 false。
func (*WhereClause) WhereLike ¶
func (w *WhereClause) WhereLike(column string, value string) IWhere
WhereLike 在指定列进行模糊匹配时添加一个"where"条件。
relation: and/or column: 要进行模糊匹配的列名。 value: 包含通配符(%)的匹配字符串。
func (*WhereClause) WhereNested ¶
func (w *WhereClause) WhereNested(handler WhereNestedHandler) IWhere
func (*WhereClause) WhereNotBetween ¶
func (w *WhereClause) WhereNotBetween(column string, values any) IWhere
func (*WhereClause) WhereNotExists ¶
func (w *WhereClause) WhereNotExists(clause IBuilder) IWhere
func (*WhereClause) WhereNotIn ¶
func (w *WhereClause) WhereNotIn(column string, values any) IWhere
func (*WhereClause) WhereNotLike ¶
func (w *WhereClause) WhereNotLike(column string, value string) IWhere
func (*WhereClause) WhereNotNull ¶
func (w *WhereClause) WhereNotNull(column string) IWhere
func (*WhereClause) WhereNull ¶
func (w *WhereClause) WhereNull(column string) IWhere
WhereNull 指定列的值为 NULL 时添加一个"where"条件。
relation: and/or column: 列名。
func (*WhereClause) WhereRaw ¶
func (w *WhereClause) WhereRaw(raw string, bindingsAndBoolean ...any) IWhere
WhereRaw Add a raw where clause to the query.
whereRaw($sql, $bindings = [], $boolean = 'and')
Parameters:
string $sql mixed $bindings string $boolean
Returns:
SubQuery
Laravel api
func (*WhereClause) WhereSub ¶
func (w *WhereClause) WhereSub(column string, operation string, sub WhereSubHandler) IWhere
type WhereNestedHandler ¶
type WhereNestedHandler func(where IWhere)
type WhereSubHandler ¶
type WhereSubHandler func(tx *Context)