wrapper

package
v1.9.26 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: Zlib Imports: 10 Imported by: 1

Documentation

Index

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 InOp = []string{Eq, In}
View Source
var NotInOp = []string{Neq, NotIn}

Functions

func AND added in v1.8.22

func AND[T ComposeType](cond *Condition, column string, size int, values []T)

func AddAlias added in v1.8.17

func AddAlias(builder *strings.Builder, v string) bool

func AddQuoted added in v1.8.15

func AddQuoted(builder *strings.Builder, v string) bool

func AddSQLFunc added in v1.3.8

func AddSQLFunc(flag int, fn string)

func AddVar added in v1.8.15

func AddVar(builder *strings.Builder, val interface{})

func AndCompose added in v1.3.0

func AndCompose[T ComposeType](op []string, cond *Condition, column string, size int, values []T)

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 IsNotFound(db *gorm.DB) int

func IsValid

func IsValid(r interface{}) bool

func MLike added in v1.2.16

func MLike(value string) string

MLike %?%

func MustName added in v1.8.31

func MustName(name string) string

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 PLike added in v1.2.16

func PLike(value string) string

PLike %?

func SLike added in v1.2.16

func SLike(value string) string

SLike ?%

func SQLFunc added in v1.3.8

func SQLFunc(flag int) string

func SqlColumn added in v1.8.16

func SqlColumn(builder *strings.Builder, column string) bool

Types

type Base

type Base struct {
	DB *gorm.DB

	Results interface{}
	// contains filtered or unexported fields
}

func (*Base) Cancel

func (b *Base) Cancel()

func (*Base) Count

func (b *Base) Count(model interface{}, count *int64) error

func (*Base) Create

func (b *Base) Create(model interface{}, opts ...option.QueryFunc) error

func (*Base) Delete

func (b *Base) Delete(model interface{}, cond IQuery) error

func (*Base) Find added in v0.5.1

func (b *Base) Find(model interface{}, where IQuery, sel ISelect) error

func (*Base) First

func (b *Base) First(model interface{}, where IQuery, sel ISelect) error

func (*Base) Get

func (b *Base) Get(model interface{}) (result interface{}, err error)

Get 获取

func (*Base) Gets

func (b *Base) Gets(model interface{}) (results []*interface{}, err error)

Gets 获取批量结果

func (*Base) NewDB

func (b *Base) NewDB() *gorm.DB

func (*Base) UpdateColumn

func (b *Base) UpdateColumn(model interface{}, where IQuery, column string, value interface{}) error

func (*Base) Updates

func (b *Base) Updates(model interface{}, where IQuery, opts ...option.QueryFunc) error

func (*Base) WithOrder

func (b *Base) WithOrder(order interface{}) *Base

func (*Base) WithResult

func (b *Base) WithResult(result interface{}) *Base

type Column added in v1.2.26

type Column struct {
	Flag          //是否函数
	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 WithColumn(column string) *Column

func WithColumns added in v1.3.9

func WithColumns(cols []string) *Column

func (*Column) AS added in v1.3.8

func (col *Column) AS(as string) *Column

func (*Column) Build added in v1.8.10

func (col *Column) Build(convert option.ColumnConvertFunc) string

func (*Column) Check added in v1.3.8

func (col *Column) Check(filters []FField) *Column

func (*Column) GetColumn added in v1.2.26

func (col *Column) GetColumn(opts ...option.Option) []string

func (*Column) SetColumn added in v1.2.26

func (col *Column) SetColumn(cols []string)

func (*Column) With added in v1.3.8

func (col *Column) With(column string) *Column

func (*Column) WithFunc added in v1.3.8

func (col *Column) WithFunc(fg int) *Column

type ComposeType added in v1.3.0

type ComposeType interface {
	string | bool | int8 | int16 | int | int32 | int64 | uint8 | uint16 | uint | uint32 | uint64 | float32 | float64
}

type Condition

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

func (*Condition) And

func (sq *Condition) And(column, operator string, value interface{}) *Condition

And

 @param column
*  @param operator "=、<小于、>大于、>=大于等于、<=小于等于、<>以及不等于"

func (*Condition) AndBetween added in v1.2.24

func (sq *Condition) AndBetween(column string, value1, value2 interface{}) *Condition

func (*Condition) AndEq added in v0.5.1

func (sq *Condition) AndEq(column string, value interface{}) *Condition

func (*Condition) AndGt added in v0.5.1

func (sq *Condition) AndGt(column string, value interface{}) *Condition

func (*Condition) AndGte added in v1.8.9

func (sq *Condition) AndGte(column string, value interface{}) *Condition

func (*Condition) AndLt added in v0.5.1

func (sq *Condition) AndLt(column string, value interface{}) *Condition

func (*Condition) AndLte added in v1.8.9

func (sq *Condition) AndLte(column string, value interface{}) *Condition

func (*Condition) AndNEq added in v0.5.1

func (sq *Condition) AndNEq(column string, value interface{}) *Condition

func (*Condition) Between added in v1.2.13

func (sq *Condition) Between(column string, value1, value2 interface{}) *Condition

func (*Condition) Build added in v1.8.9

func (sq *Condition) Build(opts ...option.Option) string

func (*Condition) Column

func (sq *Condition) Column(column string) *Condition

Column

  • example db.Where("created_at BETWEEN ? AND ?", lastWeek, today).Find(&users)

func (*Condition) Compose

func (sq *Condition) Compose(column string, operator string, value ...interface{}) *Condition

func (*Condition) ComposeFrom added in v0.5.39

func (sq *Condition) ComposeFrom(src *Condition, operator string) *Condition

ComposeFrom 组合

func (*Condition) Cond

func (sq *Condition) Cond() string

func (*Condition) Eq

func (sq *Condition) Eq(column string, value interface{}) *Condition

func (*Condition) Gt

func (sq *Condition) Gt(column string, value interface{}) *Condition

func (*Condition) GtEq

func (sq *Condition) GtEq(column string, value interface{}) *Condition

func (*Condition) In

func (sq *Condition) In(column string, value interface{}) *Condition

func (*Condition) Is

func (sq *Condition) Is() bool

func (*Condition) IsFirst added in v0.5.40

func (sq *Condition) IsFirst() bool

func (*Condition) Like

func (sq *Condition) Like(column string, value interface{}) *Condition

Like

@example db.Where("name LIKE ?", "%jin%").Find(&users)
* Condition.Like("name","jin")

func (*Condition) Lt

func (sq *Condition) Lt(column string, value interface{}) *Condition

func (*Condition) LtEq

func (sq *Condition) LtEq(column string, value interface{}) *Condition

func (*Condition) MLike added in v1.2.16

func (sq *Condition) MLike(column string, value string) *Condition

func (*Condition) Modifier

func (sq *Condition) Modifier(m string) *Condition

Modifier 修饰符,比如 ()

func (*Condition) NEq

func (sq *Condition) NEq(column string, value interface{}) *Condition

func (*Condition) NotIn added in v1.8.22

func (sq *Condition) NotIn(column string, value interface{}) *Condition

func (*Condition) Operate

func (sq *Condition) Operate(operator string) *Condition

Operate

@param operator
* @example created_at BETWEEN ? AND ?
* Condition.Column("created_at").Operate("BETWEEN").Operate("AND").Values(11333,34444)

func (*Condition) Or

func (sq *Condition) Or(column, operator string, value interface{}) *Condition

func (*Condition) OrBetween added in v1.2.24

func (sq *Condition) OrBetween(column string, value1, value2 interface{}) *Condition

func (*Condition) OrEq added in v0.5.1

func (sq *Condition) OrEq(column string, value interface{}) *Condition

func (*Condition) OrGt added in v0.5.1

func (sq *Condition) OrGt(column string, value interface{}) *Condition

func (*Condition) OrGte added in v1.8.9

func (sq *Condition) OrGte(column string, value interface{}) *Condition

func (*Condition) OrLt added in v0.5.1

func (sq *Condition) OrLt(column string, value interface{}) *Condition

func (*Condition) OrLte added in v1.8.9

func (sq *Condition) OrLte(column string, value interface{}) *Condition

func (*Condition) OrNEq added in v0.5.1

func (sq *Condition) OrNEq(column string, value interface{}) *Condition

func (*Condition) PLike added in v1.2.16

func (sq *Condition) PLike(column string, value string) *Condition

func (*Condition) Query added in v0.5.1

func (sq *Condition) Query() string

func (*Condition) Reset

func (sq *Condition) Reset() *Condition

func (*Condition) SLike added in v1.2.16

func (sq *Condition) SLike(column string, value string) *Condition

func (*Condition) Value

func (sq *Condition) Value() []interface{}

func (*Condition) Values

func (sq *Condition) Values(value ...interface{}) *Condition

type FField added in v1.2.26

type FField string

func (FField) Equal added in v1.2.26

func (ff FField) Equal(des FField) bool

type Flag added in v1.3.8

type Flag struct {
	FInt int `form:"flag" json:"flag" yaml:"flag"`
}

type From added in v1.8.17

type From struct {
	From string `json:"from" yaml:"from"`
	As   string `json:"as" yaml:"as"`
	// contains filtered or unexported fields
}

func (*From) Build added in v1.8.17

func (f *From) Build(opts ...option.Option) string

func (*From) Is added in v1.8.17

func (f *From) Is() bool

func (*From) SetAs added in v1.8.17

func (f *From) SetAs(as string)

func (*From) SetChild added in v1.8.17

func (f *From) SetChild(child bool)

type GroupBy added in v1.3.7

type GroupBy []Column

func (*GroupBy) Build added in v1.8.10

func (g *GroupBy) Build(opts ...option.Option) string

func (*GroupBy) Check added in v1.3.7

func (g *GroupBy) Check(filters []FField, opts ...option.Option)

func (*GroupBy) Is added in v1.8.13

func (g *GroupBy) Is() bool

type IBuilder added in v1.8.13

type IBuilder interface {
	Is() bool
	Build(opts ...option.Option) string
}

type ICond added in v1.3.0

type ICond interface {
	HasValid() error
	Decode(cond string)
	BuildCond(cond *Condition)
	Build(key string, cb func(obj interface{})) error
}

type IFrom added in v1.8.17

type IFrom interface {
	Is() bool
	SetChild(child bool)
	SetAs(as string)
	Build(opts ...option.Option) string
}

type ILimit added in v1.8.14

type ILimit interface {
	Is() bool
	GetLimit() int
	GetOffset() int
	Build(opts ...option.Option) string
}

type IModel added in v1.3.2

type IModel interface {
	Clone() IModel
	Model() interface{}
	Set(key string, v interface{})
	Get(key string) interface{}
	ForEach(cb func(key string, v interface{}))
}

type IQuery added in v0.5.4

type IQuery interface {
	Is() bool
	Query() string
	Value() []interface{}
	Build(opts ...option.Option) string
}

type ISelect added in v0.5.4

type ISelect interface {
	Is() bool
	Query() []string
	Value() []interface{}
	Build(opts ...option.Option) string
}

type Join added in v1.8.9

type Join struct {
	Type  string   `json:"type" yaml:"type"`
	Table string   `json:"table" yaml:"table"`
	Alias string   `json:"as" yaml:"as"`
	ON    string   `json:"expr" yaml:"expr"`
	Using []string `json:"using" yaml:"using"`
}

func (*Join) Build added in v1.8.9

func (jn *Join) Build(opts ...option.Option) string

func (*Join) Is added in v1.8.9

func (jn *Join) Is() bool

func (*Join) JoinType added in v1.8.17

func (jn *Join) JoinType() (string, bool)

type Limit added in v1.2.26

type Limit struct {
	Offset int
	Limit  int
}

func (*Limit) Build added in v1.8.13

func (l *Limit) Build(opts ...option.Option) string

func (*Limit) GetLimit added in v1.8.14

func (l *Limit) GetLimit() int

func (*Limit) GetOffset added in v1.8.14

func (l *Limit) GetOffset() int

func (*Limit) Is added in v1.8.13

func (l *Limit) Is() bool

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}]

func (*OrderBy) Build added in v1.8.10

func (ob *OrderBy) Build(opts ...option.Option) string

func (*OrderBy) Check added in v1.2.26

func (ob *OrderBy) Check(filters []FField, opts ...option.Option)

func (*OrderBy) Is added in v1.8.13

func (ob *OrderBy) Is() bool

type Page

type Page struct {
	Base
	Total int64
	// contains filtered or unexported fields
}

func NewPage

func NewPage(db *gorm.DB, timeout time.Duration) *Page

func (*Page) FindPage added in v0.5.1

func (page *Page) FindPage(model interface{}, where IQuery, sel ISelect) error

FindPage param results := make([]object, 0)

func (*Page) WithOffset

func (page *Page) WithOffset(offset int) *Page

func (*Page) WithSize

func (page *Page) WithSize(size int) *Page

type Range added in v1.3.0

type Range[T common.IntegerType] struct {
	Column   string `json:"col"`
	Operator string `json:"operator"`
	Min      T      `json:"begin"`
	Max      T      `json:"end"`
}

Range 时间范围

func (*Range[T]) Cond added in v1.3.0

func (rg *Range[T]) Cond(cond *Condition)

func (*Range[T]) HasValid added in v1.3.0

func (rg *Range[T]) HasValid() bool

type Range2 added in v1.3.40

type Range2[T common.IntegerType] struct {
	Column string `json:"col"`
	Op     string `json:"op"`
	Min    T      `json:"start"`
	Max    T      `json:"end"`
}

Range2 时间范围

func (*Range2[T]) Cond added in v1.3.40

func (rg *Range2[T]) Cond(cond *Condition)

func (*Range2[T]) HasValid added in v1.3.40

func (rg *Range2[T]) HasValid() bool

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 NewSQL added in v1.3.7

func NewSQL(from From, opts ...option.Option) *SQL

NewSQL From 表名

func (*SQL) AsChild added in v1.8.17

func (s *SQL) AsChild(as string, opts ...option.Option) From

AsChild 作为子源来使用

func (*SQL) AsSubQuery added in v1.8.22

func (s *SQL) AsSubQuery(as string) *SQL

AsSubQuery 作为子查询使用

func (*SQL) Build added in v1.3.7

func (s *SQL) Build(opts ...option.Option) string

func (*SQL) BuildOpt added in v1.8.23

func (s *SQL) BuildOpt(opts ...option.Option) string

func (*SQL) WithGroupBy added in v1.8.14

func (s *SQL) WithGroupBy(by IBuilder) *SQL

func (*SQL) WithJoin added in v1.8.14

func (s *SQL) WithJoin(join IBuilder) *SQL

func (*SQL) WithLimit added in v1.8.12

func (s *SQL) WithLimit(limit ILimit) *SQL

func (*SQL) WithOrderBy added in v1.8.14

func (s *SQL) WithOrderBy(by IBuilder) *SQL

func (*SQL) WithSelector added in v1.8.14

func (s *SQL) WithSelector(sel ISelect) *SQL

func (*SQL) WithWhere added in v1.8.14

func (s *SQL) WithWhere(where IQuery) *SQL

type Select added in v0.5.4

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

func (*Select) Add added in v0.5.4

func (sel *Select) Add(column string) *Select

func (*Select) Build added in v1.8.9

func (sel *Select) Build(opts ...option.Option) string

func (*Select) Clone added in v1.3.6

func (sel *Select) Clone() *Select

func (*Select) Delete added in v1.3.6

func (sel *Select) Delete(column string) *Select

func (*Select) Is added in v0.5.4

func (sel *Select) Is() bool

func (*Select) Query added in v0.5.4

func (sel *Select) Query() []string

func (*Select) Value added in v0.5.4

func (sel *Select) Value() []interface{}

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

type Time added in v1.3.0

type Time struct {
	Range[int64]
}

Time 时间范围

func (*Time) Adjust added in v1.3.0

func (t *Time) Adjust()

func (*Time) HasValid added in v1.4.3

func (t *Time) HasValid() bool

func (*Time) RangeLegal added in v1.3.0

func (t *Time) RangeLegal(legal int64)

type Time2 added in v1.3.39

type Time2 struct {
	TimCol string `form:"time_col" json:"time_col"`
	TimOp  string `form:"time_op" json:"time_op"`
	Start  int64  `form:"start" json:"start"`
	End    int64  `form:"end" json:"end"`
}

func (*Time2) Adjust added in v1.3.39

func (t *Time2) Adjust()

func (*Time2) BuildCond added in v1.8.34

func (t *Time2) BuildCond(cond *Condition)

func (*Time2) HasValid added in v1.3.39

func (t *Time2) HasValid() bool

func (*Time2) RangeLegal added in v1.3.39

func (t *Time2) RangeLegal(legal int64)

Jump to

Keyboard shortcuts

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