Documentation
¶
Index ¶
- Constants
- 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 DeleteByMatch(c *Con, matchList []Match) *errors.Error
- func ExistsByMatch(c *Con, matchList []Match) (bool, *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 FindByPageMatchT[T Identifiable](c *Con, matchList []Match, page *load.Page, pageResp *load.PageRespT[T], ...) *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 Save(c *Con, data Identifiable, newIDs ...int64) (id int64, err *errors.Error)
- func SaveOrUpdate(c *Con, data Identifiable, newIDs ...int64) (id int64, err *errors.Error)deprecated
- func SumByMatch(c *Con, matchList []Match, field string) (float64, *errors.Error)
- func UpdateByMatch(c *Con, matchList []Match, data map[string]interface{}) *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 CreateComplex[T any](ctx context.Context, conType ConType, dbName string, table string, data *T, ...) *Complex[T]
- func NewComplex[T any](conType ConType, dbName string, table string) *Complex[T]
- func UseComplex[T any](conType ConType, dbName string, table string, prefix ...string) *Complex[T]
- func UseComplexD[T any](conType ConType, dbName string, table string) Complex[T]
- 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 ComplexList
- 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) Save(data Identifiable, newIDs ...int64) (id int64, err *errors.Error)
- func (c *Con) SaveOrUpdate(data Identifiable, newIDs ...int64) (id int64, err *errors.Error)
- func (c *Con) SetID(id int64)
- 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 ¶
const ServiceCode = "DATABASE"
Variables ¶
var GormDBServ = &gormDBService{}
var MigrationList []*Migration
var MongoDBServ = &mongoDBService{}
Functions ¶
func AutoMigrate ¶
func CountByCondition ¶
CountByCondition queries the count by condition
func CountByField ¶
CountByField queries the count by field name and value
func CountByMatch ¶
CountByMatch queries the count by condition
func ExistsByMatch ¶ added in v0.0.48
func FindByCondition ¶
func FindByCondition[T any](c *Con, condition map[string]interface{}, result *[]T, prefixes ...string) (err *errors.Error)
FindByCondition queries multiple records by condition, returns up to 1000 records
func FindByField ¶
func FindByField[T any](c *Con, fieldName string, value interface{}, result *[]T, prefixes ...string) (err *errors.Error)
FindByField queries multiple records by field name and value, returns up to 1000 records
func FindByMatch ¶
func FindByMatch[T any](c *Con, matchList []Match, result *[]T, prefixes ...string) (err *errors.Error)
FindByMatch queries multiple records by condition, returns up to 1000 records
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 queries paginated records by 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 queries paginated records by field name
func FindByPageMatch ¶
func FindByPageMatchT ¶ added in v0.0.45
func GetByCondition ¶
GetByCondition queries a single record by condition
func GetByField ¶
GetByField queries a single record by field name and value
func GetByMatch ¶
GetByMatch queries a single record by condition
func GetLastID ¶
func GetLastID[T Identifiable](conList []T) int64
func MustGetByID ¶
func MustGetByID[T Identifiable](c *Con, id int64, result T) *errors.Error
func RegisterDBService ¶
func SaveOrUpdate
deprecated
func SumByMatch ¶
SumByMatch queries the sum by condition
func UpdateByMatch ¶ added in v0.0.30
UpdateByMatch updates records by condition
func UpdatePart ¶
UpdatePart updates partial fields by ID
func UseMongoDbConn ¶
Types ¶
type Complex ¶
func CreateComplex ¶ added in v0.0.45
func UseComplex ¶
func (*Complex[T]) FindByPage ¶
func (*Complex[T]) FindByPageField ¶
func (*Complex[T]) FindByPageMatch ¶
type ComplexList ¶ added in v0.0.45
func (*ComplexList[T]) List ¶ added in v0.0.45
func (c *ComplexList[T]) List() []*T
type Con ¶
type Con struct {
Ctx context.Context `gorm:"-" bson:"-" json:"-"`
ID int64 `gorm:"primaryKey" bson:"id" json:"id"`
ConType `gorm:"-" bson:"-" json:"-"`
MysqlDB *gorm.DB `gorm:"-" bson:"-" json:"-"`
MongoDB *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) CountByCondition ¶
func (*Con) CountByField ¶
func (*Con) FindByCondition ¶
func (*Con) FindByField ¶
func (*Con) FindByMatch ¶
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)
func (*Con) GetByField ¶
func (c *Con) GetByField(fieldName string, value interface{}, result Identifiable) (err *errors.Error)
func (*Con) GetByMatch ¶
func (c *Con) GetByMatch(matchList []Match, result *Identifiable) (err *errors.Error)
func (*Con) GetConType ¶
func (*Con) SaveOrUpdate ¶
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, version ...int) (id int64, error error)
UpdatePart(c *Con, id int64, data map[string]interface{}) error
UpdateByMatch(c *Con, matchList []Match, data map[string]interface{}) error
Delete(c *Con, data Identifiable) error
DeleteByMatch(c *Con, matchList []Match) 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)
ExistsByMatch(c *Con, matchList []Match) (bool, 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 Match ¶
func (*Match) ToNearMatch ¶
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