wrapper

package
v1.3.50 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: Zlib Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Eq   = "= ? "
	NEq  = "<> ? "
	Lt   = "< ? "
	LtEq = "<= ? "
	Gt   = "> ? "
	GtEq = ">= ? "

	In      = "IN ? "
	Like    = "LIKE ? "
	Between = "BETWEEN ? AND ? "
	And     = "AND"
	Or      = "OR"
)

Operate

View Source
const (
	KIgOrderBy = 0x01
	KIgLimit   = 0x02
	KIgOffset  = 0x04
	KIgAll     = 0xffff
)
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

This section is empty.

Functions

func ANDCompose added in v1.3.15

func ANDCompose[T ComposeType](cond *Condition, column string, ac *Array[T])

func AddSQLFunc added in v1.3.8

func AddSQLFunc(flag int, fn string)

func IN added in v1.3.31

func IN[T ComposeType](cond *Condition, column string, ac *Array[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(v string) string

MLike %?%

func ORCompose added in v1.3.15

func ORCompose[T ComposeType](cond *Condition, column string, ac *Array[T])

func PLike added in v1.2.16

func PLike(v string) string

PLike %?

func SLike added in v1.2.16

func SLike(v string) string

SLike ?%

func SQLFunc added in v1.3.8

func SQLFunc(flag int) string

Types

type Array added in v1.3.34

type Array[T ComposeType] struct {
	Size  int
	Value []T
}

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) 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) 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"`
	As     string `form:"-" json:"-"`
	Desc   bool   `form:"desc" json:"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(newCol string) *Column

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() []string

func (*Column) SetColumn added in v1.2.26

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

func (*Column) Sql added in v1.2.26

func (col *Column) Sql(convert ColumnConvert) 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 ColumnConvert added in v1.3.24

type ColumnConvert func(col string) string

type ComposeType added in v1.3.0

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

type Condition

type Condition struct {
	Ignore  int
	Limit   Limit
	Offset  int
	OrderBy string
	// 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) AndGtEq added in v0.5.1

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

func (*Condition) AndLt added in v0.5.1

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

func (*Condition) AndLtEq added in v0.5.1

func (sq *Condition) AndLtEq(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) 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) ModifierF added in v0.5.39

func (sq *Condition) ModifierF(f string, m ...interface{}) *Condition

func (*Condition) NEq

func (sq *Condition) NEq(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) OrGtEq added in v0.5.1

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

func (*Condition) OrLt added in v0.5.1

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

func (*Condition) OrLtEq added in v0.5.1

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

func (*Condition) OrNEq added in v0.5.1

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

func (*Condition) Order added in v1.2.26

func (sq *Condition) Order(by string) *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) Sql added in v1.2.26

func (sq *Condition) Sql(full bool) string

func (*Condition) Value

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

func (*Condition) Values

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

func (*Condition) WithIgnore added in v1.3.11

func (sq *Condition) WithIgnore(ig int) *Condition

func (*Condition) WithLimit added in v1.3.11

func (sq *Condition) WithLimit(value Limit) *Condition

func (*Condition) WithOffset added in v1.3.11

func (sq *Condition) WithOffset(offset int) *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"`
}

type GroupBy added in v1.3.7

type GroupBy []*Column

func (GroupBy) Check added in v1.3.7

func (ob GroupBy) Check(filters []FField)

func (GroupBy) Sql added in v1.3.7

func (ob GroupBy) Sql(full bool, convert ColumnConvert) string

type ICond added in v1.3.0

type ICond interface {
	HasValid() error
	Decode(cond string) ICond
	Cond(cond *Condition) ICond
	OrderBy(full bool) string
}

type IModel added in v1.3.2

type IModel interface {
	Clone() IModel
	Model() interface{}
	Set(key string, v interface{})
}

type IQuery added in v0.5.4

type IQuery interface {
	Is() bool
	Query() string
	Value() []interface{}
	Sql(full bool) string
}

type ISelect added in v0.5.4

type ISelect interface {
	Is() bool
	Query() []string
	Value() []interface{}
	Sql(full bool) string
}

type Limit added in v1.2.26

type Limit struct {
	Offset int
	Limit  int
}

type NewCondFunc added in v1.3.0

type NewCondFunc func() ICond

type NewModelFunc added in v1.3.0

type NewModelFunc func() IModel

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option overrides behavior of Connect.

func With

func With(name string, value interface{}) Option

func WithId

func WithId(value interface{}) Option

type OptionFunc

type OptionFunc func(*Options)

type Options

type Options struct {
	Query map[string]interface{}
}

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) Check added in v1.2.26

func (ob OrderBy) Check(filters []FField)

func (OrderBy) Sql added in v1.2.26

func (ob OrderBy) Sql(full bool, convert ColumnConvert) string

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 {
	// contains filtered or unexported fields
}

func NewSQL added in v1.3.7

func NewSQL(selector ISelect, from string) *SQL

func (*SQL) AS added in v1.3.7

func (s *SQL) AS(table string) *SQL

func (*SQL) Build added in v1.3.7

func (s *SQL) Build() string

func (*SQL) GroupBy added in v1.3.7

func (s *SQL) GroupBy(by string) *SQL

func (*SQL) Where added in v1.3.7

func (s *SQL) Where(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) 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) Sql added in v1.3.7

func (sel *Select) Sql(full bool) string

func (*Select) Value added in v0.5.4

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

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) 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) Cond added in v1.3.39

func (t *Time2) Cond(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