Documentation
¶
Index ¶
- Variables
- func DefaultModel[model Modeler](db *gorm.DB, attrs ...ModelAttributer) *gorm.DB
- type ArSQLConnection
- type ArSQLSetting
- type AttrDistinct
- type AttrJoins
- type AttrPreload
- type AttrSelect
- type AttrTable
- 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 PGConnection
- type PGPool
- type PGSetting
- type Query
- type SQLServerConnection
- type SQLServerPool
- type SQLServerSetting
Constants ¶
This section is empty.
Variables ¶
View Source
var APP struct { MySQLPool MySQLPool PGPool PGPool SQLServerPool SQLServerPool DBSetting DBSetting Finder Finder }
Functions ¶
func DefaultModel ¶
Types ¶
type ArSQLConnection ¶ added in v1.53.3
type ArSQLSetting ¶ added in v1.53.3
type ArSQLSetting struct {
Database string `yaml:"database"`
Rws bool `yaml:"rws"`
Main *MySQLConnection `yaml:"main"`
Sources map[string]*ArSQLConnection `yaml:"sources"`
Replicas map[string]*ArSQLConnection `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(preloads ...string) *AttrPreload
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 ¶ added in v1.53.3
type DBSetting struct {
Common *Common `yaml:"common,omitempty"`
MySql *MySQLSetting `yaml:"mysql,omitempty"`
Postgres *PGSetting `yaml:"postgres,omitempty"`
SqlServer *SQLServerSetting `yaml:"sql-server,omitempty"`
CbitSql *ArSQLSetting `yaml:"ar-sql,omitempty"`
}
func (*DBSetting) ExampleYaml ¶ added in v1.53.3
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
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 []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 GORMPool ¶ added in v1.53.3
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 ¶ added in v1.53.3
type MySQLPool ¶ added in v1.53.3
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 ¶ added in v1.53.3
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 PGConnection ¶ added in v1.53.3
type PGPool ¶ added in v1.53.3
type PGPool struct {
// contains filtered or unexported fields
}
var ( PostgresDsnFormat = "host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s" PostgresPoolApp PGPool )
type PGSetting ¶ added in v1.53.3
type PGSetting struct {
Main *PGConnection `yaml:"main"`
}
type Query ¶ added in v1.51.22
type Query struct {
Option *string `json:"option,omitempty"` // 操作:and、or、not
Conditions []Condition `json:"conditions,omitempty"` // 条件
}
Query 查询
type SQLServerConnection ¶ added in v1.53.3
type SQLServerPool ¶ added in v1.53.3
type SQLServerPool struct {
// contains filtered or unexported fields
}
var ( SqlServerDsnFormat = "sqlserver://%s:%s@%s:?%d?database=%s" SqlServerPoolApp SQLServerPool )
func (*SQLServerPool) GetConn ¶ added in v1.53.3
func (my *SQLServerPool) GetConn() *gorm.DB
GetConn 获取主数据库链接
func (*SQLServerPool) Once ¶ added in v1.53.3
func (*SQLServerPool) Once(dbSetting *DBSetting) GORMPool
type SQLServerSetting ¶ added in v1.53.3
type SQLServerSetting struct {
Main *SQLServerConnection `yaml:"main"`
}
Click to show internal directories.
Click to hide internal directories.