Documentation
¶
Index ¶
- Variables
- func DefaultModel[model Modeler](db *gorm.DB, attrs ...ModelAttributer) *gorm.DB
- type AttrDistinct
- type AttrJoins
- type AttrPreload
- type AttrSelect
- type AttrTable
- type CbitSqlConnection
- type CbitSqlSetting
- type Common
- type Condition
- type DbSetting
- type Dsn
- type Finder
- func (my *Finder) Ex(functions ...func(db *gorm.DB)) *Finder
- func (my *Finder) Find(ret any, preloads ...string) *Finder
- func (my *Finder) FindOnlyCondition(finderCondition *FinderCondition, ret any) *Finder
- func (my *Finder) FindUseCondition(finderCondition *FinderCondition, page, size int, ret any) *Finder
- func (my *Finder) FindUseMap(queries map[string][]any, preloads []string, orders []string, page, size int, ...) *Finder
- func (my *Finder) GetDB() *gorm.DB
- func (my *Finder) GetTotal() int64
- func (*Finder) New(db *gorm.DB) *Finder
- func (my *Finder) QueryUseCondition(finderCondition *FinderCondition) *Finder
- func (my *Finder) QueryUseMap(queries map[string][]any) *Finder
- func (my *Finder) SetTotal(total int64) *Finder
- func (my *Finder) Transaction(functions ...func(db *gorm.DB)) error
- func (my *Finder) TryOrder(orders ...string) *Finder
- func (my *Finder) TryPagination(page, size int) *Finder
- func (my *Finder) TryPreload(preloads ...string) *Finder
- func (my *Finder) TryQuery(mode string, fieldName string, values ...any)
- func (my *Finder) When(condition bool, query any, args ...any) *Finder
- func (my *Finder) WhenBetween(condition bool, query any, args ...any) *Finder
- func (my *Finder) WhenFunc(condition bool, fn func(db *gorm.DB)) *Finder
- func (my *Finder) WhenIn(condition bool, query any, args any) *Finder
- func (my *Finder) WhenInPtr(condition bool, query any, args any) *Finder
- func (my *Finder) WhenLike(condition bool, query, arg any) *Finder
- func (my *Finder) WhenLikeLeft(condition bool, query, arg any) *Finder
- func (my *Finder) WhenLikeRight(condition bool, query, arg any) *Finder
- func (my *Finder) WhenNotBetween(condition bool, query any, args ...any) *Finder
- func (my *Finder) WhenNotIn(condition bool, query any, args any) *Finder
- func (my *Finder) WhenNotInPtr(condition bool, query any, args any) *Finder
- type FinderCondition
- type GormPool
- type ModelAttributer
- type Modeler
- type MySqlConnection
- type MySqlPool
- type MySqlSetting
- type PostgresConnection
- type PostgresPool
- type PostgresSetting
- type SqlServerConnection
- type SqlServerPool
- type SqlServerSetting
Constants ¶
This section is empty.
Variables ¶
View Source
var APP struct { MySqlPool MySqlPool PostgresPool PostgresPool SqlServerPool SqlServerPool DBSetting DbSetting Finder Finder }
Functions ¶
func DefaultModel ¶
Types ¶
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(preloads ...string) *AttrPreload
type AttrSelect ¶
type AttrSelect struct {
// contains filtered or unexported fields
}
func Select ¶
func Select(query any, args ...any) *AttrSelect
type CbitSqlConnection ¶
type CbitSqlSetting ¶
type CbitSqlSetting struct {
Database string `yaml:"database"`
Rws bool `yaml:"rws"`
Main *MySqlConnection `yaml:"main"`
Sources map[string]*CbitSqlConnection `yaml:"sources"`
Replicas map[string]*CbitSqlConnection `yaml:"replicas"`
}
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 *PostgresSetting `yaml:"postgres,omitempty"`
SqlServer *SqlServerSetting `yaml:"sqlServer,omitempty"`
CbitSql *CbitSqlSetting `yaml:"cbitSql,omitempty"`
}
var DbSettingApp DbSetting
func (*DbSetting) ExampleYaml ¶
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
Finder 查询帮助器
var FinderApp Finder
func DefaultFinder ¶
func DefaultFinder[model Modeler](db *gorm.DB, attrs ...ModelAttributer) *Finder
func (*Finder) FindOnlyCondition ¶
func (my *Finder) FindOnlyCondition(finderCondition *FinderCondition, ret any) *Finder
FindOnlyCondition 自动填充查询条件并查询:使用FinderCondition
func (*Finder) FindUseCondition ¶
func (my *Finder) FindUseCondition(finderCondition *FinderCondition, page, size int, ret any) *Finder
FindUseCondition 自动填充查询条件并查询:使用FinderCondition
func (*Finder) FindUseMap ¶
func (my *Finder) FindUseMap(queries map[string][]any, preloads []string, orders []string, page, size int, ret any) *Finder
FindUseMap 自动填充查询条件并查询:使用map[string][]any
func (*Finder) QueryUseCondition ¶
func (my *Finder) QueryUseCondition(finderCondition *FinderCondition) *Finder
QueryUseCondition 从请求体中获取查询条件
func (*Finder) QueryUseMap ¶
QueryUseMap 从map中解析参数并查询
func (*Finder) Transaction ¶
Transaction 执行一组数据库事务操作 参数 funcs 为需要在事务中执行的函数切片,每个函数接收一个 *gorm.DB 参数 如果任一函数执行出错,将回滚整个事务并返回错误 所有函数执行成功后提交事务 返回 error,nil 表示事务执行成功,非 nil 表示事务执行失败
func (*Finder) TryPagination ¶
TryPagination 尝试分页
func (*Finder) TryPreload ¶
TryPreload 尝试深度查询
func (*Finder) WhenBetween ¶
WhenBetween 当条件满足时执行:where between
func (*Finder) WhenLikeLeft ¶
WhenLikeLeft 当条件满足时执行:like %?
func (*Finder) WhenLikeRight ¶
WhenLikeRight 当条件满足时执行:like ?%
func (*Finder) WhenNotBetween ¶
WhenNotBetween 当条件满足时执行:where not between
type FinderCondition ¶
type FinderCondition struct {
Table *string `json:"table,omitempty"`
Queries []struct {
Option *string `json:"option,omitempty"` // 操作:and、or、not
Conditions []Condition `json:"conditions,omitempty"` // 条件
} `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 GormPool ¶
type GormPool interface {
GetConn() *gorm.DB
Close() error
// contains filtered or unexported methods
}
func OncePostgresPool ¶
OncePostgresPool 单例化:postgres链接池
func OnceSqlServerPool ¶
OnceSqlServerPool 单例化:sql server连接池
type ModelAttributer ¶
type MySqlConnection ¶
type MySqlPool ¶
type MySqlPool struct {
// contains filtered or unexported fields
}
var ( MySqlDsnFormat = "%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local" MySqlPoolApp MySqlPool )
type MySqlSetting ¶
type MySqlSetting struct {
Database string `yaml:"database"`
Charset string `yaml:"charset"`
Collation string `yaml:"collation"`
Rws bool `yaml:"rws"`
Main *MySqlConnection `yaml:"main"`
Sources map[string]*MySqlConnection `yaml:"sources"`
Replicas map[string]*MySqlConnection `yaml:"replicas"`
}
type PostgresConnection ¶
type PostgresPool ¶
type PostgresPool struct {
// contains filtered or unexported fields
}
var ( PostgresDsnFormat = "host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s" PostgresPoolApp PostgresPool )
func (*PostgresPool) Once ¶
func (*PostgresPool) Once(dbSetting *DbSetting) GormPool
type PostgresSetting ¶
type PostgresSetting struct {
Main *PostgresConnection `yaml:"main"`
}
type SqlServerConnection ¶
type SqlServerPool ¶
type SqlServerPool struct {
// contains filtered or unexported fields
}
var ( SqlServerDsnFormat = "sqlserver://%s:%s@%s:?%d?database=%s" SqlServerPoolApp SqlServerPool )
func (*SqlServerPool) Once ¶
func (*SqlServerPool) Once(dbSetting *DbSetting) GormPool
type SqlServerSetting ¶
type SqlServerSetting struct {
Main *SqlServerConnection `yaml:"main"`
}
Click to show internal directories.
Click to hide internal directories.