Documentation ¶
Index ¶
- Constants
- Variables
- func AND[T ComposeType](cond *Condition, column string, size int, values []T)
- func AddAlias(builder *strings.Builder, v string) bool
- func AddQuoted(builder *strings.Builder, v string) bool
- func AddSQLFunc(flag int, fn string)
- func AddTable(builder *strings.Builder, table string)
- func AddVar(builder *strings.Builder, val interface{})
- func AndCompose[T ComposeType](op []string, cond *Condition, column string, size int, values []T)
- func ColumnAs[T ~string](column T, as string) string
- func ColumnName[T ~string](column T) string
- func Compose[T ComposeType](op []string, cond *Condition, column string, size int, values []T)
- func IN[T ComposeType](cond *Condition, column string, size int, values []T)
- func IsNotFound(db *gorm.DB) int
- func IsQuoted(v string) bool
- func IsValid(r interface{}) bool
- func MLike(value string) string
- func NIN[T ComposeType](cond *Condition, column string, size int, values []T)
- func OR[T ComposeType](cond *Condition, column string, size int, values []T)
- func OrCompose[T ComposeType](op []string, cond *Condition, column string, size int, values []T)
- func PLike(value string) string
- func SLike(value string) string
- func SQLFunc(flag int) string
- func SqlColumn(builder *strings.Builder, column string) bool
- func TColumnAs[T ~string](table string, column T, as string) string
- func TColumnName[T ~string](table string, column T) string
- type Base
- func (b *Base) Cancel()
- func (b *Base) Count(model interface{}, count *int64) error
- func (b *Base) Create(model interface{}, opts ...option.QueryFunc) error
- func (b *Base) Delete(model interface{}, cond IQuery) error
- func (b *Base) Find(model interface{}, where IQuery, sel ISelect) error
- func (b *Base) First(model interface{}, where IQuery, sel ISelect) error
- func (b *Base) Get(model interface{}) (result interface{}, err error)
- func (b *Base) Gets(model interface{}) (results []*interface{}, err error)
- func (b *Base) NewDB() *gorm.DB
- func (b *Base) UpdateColumn(model interface{}, where IQuery, column string, value interface{}) error
- func (b *Base) Updates(model interface{}, where IQuery, opts ...option.QueryFunc) error
- func (b *Base) WithOrder(order interface{}) *Base
- func (b *Base) WithResult(result interface{}) *Base
- type Column
- func (col *Column) AS(as string) *Column
- func (col *Column) Build(convert option.ColumnConvertFunc) string
- func (col *Column) Check(filters []FField) *Column
- func (col *Column) GetColumn(opts ...option.Option) []string
- func (col *Column) SetColumn(cols []string)
- func (col *Column) With(column string) *Column
- func (col *Column) WithFunc(fg int) *Column
- func (col *Column) WithTable(table string) *Column
- type ComposeType
- type Condition
- func (sq *Condition) And(column, operator string, value any) *Condition
- func (sq *Condition) AndBetween(column string, value1, value2 any) *Condition
- func (sq *Condition) AndEq(column string, value any) *Condition
- func (sq *Condition) AndGt(column string, value any) *Condition
- func (sq *Condition) AndGte(column string, value any) *Condition
- func (sq *Condition) AndLt(column string, value any) *Condition
- func (sq *Condition) AndLte(column string, value any) *Condition
- func (sq *Condition) AndNEq(column string, value any) *Condition
- func (sq *Condition) Between(column string, value1, value2 any) *Condition
- func (sq *Condition) Build(opts ...option.Option) string
- func (sq *Condition) Column(column string) *Condition
- func (sq *Condition) Compose(column string, operator string, value ...any) *Condition
- func (sq *Condition) ComposeFrom(src *Condition, operator string) *Condition
- func (sq *Condition) Cond() string
- func (sq *Condition) Eq(column string, value any) *Condition
- func (sq *Condition) Gt(column string, value any) *Condition
- func (sq *Condition) GtEq(column string, value any) *Condition
- func (sq *Condition) Gte(column string, value any) *Condition
- func (sq *Condition) In(column string, value any) *Condition
- func (sq *Condition) Is() bool
- func (sq *Condition) IsFirst() bool
- func (sq *Condition) Like(column string, value any) *Condition
- func (sq *Condition) Lt(column string, value any) *Condition
- func (sq *Condition) LtEq(column string, value any) *Condition
- func (sq *Condition) Lte(column string, value any) *Condition
- func (sq *Condition) MLike(column string, value string) *Condition
- func (sq *Condition) Modifier(m string) *Condition
- func (sq *Condition) NEq(column string, value any) *Condition
- func (sq *Condition) Neq(column string, value any) *Condition
- func (sq *Condition) NotIn(column string, value any) *Condition
- func (sq *Condition) Operate(operator string) *Condition
- func (sq *Condition) Or(column, operator string, value any) *Condition
- func (sq *Condition) OrBetween(column string, value1, value2 any) *Condition
- func (sq *Condition) OrEq(column string, value any) *Condition
- func (sq *Condition) OrGt(column string, value any) *Condition
- func (sq *Condition) OrGte(column string, value any) *Condition
- func (sq *Condition) OrLt(column string, value any) *Condition
- func (sq *Condition) OrLte(column string, value any) *Condition
- func (sq *Condition) OrNEq(column string, value any) *Condition
- func (sq *Condition) PLike(column string, value string) *Condition
- func (sq *Condition) Query() string
- func (sq *Condition) Reset() *Condition
- func (sq *Condition) SLike(column string, value string) *Condition
- func (sq *Condition) Value() []interface{}
- func (sq *Condition) Values(value ...interface{}) *Condition
- type FField
- type Flag
- type From
- type GroupBy
- type IBuilder
- type ICond
- type IFrom
- type ILimit
- type IModel
- type IQuery
- type ISelect
- type Join
- type Limit
- type MultiJoin
- type NewCondFunc
- type NewModelFunc
- type OrderBy
- type Page
- type Range
- type RangeV2
- type SQL
- func (s *SQL) AsChild(as string, opts ...option.Option) From
- func (s *SQL) AsSubQuery(as string) *SQL
- func (s *SQL) Build(opts ...option.Option) string
- func (s *SQL) BuildOpt(opts ...option.Option) string
- func (s *SQL) WithGroupBy(by IBuilder) *SQL
- func (s *SQL) WithJoin(join IBuilder) *SQL
- func (s *SQL) WithLimit(limit ILimit) *SQL
- func (s *SQL) WithOrderBy(by IBuilder) *SQL
- func (s *SQL) WithSelector(sel ISelect) *SQL
- func (s *SQL) WithWhere(where IQuery) *SQL
- type Select
- type TableColumn
- type Time
- type TimeV2
Constants ¶
View Source
const ( And = "AND " Or = "OR " Eq = "= ?" Neq = "<> ?" Lt = "< ?" Lte = "<= ?" Gt = "> ?" Gte = ">= ?" NotIn = "NOT IN ?" In = "IN ?" Between = "BETWEEN ? AND ?" Like = "LIKE ?" Exists = "EXISTS ?" NotExists = "NOT EXISTS ?" )
Operate
View Source
const ( JoinLeft = "LEFT" JoinRight = "RIGHT" JoinInner = "INNER" JoinFull = "FULL" JonnCross = "CROSS" )
内连接(inner join…on…) 全外连接(full join…on…) 左连接(left join…on…) 右连接(right join…on…) 交叉连接(cross join …on…)
View Source
const ( KSQLFunc = iota KSQLCount KSQLMax KSQLMin KSQLWeek KSQLYear KSQLMonth KSQLSum KSQLAbs KSQLFloor KSQLGreatest KSQLLeast KSQLUpper KSQLLower KSQLTrim KSQLRTrim KSQLLTrim KSQLCharLength KSQLConcat KSQLReverse )
Variables ¶
View Source
var BuilderType = reflect.TypeOf((*IBuilder)(nil)).Elem()
View Source
var CondType = reflect.TypeOf((*ICond)(nil)).Elem()
View Source
var FromType = reflect.TypeOf((*IFrom)(nil)).Elem()
View Source
var InOp = []string{Eq, In}
View Source
var LimitType = reflect.TypeOf((*ILimit)(nil)).Elem()
View Source
var ModelType = reflect.TypeOf((*IModel)(nil)).Elem()
View Source
var NotInOp = []string{Neq, NotIn}
View Source
var QueryType = reflect.TypeOf((*IQuery)(nil)).Elem()
View Source
var SelectType = reflect.TypeOf((*ISelect)(nil)).Elem()
Functions ¶
func AND ¶ added in v1.8.22
func AND[T ComposeType](cond *Condition, column string, size int, values []T)
func AddSQLFunc ¶ added in v1.3.8
func AndCompose ¶ added in v1.3.0
func AndCompose[T ComposeType](op []string, cond *Condition, column string, size int, values []T)
func ColumnName ¶ added in v1.20.93
func Compose ¶ added in v1.8.22
func Compose[T ComposeType](op []string, cond *Condition, column string, size int, values []T)
func IN ¶ added in v1.3.31
func IN[T ComposeType](cond *Condition, column string, size int, values []T)
func IsNotFound ¶
func NIN ¶ added in v1.8.22
func NIN[T ComposeType](cond *Condition, column string, size int, values []T)
func OR ¶ added in v1.8.22
func OR[T ComposeType](cond *Condition, column string, size int, values []T)
func OrCompose ¶ added in v1.3.0
func OrCompose[T ComposeType](op []string, cond *Condition, column string, size int, values []T)
func TColumnName ¶ added in v1.20.94
Types ¶
type Base ¶
func (*Base) UpdateColumn ¶
func (*Base) WithResult ¶
type Column ¶ added in v1.2.26
type Column struct { Flag //是否函数 Table string Column string `form:"col" json:"col" yaml:"col"` //项 As string `form:"as" json:"as" yaml:"as"` // 别名 Expr string `form:"expr" json:"expr" yaml:"expr"` Desc bool `form:"desc" json:"desc" yaml:"desc"` //(降序(大=>小)desc, 升序(小=>大)asc }
func WithColumn ¶ added in v1.3.9
func WithColumns ¶ added in v1.3.9
func (*Column) Build ¶ added in v1.8.10
func (col *Column) Build(convert option.ColumnConvertFunc) string
type ComposeType ¶ added in v1.3.0
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
func (*Condition) AndBetween ¶ added in v1.2.24
func (*Condition) Column ¶
Column
- example db.Where("created_at BETWEEN ? AND ?", lastWeek, today).Find(&users)
func (*Condition) ComposeFrom ¶ added in v0.5.39
ComposeFrom 组合
func (*Condition) Like ¶
Like
@example db.Where("name LIKE ?", "%jin%").Find(&users) * Condition.Like("name","jin")
func (*Condition) Operate ¶
Operate
@param operator * @example created_at BETWEEN ? AND ? * Condition.Column("created_at").Operate("BETWEEN").Operate("AND").Values(11333,34444)
type From ¶ added in v1.8.17
type Join ¶ added in v1.8.9
type NewCondFunc ¶ added in v1.3.0
type NewCondFunc func() ICond
type NewModelFunc ¶ added in v1.3.0
type NewModelFunc func() IModel
type OrderBy ¶ added in v1.2.26
type OrderBy []Column
OrderBy 排序(降序(大=>小)desc, 升序(小=>大)asc example: "orderBy:[{"col:"create_at","desc":true}, {"col":"id","desc":false}]
"orderBy:[{"col:"create_at,id","desc":true}]
type Page ¶
func (*Page) WithOffset ¶
type Range ¶ added in v1.3.0
type Range[T common.IntegerType] struct { Column string `form:"col" json:"col"` Operator string `form:"operator" json:"operator"` Min T `form:"begin" json:"begin"` Max T `form:"end" json:"end"` }
Range 时间范围
func (*Range[T]) RangeLegal ¶ added in v1.20.54
func (rg *Range[T]) RangeLegal(legal T)
type RangeV2 ¶ added in v1.3.38
type RangeV2[T common.IntegerType] struct { Column string `form:"col" json:"col"` Op string `form:"op" json:"op"` Min T `form:"start" json:"start"` Max T `form:"end" json:"end"` }
RangeV2 时间范围
func (*RangeV2[T]) RangeLegal ¶ added in v1.20.54
func (rg *RangeV2[T]) RangeLegal(legal T)
type SQL ¶ added in v1.3.7
type SQL struct { From Selector ISelect Where IQuery Join IBuilder GroupBy IBuilder OrderBy IBuilder Limit ILimit Opts []option.Option }
func (*SQL) AsSubQuery ¶ added in v1.8.22
AsSubQuery 作为子查询使用
func (*SQL) WithGroupBy ¶ added in v1.8.14
func (*SQL) WithOrderBy ¶ added in v1.8.14
func (*SQL) WithSelector ¶ added in v1.8.14
type TableColumn ¶ added in v1.8.9
type TableColumn struct { Name string `form:"name" json:"name"` //表名 Col string `form:"col" json:"col"` //项 }
func ParseColumn ¶ added in v1.8.10
func ParseColumn(column string) TableColumn
func (*TableColumn) Column ¶ added in v1.8.10
func (t *TableColumn) Column() string
Click to show internal directories.
Click to hide internal directories.