Documentation
¶
Index ¶
- Variables
- func Exist(tx *gorm.DB, query any, args ...any) (exist bool, err error)
- func SaveOrCreate(tx *gorm.DB, data Modeler, query any, args ...any) (err error)
- func ToModel[model Modeler](db *gorm.DB, attrs ...ModelAttr) *gorm.DB
- func UpdateColumnsOrCreate(tx *gorm.DB, data Modeler, updates any, query any, args ...any) (err error)
- func UpdatesOrCreate(tx *gorm.DB, data Modeler, updates any, query any, args ...any) (err error)
- type ArSQLEndpoint
- type ArSQLSetting
- type AttrDistinct
- type AttrJoins
- type AttrPreload
- type AttrPreloadMap
- type AttrSelect
- type AttrTable
- type Common
- type Condition
- type DBSetting
- type DSN
- type Finder
- type FinderCondition
- type FinderImpl
- func (my *FinderImpl) Ex(functions ...func(db *gorm.DB)) Finder
- func (my *FinderImpl) Find(ret any, preloads ...string) Finder
- func (my *FinderImpl) FindOnlyCondition(finderCondition *FinderCondition, ret any) Finder
- func (my *FinderImpl) FindUseCondition(finderCondition *FinderCondition, page, size int, ret any) Finder
- func (my *FinderImpl) FindUseMap(queries map[string][]any, preloads []string, orders []string, page, size int, ...) Finder
- func (my *FinderImpl) GetDB() *gorm.DB
- func (my *FinderImpl) GetTotal() int64
- func (my *FinderImpl) QueryUseCondition(finderCondition *FinderCondition) Finder
- func (my *FinderImpl) QueryUseMap(queries map[string][]any) Finder
- func (my *FinderImpl) SetTotal(total int64) Finder
- func (my *FinderImpl) Transaction(functions ...func(db *gorm.DB)) error
- func (my *FinderImpl) TryOrder(orders ...string) Finder
- func (my *FinderImpl) TryPagination(page, size int) Finder
- func (my *FinderImpl) TryPreload(preloads ...string) Finder
- func (my *FinderImpl) TryQuery(mode string, fieldName string, values ...any)
- func (my *FinderImpl) When(condition bool, query any, args ...any) Finder
- func (my *FinderImpl) WhenBetween(condition bool, query any, args ...any) Finder
- func (my *FinderImpl) WhenFunc(condition bool, fn func(db *gorm.DB)) Finder
- func (my *FinderImpl) WhenIn(condition bool, query any, args any) Finder
- func (my *FinderImpl) WhenInPtr(condition bool, query any, args any) Finder
- func (my *FinderImpl) WhenLike(condition bool, query, arg any) Finder
- func (my *FinderImpl) WhenLikeLeft(condition bool, query, arg any) Finder
- func (my *FinderImpl) WhenLikeRight(condition bool, query, arg any) Finder
- func (my *FinderImpl) WhenNotBetween(condition bool, query any, args ...any) Finder
- func (my *FinderImpl) WhenNotIn(condition bool, query any, args any) Finder
- func (my *FinderImpl) WhenNotInPtr(condition bool, query any, args any) Finder
- type GORMPool
- type MSSQLEndpoint
- type MSSQLSetting
- type ModelAttr
- type Modeler
- type MySQLBasic
- type MySQLEndpoint
- type MySQLSetting
- type PGEndpoint
- type PGSetting
- type Query
Constants ¶
This section is empty.
Variables ¶
var APP struct { DBSetting DBSetting }
Functions ¶
func SaveOrCreate ¶
func UpdateColumnsOrCreate ¶
Types ¶
type ArSQLEndpoint ¶
type ArSQLSetting ¶
type ArSQLSetting struct {
Database string `yaml:"database"`
Rws bool `yaml:"rws"`
Main *MySQLEndpoint `yaml:"main"`
Sources map[string]*ArSQLEndpoint `yaml:"sources"`
Replicas map[string]*ArSQLEndpoint `yaml:"replicas"`
}
type AttrDistinct ¶
type AttrDistinct struct {
// contains filtered or unexported fields
}
func Distinct ¶
func Distinct(args ...any) AttrDistinct
type AttrPreload ¶
type AttrPreload struct {
// contains filtered or unexported fields
}
func Preload ¶
func Preload(preload string, args ...any) AttrPreload
type AttrPreloadMap ¶
type AttrPreloadMap struct {
// contains filtered or unexported fields
}
func PreloadMap ¶
func PreloadMap(preloadMap map[string][]any) AttrPreloadMap
type AttrSelect ¶
type AttrSelect struct {
// contains filtered or unexported fields
}
func Select ¶
func Select(query any, args ...any) AttrSelect
type Condition ¶
type Condition struct {
Key string `json:"key"` // SQL字段名称,如果有别名则需要带有别名
Operator string `json:"operator"` // 操作符:=、>、<、!=、<=、>=、<>、in、not in、between、not between、like、like%、%like、raw、join
Values []any `json:"values"` // 查询条件值
}
Condition 查询
type DBSetting ¶
type DBSetting struct {
Common *Common `yaml:"common,omitempty"`
MySQL *MySQLSetting `yaml:"mysql,omitempty"`
Postgres *PGSetting `yaml:"postgres,omitempty"`
SQLServer *MSSQLSetting `yaml:"sql-server,omitempty"`
ArSQL *ArSQLSetting `yaml:"ar-sql,omitempty"`
}
func (*DBSetting) ExampleYaml ¶
type Finder ¶
type Finder interface {
GetDB() *gorm.DB
Find(ret any, preloads ...string) Finder
Ex(functions ...func(db *gorm.DB)) Finder
TryPagination(page, size int) Finder
TryOrder(orders ...string) Finder
TryPreload(preloads ...string) Finder
TryQuery(mode string, fieldName string, values ...any)
SetTotal(total int64) Finder
GetTotal() int64
When(condition bool, query any, args ...any) Finder
WhenIn(condition bool, query any, args any) Finder
WhenInPtr(condition bool, query any, args any) Finder
WhenNotIn(condition bool, query any, args any) Finder
WhenNotInPtr(condition bool, query any, args any) Finder
WhenBetween(condition bool, query any, args ...any) Finder
WhenNotBetween(condition bool, query any, args ...any) Finder
WhenLike(condition bool, query, arg any) Finder
WhenLikeLeft(condition bool, query, arg any) Finder
WhenLikeRight(condition bool, query, arg any) Finder
WhenFunc(condition bool, fn func(db *gorm.DB)) Finder
Transaction(functions ...func(db *gorm.DB)) error
QueryUseMap(queries map[string][]any) Finder
QueryUseCondition(finderCondition *FinderCondition) Finder
FindUseMap(queries map[string][]any, preloads []string, orders []string, page, size int, ret any) Finder
FindUseCondition(finderCondition *FinderCondition, page, size int, ret any) Finder
FindOnlyCondition(finderCondition *FinderCondition, ret any) Finder
// contains filtered or unexported methods
}
type FinderCondition ¶
type FinderCondition struct {
Table *string `json:"table,omitempty"`
Queries []Query `json:"queries,omitempty"` // 查询条件
Orders []string `json:"orders,omitempty"` // 排序
Preloads []string `json:"preloads,omitempty"` // 预加载
Page int `json:"page,omitempty"` // 页码
Limit int `json:"limit,omitempty"` // 页容量
}
FinderCondition 查询条件
type FinderImpl ¶
type FinderImpl struct {
// contains filtered or unexported fields
}
FinderImpl 查询帮助器
func (*FinderImpl) FindOnlyCondition ¶
func (my *FinderImpl) FindOnlyCondition(finderCondition *FinderCondition, ret any) Finder
FindOnlyCondition 自动填充查询条件并查询:使用FinderCondition
func (*FinderImpl) FindUseCondition ¶
func (my *FinderImpl) FindUseCondition(finderCondition *FinderCondition, page, size int, ret any) Finder
FindUseCondition 自动填充查询条件并查询:使用FinderCondition
func (*FinderImpl) FindUseMap ¶
func (my *FinderImpl) FindUseMap(queries map[string][]any, preloads []string, orders []string, page, size int, ret any) Finder
FindUseMap 自动填充查询条件并查询:使用map[string][]any
func (*FinderImpl) QueryUseCondition ¶
func (my *FinderImpl) QueryUseCondition(finderCondition *FinderCondition) Finder
QueryUseCondition 从请求体中获取查询条件
func (*FinderImpl) QueryUseMap ¶
func (my *FinderImpl) QueryUseMap(queries map[string][]any) Finder
QueryUseMap 从map中解析参数并查询
func (*FinderImpl) Transaction ¶
func (my *FinderImpl) Transaction(functions ...func(db *gorm.DB)) error
Transaction 执行一组数据库事务操作 参数 funcs 为需要在事务中执行的函数切片,每个函数接收一个 *gorm.DB 参数 如果任一函数执行出错,将回滚整个事务并返回错误 所有函数执行成功后提交事务 返回 error,nil 表示事务执行成功,非 nil 表示事务执行失败
func (*FinderImpl) TryPagination ¶
func (my *FinderImpl) TryPagination(page, size int) Finder
TryPagination 尝试分页
func (*FinderImpl) TryPreload ¶
func (my *FinderImpl) TryPreload(preloads ...string) Finder
TryPreload 尝试深度查询
func (*FinderImpl) TryQuery ¶
func (my *FinderImpl) TryQuery(mode string, fieldName string, values ...any)
TryQuery 尝试查询
func (*FinderImpl) When ¶
func (my *FinderImpl) When(condition bool, query any, args ...any) Finder
When 当条件满足时执行:where
func (*FinderImpl) WhenBetween ¶
func (my *FinderImpl) WhenBetween(condition bool, query any, args ...any) Finder
WhenBetween 当条件满足时执行:where between
func (*FinderImpl) WhenFunc ¶
func (my *FinderImpl) WhenFunc(condition bool, fn func(db *gorm.DB)) Finder
WhenFunc 当条件满足时执行:通过回调执行
func (*FinderImpl) WhenIn ¶
func (my *FinderImpl) WhenIn(condition bool, query any, args any) Finder
WhenIn 当条件满足时执行:where in
func (*FinderImpl) WhenInPtr ¶
func (my *FinderImpl) WhenInPtr(condition bool, query any, args any) Finder
WhenInPtr 当条件满足时执行:where in args 为指针类型
func (*FinderImpl) WhenLike ¶
func (my *FinderImpl) WhenLike(condition bool, query, arg any) Finder
WhenLike 当条件满足时执行:like %?%
func (*FinderImpl) WhenLikeLeft ¶
func (my *FinderImpl) WhenLikeLeft(condition bool, query, arg any) Finder
WhenLikeLeft 当条件满足时执行:like %?
func (*FinderImpl) WhenLikeRight ¶
func (my *FinderImpl) WhenLikeRight(condition bool, query, arg any) Finder
WhenLikeRight 当条件满足时执行:like ?%
func (*FinderImpl) WhenNotBetween ¶
func (my *FinderImpl) WhenNotBetween(condition bool, query any, args ...any) Finder
WhenNotBetween 当条件满足时执行:where not between
func (*FinderImpl) WhenNotIn ¶
func (my *FinderImpl) WhenNotIn(condition bool, query any, args any) Finder
WhenNotIn 当条件满足时执行:where not in
func (*FinderImpl) WhenNotInPtr ¶
func (my *FinderImpl) WhenNotInPtr(condition bool, query any, args any) Finder
WhenNotInPtr 当条件满足时执行:where in args 为指针类型
type MSSQLEndpoint ¶
type MSSQLSetting ¶
type MSSQLSetting struct {
Main *MSSQLEndpoint `yaml:"main"`
}
type MySQLBasic ¶
type MySQLBasic struct {
ID int64 `gorm:"column:id;type:bigint unsigned;primaryKey" json:"id"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:current_timestamp" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;default:current_timestamp;autoUpdateTime:true" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime;not null" json:"deleted_at"`
UUID string `gorm:"column:uuid;type:char(36);not null;unique" json:"uuid"`
}
type MySQLEndpoint ¶
type MySQLSetting ¶
type MySQLSetting struct {
Database string `yaml:"database"`
Charset string `yaml:"charset"`
Collation string `yaml:"collation"`
Rws bool `yaml:"rws"`
Main *MySQLEndpoint `yaml:"main"`
Sources map[string]MySQLEndpoint `yaml:"sources"`
Replicas map[string]MySQLEndpoint `yaml:"replicas"`
}
type PGEndpoint ¶
type PGSetting ¶
type PGSetting struct {
Main *PGEndpoint `yaml:"main"`
}