Documentation
¶
Index ¶
- Variables
- func AutoMigrate(getDB func() (value ConTable), index ...Index)
- func Check(s string) bool
- func CountByCondition(c *Con, condition map[string]interface{}) (int64, *errors.Error)
- func CountByField(c *Con, fieldName string, value interface{}) (int64, *errors.Error)
- func CountByMatch(c *Con, matchList []Match) (int64, *errors.Error)
- func Delete(c *Con, data Identifiable) *errors.Error
- func FindByCondition[T any](c *Con, condition map[string]interface{}, result *[]T, prefixes ...string) (err *errors.Error)
- func FindByField[T any](c *Con, fieldName string, value interface{}, result *[]T, prefixes ...string) (err *errors.Error)
- func FindByIDs[T any](c *Con, ids []int64, result *[]T) *errors.Error
- func FindByMatch[T any](c *Con, matchList []Match, result *[]T, prefixes ...string) (err *errors.Error)
- func FindByPage[T Identifiable](c *Con, condition map[string]interface{}, page *load.Page, ...) *errors.Error
- func FindByPageField[T Identifiable](c *Con, fieldName string, value interface{}, page *load.Page, ...) *errors.Error
- func FindByPageMatch[T Identifiable](c *Con, matchList []Match, page *load.Page, pageResp *load.PageResp, ...) *errors.Error
- func GetByCondition[T any](c *Con, condition map[string]interface{}, result *T) (err *errors.Error)
- func GetByField[T any](c *Con, fieldName string, value interface{}, result *T) (err *errors.Error)
- func GetByID[T any](c *Con, id int64, result *T) (err *errors.Error)
- func GetByMatch[T any](c *Con, matchList []Match, result *T) (err *errors.Error)
- func GetEntity[T any](entity interface{}) (*T, *errors.Error)
- func GetLastID[T Identifiable](conList []T) int64
- func GetListEntity[T any](docList any) (*[]T, *errors.Error)
- func MustGetByID[T Identifiable](c *Con, id int64, result T) *errors.Error
- func RegisterDBService(conType ConType, s DBService)
- func SaveOrUpdate(c *Con, data Identifiable, newIDs ...int64) (id int64, err *errors.Error)
- func SumByMatch(c *Con, matchList []Match, field string) (float64, *errors.Error)
- func UpdatePart(c *Con, id int64, data map[string]interface{}) *errors.Error
- func UseDbConn(dbname string) *gorm.DB
- func UseMongoDbConn(dbname string) *qmgo.Client
- type Complex
- func (c *Complex[T]) FindByPage(condition map[string]interface{}, page *load.Page, pageResp *load.PageResp, ...) *errors.Error
- func (c *Complex[T]) FindByPageField(fieldName string, value interface{}, page *load.Page, pageResp *load.PageResp, ...) *errors.Error
- func (c *Complex[T]) FindByPageMatch(matchList []Match, page *load.Page, pageResp *load.PageResp, ...) *errors.Error
- func (c *Complex[T]) GetID() ID
- func (c *Complex[T]) IsNil() bool
- func (c *Complex[T]) TableName() string
- type Con
- func (c *Con) AfterCreate(gormDB *gorm.DB) error
- func (c *Con) AfterUpdate(gormDB *gorm.DB) error
- func (c *Con) BeforeCreate(gormDB *gorm.DB) error
- func (c *Con) BeforeUpdate(gormDB *gorm.DB) error
- func (c *Con) CountByCondition(condition map[string]interface{}) (int64, *errors.Error)
- func (c *Con) CountByField(fieldName string, value interface{}) (int64, *errors.Error)
- func (c *Con) CountByMatch(matchList []Match) (int64, *errors.Error)
- func (c *Con) Delete(data Identifiable) *errors.Error
- func (c *Con) FindByCondition(condition map[string]interface{}, result *[]Identifiable, prefixes ...string) (err *errors.Error)
- func (c *Con) FindByField(fieldName string, value interface{}, result *[]Identifiable, ...) (err *errors.Error)
- func (c *Con) FindByIDs(ids []int64, result *[]Identifiable) *errors.Error
- func (c *Con) FindByMatch(matchList []Match, result *[]Identifiable, prefixes ...string) (err *errors.Error)
- func (c *Con) GenerateID() int64
- func (c *Con) GenerateId() int64
- func (c *Con) GenerateSetID()
- func (c *Con) GetByCondition(condition map[string]interface{}, result *Identifiable) (err *errors.Error)
- func (c *Con) GetByField(fieldName string, value interface{}, result Identifiable) (err *errors.Error)
- func (c *Con) GetByMatch(matchList []Match, result *Identifiable) (err *errors.Error)
- func (c *Con) GetCon() *Con
- func (c *Con) GetConType() ConType
- func (c *Con) GetDB() any
- func (c *Con) GetID() ID
- func (*Con) HandleError(tx *gorm.DB) (err *errors.Error)
- func (c *Con) HandleWithErr(err error) (error *errors.Error)
- func (c *Con) MustGetDB() (any, *errors.Error)
- func (c *Con) SaveOrUpdate(data Identifiable, newIDs ...int64) (id int64, err *errors.Error)
- func (c *Con) TableName() string
- func (c *Con) UpdatePart(id int64, data map[string]interface{}) *errors.Error
- type ConTable
- type ConType
- type Converter
- type DBService
- type ID
- type Identifiable
- type IdxType
- type Index
- type IndexFunc
- type Match
- type MatchType
- type Matches
- func (m *Matches) Add(field string, value interface{}, t MatchType, ignore ...bool) *Matches
- func (m *Matches) AddMatch(match *Match) *Matches
- func (m *Matches) AddMatches(matches *Matches) *Matches
- func (m *Matches) Eq(field string, value interface{}, ignore ...bool) *Matches
- func (m *Matches) Gt(field string, value interface{}, ignore ...bool) *Matches
- func (m *Matches) Gte(field string, value interface{}, ignore ...bool) *Matches
- func (m *Matches) In(field string, value interface{}, ignore ...bool) *Matches
- func (m *Matches) Like(field string, value string, ignore ...bool) *Matches
- func (m *Matches) Lt(field string, value interface{}, ignore ...bool) *Matches
- func (m *Matches) Lte(field string, value interface{}, ignore ...bool) *Matches
- func (m *Matches) NEmpty(field string) *Matches
- func (m *Matches) Ne(field string, value interface{}, ignore ...bool) *Matches
- func (m *Matches) Near(latFiled, lngFiled string, lat, lng, distance float64) *Matches
- func (m *Matches) NearLoc(localField string, lat, lng, distance float64) *Matches
- func (m *Matches) NotIn(field string, value interface{}, ignore ...bool) *Matches
- type Migration
- type NearMatch
- type Options
- type Result
- type Sort
- type Sorts
- type ValueField
Constants ¶
This section is empty.
Variables ¶
var GormDBServ = &gormDBService{}
var MigrationList []*Migration
var MongoDBServ = &mongoDBService{}
Functions ¶
func AutoMigrate ¶
func CountByCondition ¶
CountByCondition 根据条件查询数量
func CountByField ¶
CountByField 根据字段名称和值查询数量
func CountByMatch ¶
CountByMatch 根据条件查询数量
func FindByCondition ¶
func FindByCondition[T any](c *Con, condition map[string]interface{}, result *[]T, prefixes ...string) (err *errors.Error)
FindByCondition 根据条件查询多条记录 最多返回1000条
func FindByField ¶
func FindByField[T any](c *Con, fieldName string, value interface{}, result *[]T, prefixes ...string) (err *errors.Error)
FindByField 根据字段名称和值查询多条记录 最多返回1000条
func FindByMatch ¶
func FindByMatch[T any](c *Con, matchList []Match, result *[]T, prefixes ...string) (err *errors.Error)
FindByMatch 根据条件查询多条记录 最多返回1000条
func FindByPage ¶
func FindByPage[T Identifiable](c *Con, condition map[string]interface{}, page *load.Page, pageResp *load.PageResp, result *[]T, prefixes ...string) *errors.Error
FindByPage Condition查询分页
func FindByPageField ¶
func FindByPageField[T Identifiable](c *Con, fieldName string, value interface{}, page *load.Page, pageResp *load.PageResp, result *[]T, prefixes ...string) *errors.Error
FindByPageField FiledName查询分页
func FindByPageMatch ¶
func GetByCondition ¶
GetByCondition 根据条件查询单条记录
func GetByField ¶
GetByField 根据字段名称和值查询单条记录
func GetByMatch ¶
GetByMatch 根据条件查询单条记录
func GetLastID ¶
func GetLastID[T Identifiable](conList []T) int64
func GetListEntity ¶
GetListEntity 获取列表实体
func MustGetByID ¶
func MustGetByID[T Identifiable](c *Con, id int64, result T) *errors.Error
MustGetByID 获取单条记录
func RegisterDBService ¶
func SaveOrUpdate ¶
SaveOrUpdate 新增或者根据id更新
func SumByMatch ¶
SumByMatch 根据条件查询总和
func UpdatePart ¶
UpdatePart 根据ID更新部分字段
func UseMongoDbConn ¶
Types ¶
type Complex ¶
func UseComplex ¶
func (*Complex[T]) FindByPage ¶
func (c *Complex[T]) FindByPage(condition map[string]interface{}, page *load.Page, pageResp *load.PageResp, prefixes ...string) *errors.Error
FindByPage Condition查询分页
func (*Complex[T]) FindByPageField ¶
func (c *Complex[T]) FindByPageField(fieldName string, value interface{}, page *load.Page, pageResp *load.PageResp, prefixes ...string) *errors.Error
FindByPageField FiledName查询分页
func (*Complex[T]) FindByPageMatch ¶
type Con ¶
type Con struct {
ID int64 `gorm:"primaryKey" bson:"id" json:"id"`
ConType `gorm:"-" bson:"-" json:"-"`
*gorm.DB `gorm:"-" bson:"-" json:"-"`
MDB *qmgo.Client `gorm:"-" bson:"-" json:"-"`
DBName string `gorm:"-" bson:"-" json:"-"`
GTable string `gorm:"-" bson:"-" json:"-"`
Sort Sorts `gorm:"-" bson:"-" json:"-"`
SaveCreateTime func() `gorm:"-" bson:"-" json:"-"`
SaveUpdateTime func() `gorm:"-" bson:"-" json:"-"`
}
func (*Con) BeforeUpdate ¶
BeforeUpdate BeforeUpdate、BeforeSave 函数都会因为 更新类的操作而被触发 如果baseModel 和 普通业务 model 都想使用回调函数,那么请设置不同的回调函数名,例如:这里设置 BeforeUpdate、普通业务model 设置 BeforeSave 即可
func (*Con) CountByCondition ¶
CountByCondition 根据条件查询数量
func (*Con) CountByField ¶
CountByField 根据字段名称和值查询数量
func (*Con) CountByMatch ¶
CountByMatch 根据条件查询数量
func (*Con) FindByCondition ¶
func (c *Con) FindByCondition(condition map[string]interface{}, result *[]Identifiable, prefixes ...string) (err *errors.Error)
FindByCondition 根据条件查询多条记录 最多返回1000条
func (*Con) FindByField ¶
func (c *Con) FindByField(fieldName string, value interface{}, result *[]Identifiable, prefixes ...string) (err *errors.Error)
FindByField 根据字段名称和值查询多条记录 最多返回1000条
func (*Con) FindByIDs ¶
func (c *Con) FindByIDs(ids []int64, result *[]Identifiable) *errors.Error
FindByIDs 根据ID列表查询多条记录
func (*Con) FindByMatch ¶
func (c *Con) FindByMatch(matchList []Match, result *[]Identifiable, prefixes ...string) (err *errors.Error)
FindByMatch 根据条件查询多条记录 最多返回1000条
func (*Con) GenerateID ¶
func (*Con) GenerateId ¶
func (*Con) GenerateSetID ¶
func (c *Con) GenerateSetID()
func (*Con) GetByCondition ¶
func (c *Con) GetByCondition(condition map[string]interface{}, result *Identifiable) (err *errors.Error)
GetByCondition 根据条件查询单条记录
func (*Con) GetByField ¶
func (c *Con) GetByField(fieldName string, value interface{}, result Identifiable) (err *errors.Error)
GetByField 根据字段名称和值查询单条记录
func (*Con) GetByMatch ¶
func (c *Con) GetByMatch(matchList []Match, result *Identifiable) (err *errors.Error)
GetByMatch 根据条件查询单条记录
func (*Con) GetConType ¶
func (*Con) SaveOrUpdate ¶
SaveOrUpdate 新增或者根据id更新
type DBService ¶
type DBService interface {
Start() error
End() error
Migrate(con *Con, tableName string, value ConTable, indexList []Index) error
GetByID(c *Con, id int64, result interface{}) error
Save(c *Con, data Identifiable, newID int64) (id int64, error error)
UpdatePart(c *Con, id int64, data map[string]interface{}) error
Delete(c *Con, data Identifiable) error
FindByMatch(c *Con, matchList []Match, result interface{}, prefixes ...string) error
GetByMatch(c *Con, matchList []Match, result interface{}) error
CountByMatch(c *Con, matchList []Match) (int64, error)
SumByMatch(c *Con, matchList []Match, field string) (float64, error)
FindByPageMatch(c *Con, matchList []Match, page *load.Page, total *load.Total, result interface{}, prefixes ...string) error
}
func GetDBService ¶
type Identifiable ¶
type Identifiable interface {
GetID() ID
}
type Match ¶
func (*Match) ToNearMatch ¶
type MatchType ¶
type MatchType string
const ( MEq MatchType = "=" MEqr MatchType = "=" MLt MatchType = "<" MLte MatchType = "<=" MGt MatchType = ">" MGte MatchType = ">=" MNE MatchType = "!=" MLIKE MatchType = "like" MIN MatchType = "in" MNOTIN MatchType = "not in" Near MatchType = "near" NearLoc MatchType = "nearloc" MNEmpty MatchType = "not empty" )
type Matches ¶
type Matches []Match
func NewMatches ¶
func NewMatches() *Matches
func (*Matches) AddMatches ¶
type Options ¶
type Options struct {
CreatedAt time.Time `gorm:"autoCreateTime:second;" bson:"createAt" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime:second" bson:"updateAt" json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at" bson:"-"`
}
func (*Options) SaveCreate ¶
func (o *Options) SaveCreate()
func (*Options) SaveUpdate ¶
func (o *Options) SaveUpdate()
type ValueField ¶
type ValueField string
func (ValueField) Check ¶
func (v ValueField) Check(sqlKeywords ...string) bool