Documentation ¶
Overview ¶
Package gplus is wrap for gorm
Index ¶
- func As(columnName any, asName any) string
- func Begin(opts ...*sql.TxOptions) *gorm.DB
- func Cache(models ...any)
- func Delete[T any](q *QueryCond[T], opts ...OptionFunc) *gorm.DB
- func DeleteById[T any](id any, opts ...OptionFunc) *gorm.DB
- func DeleteByIds[T any](ids any, opts ...OptionFunc) *gorm.DB
- func ExcSQL(querySQL string, opts ...OptionFunc) *gorm.DB
- func Exists[T any](q *QueryCond[T], opts ...OptionFunc) (bool, error)
- func GetModel[T any]() *T
- func Init(db *gorm.DB)
- func Insert[T any](entity *T, opts ...OptionFunc) *gorm.DB
- func InsertBatch[T any](entities []*T, opts ...OptionFunc) *gorm.DB
- func InsertBatchSize[T any](entities []*T, batchSize int, opts ...OptionFunc) *gorm.DB
- func LikeLeft(query *QueryCond[any], name string, value any)
- func LikeRight(query *QueryCond[any], name string, value any)
- func Pluck[T any, R any](column string, q *QueryCond[T], opts ...OptionFunc) ([]R, *gorm.DB)
- func PluckDistinct[T any, R any](column string, q *QueryCond[T], opts ...OptionFunc) ([]R, *gorm.DB)
- func SelectById[T any](id any, opts ...OptionFunc) (*T, *gorm.DB)
- func SelectByIdGeneric[T any, R any](id any, opts ...OptionFunc) (*R, *gorm.DB)
- func SelectByIds[T any](ids any, opts ...OptionFunc) ([]*T, *gorm.DB)
- func SelectCount[T any](q *QueryCond[T], opts ...OptionFunc) (int64, *gorm.DB)
- func SelectGeneric[T any, R any](q *QueryCond[T], opts ...OptionFunc) (R, *gorm.DB)
- func SelectList[T any](q *QueryCond[T], opts ...OptionFunc) ([]*T, *gorm.DB)
- func SelectListBySQL[R any](querySQL string, opts ...OptionFunc) ([]*R, *gorm.DB)
- func SelectListGeneric[T any, R any](q *QueryCond[T], opts ...OptionFunc) ([]*R, *gorm.DB)
- func SelectOne[T any](q *QueryCond[T], opts ...OptionFunc) (*T, *gorm.DB)
- func SelectOneBySQL[R any](countSQL string, opts ...OptionFunc) (R, *gorm.DB)
- func Tx(txFunc func(tx *gorm.DB) error, opts ...OptionFunc) error
- func Update[T any](q *QueryCond[T], opts ...OptionFunc) *gorm.DB
- func UpdateById[T any](entity *T, opts ...OptionFunc) *gorm.DB
- func UpdateZeroById[T any](entity *T, opts ...OptionFunc) *gorm.DB
- type Comparable
- type Condition
- type Dao
- type Function
- func (f *Function) As(asName any) string
- func (f *Function) Between(start int64, end int64) (string, int64, int64)
- func (f *Function) Eq(value int64) (string, int64)
- func (f *Function) Ge(value int64) (string, int64)
- func (f *Function) Gt(value int64) (string, int64)
- func (f *Function) In(values ...any) (string, []any)
- func (f *Function) Le(value int64) (string, int64)
- func (f *Function) Lt(value int64) (string, int64)
- func (f *Function) Ne(value int64) (string, int64)
- func (f *Function) NotBetween(start int64, end int64) (string, int64, int64)
- func (f *Function) NotIn(values ...any) (string, []any)
- type Option
- type OptionFunc
- type Page
- type QueryCond
- func (q *QueryCond[T]) AddAndStrCond(cond string) *QueryCond[T]
- func (q *QueryCond[T]) AddOrStrCond(cond string) *QueryCond[T]
- func (q *QueryCond[T]) And(fn ...func(q *QueryCond[T])) *QueryCond[T]
- func (q *QueryCond[T]) AndCond(cond bool, fn ...func(q *QueryCond[T])) *QueryCond[T]
- func (q *QueryCond[T]) AndEqCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndGeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndGtCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndInCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndLeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndLikeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndLikeLeftCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndLikeRightCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndLtCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndNeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndNotLikeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndNotLikeLeftCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) AndNotLikeRightCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) Between(column any, start, end any) *QueryCond[T]
- func (q *QueryCond[T]) Case(isTrue bool, handleFunc func()) *QueryCond[T]
- func (q *QueryCond[T]) Distinct(columns ...any) *QueryCond[T]
- func (q *QueryCond[T]) Eq(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) EqCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) Ge(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) GeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) Group(columns ...any) *QueryCond[T]
- func (q *QueryCond[T]) Gt(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) GtCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) Having(having string, args ...any) *QueryCond[T]
- func (q *QueryCond[T]) In(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) InCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) IsNotNull(column any) *QueryCond[T]
- func (q *QueryCond[T]) IsNull(column any) *QueryCond[T]
- func (q *QueryCond[T]) Le(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) LeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) Like(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) LikeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) LikeLeft(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) LikeLeftCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) LikeRight(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) LikeRightCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) Lt(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) LtCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) Ne(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) NeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) NotBetween(column any, start, end any) *QueryCond[T]
- func (q *QueryCond[T]) NotIn(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) NotLike(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) NotLikeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) NotLikeLeft(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) NotLikeLeftCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) NotLikeRight(column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) NotLikeRightCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) Omit(columns ...any) *QueryCond[T]
- func (q *QueryCond[T]) Or(fn ...func(q *QueryCond[T])) *QueryCond[T]
- func (q *QueryCond[T]) OrCond(cond bool, fn ...func(q *QueryCond[T])) *QueryCond[T]
- func (q *QueryCond[T]) OrEqCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrGeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrGtCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrInCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrLeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrLikeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrLikeLeftCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrLikeRightCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrLtCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrNeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrNotLikeCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrNotLikeLeftCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrNotLikeRightCond(cond bool, column any, val any) *QueryCond[T]
- func (q *QueryCond[T]) OrderByAsc(columns ...any) *QueryCond[T]
- func (q *QueryCond[T]) OrderByDesc(columns ...any) *QueryCond[T]
- func (q *QueryCond[T]) Reset() *QueryCond[T]
- func (q *QueryCond[T]) Select(columns ...any) *QueryCond[T]
- func (q *QueryCond[T]) Set(column any, val any) *QueryCond[T]
- type SQLSegment
- type StreamingPage
- func NewStreamingPage[T any, V Comparable](columnName any, startValue V, limit int) *StreamingPage[T, V]
- func SelectStreamingPage[T any, V Comparable](page *StreamingPage[T, V], q *QueryCond[T], opts ...OptionFunc) (*StreamingPage[T, V], *gorm.DB)
- func SelectStreamingPageGeneric[T any, R any, V Comparable](page *StreamingPage[R, V], q *QueryCond[T], opts ...OptionFunc) (*StreamingPage[R, V], *gorm.DB)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteByIds ¶
func DeleteByIds[T any](ids any, opts ...OptionFunc) *gorm.DB
DeleteByIds 根据 ID 批量删除记录
func ExcSQL ¶ added in v0.0.6
func ExcSQL(querySQL string, opts ...OptionFunc) *gorm.DB
ExcSQL 按任意SQL执行,返回影响的行
func Exists ¶
func Exists[T any](q *QueryCond[T], opts ...OptionFunc) (bool, error)
Exists 根据条件判断记录是否存在
func InsertBatch ¶
func InsertBatch[T any](entities []*T, opts ...OptionFunc) *gorm.DB
InsertBatch 批量插入多条记录
func InsertBatchSize ¶
func InsertBatchSize[T any](entities []*T, batchSize int, opts ...OptionFunc) *gorm.DB
InsertBatchSize 批量插入多条记录
func PluckDistinct ¶
func PluckDistinct[T any, R any](column string, q *QueryCond[T], opts ...OptionFunc) ([]R, *gorm.DB)
PluckDistinct 取某列值,去重
func SelectById ¶
func SelectById[T any](id any, opts ...OptionFunc) (*T, *gorm.DB)
SelectById 根据 ID 查询单条记录
func SelectByIdGeneric ¶
SelectByIdGeneric 查询时,转化为其他类型 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体
func SelectByIds ¶
func SelectByIds[T any](ids any, opts ...OptionFunc) ([]*T, *gorm.DB)
SelectByIds 根据 ID 查询多条记录
func SelectCount ¶
SelectCount 根据条件查询记录数量
func SelectGeneric ¶
SelectGeneric 根据传入的泛型封装记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体
func SelectList ¶
func SelectList[T any](q *QueryCond[T], opts ...OptionFunc) ([]*T, *gorm.DB)
SelectList 根据条件查询多条记录
func SelectListBySQL ¶ added in v0.0.6
func SelectListBySQL[R any](querySQL string, opts ...OptionFunc) ([]*R, *gorm.DB)
SelectListBySQL 按任意SQL执行,指定返回类型数组
func SelectListGeneric ¶
SelectListGeneric 根据条件查询多条记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体
func SelectOne ¶
func SelectOne[T any](q *QueryCond[T], opts ...OptionFunc) (*T, *gorm.DB)
SelectOne 根据条件查询单条记录
func SelectOneBySQL ¶ added in v0.0.6
func SelectOneBySQL[R any](countSQL string, opts ...OptionFunc) (R, *gorm.DB)
SelectOneBySQL 根据原始的SQL语句,取一个
func UpdateById ¶
func UpdateById[T any](entity *T, opts ...OptionFunc) *gorm.DB
UpdateById 根据 ID 更新,默认零值不更新
func UpdateZeroById ¶
func UpdateZeroById[T any](entity *T, opts ...OptionFunc) *gorm.DB
UpdateZeroById 根据 ID 零值更新
Types ¶
type Comparable ¶ added in v0.0.4
type Comparable interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | time.Time }
Comparable 可比较的接口
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
func (*Function) NotBetween ¶
type OptionFunc ¶
type OptionFunc func(*Option)
OptionFunc 是 option指令的函数
func IgnoreTotal ¶
func IgnoreTotal() OptionFunc
IgnoreTotal 分页查询忽略总数 issue: https://github.com/aixj1984/gorm-plus/issues/37
type Page ¶
type Page[T any] struct { Current int `json:"page"` // 页码 Size int `json:"pageSize"` // 每页大小 Total int64 `json:"total"` Records []*T `json:"list"` CurTime int64 `json:"curTime"` // 当前时间,毫秒 RecordsMap []T `json:"listMap"` }
Page 分页查询结构
func SelectPage ¶
SelectPage 根据条件分页查询记录
func SelectPageGeneric ¶
func SelectPageGeneric[T any, R any](page *Page[R], q *QueryCond[T], opts ...OptionFunc) (*Page[R], *gorm.DB)
SelectPageGeneric 根据传入的泛型封装分页记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体
type QueryCond ¶
type QueryCond[T any] struct { // contains filtered or unexported fields }
func BuildQuery ¶ added in v0.0.3
BuildQuery 编译查询
func NewQueryModel ¶
NewQueryModel 构建查询条件
func (*QueryCond[T]) AddAndStrCond ¶ added in v0.0.4
AddAndStrCond 执行增加AND条件
func (*QueryCond[T]) AddOrStrCond ¶ added in v0.0.4
AddOrStrCond 执行增加OR条件
func (*QueryCond[T]) AndLikeCond ¶ added in v0.0.4
AndLikeCond 并且模糊 LIKE '%值%'
func (*QueryCond[T]) AndLikeLeftCond ¶ added in v0.0.4
AndLikeLeftCond 并且左模糊 LIKE '%值'
func (*QueryCond[T]) AndLikeRightCond ¶ added in v0.0.4
AndLikeRightCond 并且右模糊 LIKE '值%'
func (*QueryCond[T]) AndNotLikeCond ¶ added in v0.0.4
AndNotLikeCond 并且非模糊 NOT LIKE '%值%'
func (*QueryCond[T]) AndNotLikeLeftCond ¶ added in v0.0.4
AndNotLikeLeftCond 并且非左模糊 NOT LIKE '%值'
func (*QueryCond[T]) AndNotLikeRightCond ¶ added in v0.0.4
AndNotLikeRightCond 并且非右模糊 NOT LIKE '值%'
func (*QueryCond[T]) LikeLeftCond ¶ added in v0.0.3
LikeLeftCond 左模糊 LIKE '%值'
func (*QueryCond[T]) LikeRightCond ¶ added in v0.0.3
LikeRightCond 右模糊 LIKE '值%'
func (*QueryCond[T]) NotBetween ¶
NotBetween NOT BETWEEN 值1 AND 值2
func (*QueryCond[T]) NotLikeCond ¶ added in v0.0.3
NotLikeCond 非模糊 NOT LIKE '%值%'
func (*QueryCond[T]) NotLikeLeft ¶ added in v0.0.3
NotLikeLeft 非左模糊 NOT LIKE '%值'
func (*QueryCond[T]) NotLikeLeftCond ¶ added in v0.0.3
NotLikeLeftCond 非左模糊 NOT LIKE '%值'
func (*QueryCond[T]) NotLikeRight ¶ added in v0.0.3
NotLikeRight 非右模糊 NOT LIKE '值%'
func (*QueryCond[T]) NotLikeRightCond ¶ added in v0.0.3
NotLikeRightCond 非右模糊 NOT LIKE '值%'
func (*QueryCond[T]) OrLikeCond ¶ added in v0.0.4
OrLikeCond 或者模糊 LIKE '%值%'
func (*QueryCond[T]) OrLikeLeftCond ¶ added in v0.0.4
OrLikeLeftCond 或者左模糊 LIKE '%值'
func (*QueryCond[T]) OrLikeRightCond ¶ added in v0.0.4
OrLikeRightCond 或者右模糊 LIKE '值%'
func (*QueryCond[T]) OrNotLikeCond ¶ added in v0.0.4
OrNotLikeCond 或者非模糊 NOT LIKE '%值%'
func (*QueryCond[T]) OrNotLikeLeftCond ¶ added in v0.0.4
OrNotLikeLeftCond 或者非左模糊 NOT LIKE '%值'
func (*QueryCond[T]) OrNotLikeRightCond ¶ added in v0.0.4
OrNotLikeRightCond 或者非右模糊 NOT LIKE '值%'
func (*QueryCond[T]) OrderByAsc ¶
OrderByAsc 排序:ORDER BY 字段1,字段2 ASC
func (*QueryCond[T]) OrderByDesc ¶
OrderByDesc 排序:ORDER BY 字段1,字段2 Desc
type SQLSegment ¶ added in v0.0.6
type SQLSegment interface {
// contains filtered or unexported methods
}
type StreamingPage ¶ added in v0.0.4
type StreamingPage[T any, V Comparable] struct { ColumnName any `json:"columnName"` // 进行分页的列字段名称 StartValue V `json:"startValue"` // 分页起始值 Limit int `json:"limit"` // 页大小 Forward bool `json:"forward"` // 上下页翻页标识 Total int64 `json:"total"` // 总记录数 Records []*T `json:"records"` // 查询记录 RecordsMap []T `json:"recordsMap"` // 查询记录Map }
StreamingPage 流式分页查询结构
func NewStreamingPage ¶ added in v0.0.4
func NewStreamingPage[T any, V Comparable](columnName any, startValue V, limit int) *StreamingPage[T, V]
NewStreamingPage 流式分页查询
func SelectStreamingPage ¶ added in v0.0.4
func SelectStreamingPage[T any, V Comparable](page *StreamingPage[T, V], q *QueryCond[T], opts ...OptionFunc) (*StreamingPage[T, V], *gorm.DB)
SelectStreamingPage 根据条件分页查询记录
func SelectStreamingPageGeneric ¶ added in v0.0.4
func SelectStreamingPageGeneric[T any, R any, V Comparable](page *StreamingPage[R, V], q *QueryCond[T], opts ...OptionFunc) (*StreamingPage[R, V], *gorm.DB)
SelectStreamingPageGeneric 根据传入的泛型封装分页记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体