domainx

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GormDBServ = &gormDBService{}
View Source
var MigrationList []*Migration
View Source
var MongoDBServ = &mongoDBService{}

Functions

func AutoMigrate

func AutoMigrate(getDB func() (value ConTable), index ...Index)

func Check

func Check(s string) bool

func CountByCondition

func CountByCondition(c *Con, condition map[string]interface{}) (int64, *errors.Error)

CountByCondition 根据条件查询数量

func CountByField

func CountByField(c *Con, fieldName string, value interface{}) (int64, *errors.Error)

CountByField 根据字段名称和值查询数量

func CountByMatch

func CountByMatch(c *Con, matchList []Match) (int64, *errors.Error)

CountByMatch 根据条件查询数量

func Delete

func Delete(c *Con, data Identifiable) *errors.Error

Delete 删除

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 FindByIDs

func FindByIDs[T any](c *Con, ids []int64, result *[]T) *errors.Error

FindByIDs

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 FindByPageMatch[T Identifiable](c *Con, matchList []Match, page *load.Page, pageResp *load.PageResp, result *[]T, prefixes ...string) *errors.Error

func GetByCondition

func GetByCondition[T any](c *Con, condition map[string]interface{}, result *T) (err *errors.Error)

GetByCondition 根据条件查询单条记录

func GetByField

func GetByField[T any](c *Con, fieldName string, value interface{}, result *T) (err *errors.Error)

GetByField 根据字段名称和值查询单条记录

func GetByID

func GetByID[T any](c *Con, id int64, result *T) (err *errors.Error)

GetByID 获取单条记录

func GetByMatch

func GetByMatch[T any](c *Con, matchList []Match, result *T) (err *errors.Error)

GetByMatch 根据条件查询单条记录

func GetEntity

func GetEntity[T any](entity interface{}) (*T, *errors.Error)

func GetLastID

func GetLastID[T Identifiable](conList []T) int64

func GetListEntity

func GetListEntity[T any](docList any) (*[]T, *errors.Error)

GetListEntity 获取列表实体

func MustGetByID

func MustGetByID[T Identifiable](c *Con, id int64, result T) *errors.Error

MustGetByID 获取单条记录

func RegisterDBService

func RegisterDBService(conType ConType, s DBService)

func SaveOrUpdate

func SaveOrUpdate(c *Con, data Identifiable, newIDs ...int64) (id int64, err *errors.Error)

SaveOrUpdate 新增或者根据id更新

func SumByMatch

func SumByMatch(c *Con, matchList []Match, field string) (float64, *errors.Error)

SumByMatch 根据条件查询总和

func UpdatePart

func UpdatePart(c *Con, id int64, data map[string]interface{}) *errors.Error

UpdatePart 根据ID更新部分字段

func UseDbConn

func UseDbConn(dbname string) *gorm.DB

func UseMongoDbConn

func UseMongoDbConn(dbname string) *qmgo.Client

Types

type Complex

type Complex[T any] struct {
	*Con
	Data *T `bson:"data" gorm:"embedded" json:"data"`
	Options
}

func NewComplex

func NewComplex[T any](conType ConType, dbName string, table string) *Complex[T]

func UseComplex

func UseComplex[T any](conType ConType, dbName string, table string, prefix ...string) *Complex[T]

func UseComplexD

func UseComplexD[T any](conType ConType, dbName string, table string) Complex[T]

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

func (c *Complex[T]) FindByPageMatch(matchList []Match, page *load.Page, pageResp *load.PageResp, prefixes ...string) *errors.Error

func (*Complex[T]) GetID

func (c *Complex[T]) GetID() ID

func (*Complex[T]) IsNil

func (c *Complex[T]) IsNil() bool

func (*Complex[T]) TableName

func (c *Complex[T]) TableName() string

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 UseCon

func UseCon(conType ConType, dbName string, table string) *Con

func (*Con) AfterCreate

func (c *Con) AfterCreate(gormDB *gorm.DB) error

func (*Con) AfterUpdate

func (c *Con) AfterUpdate(gormDB *gorm.DB) error

func (*Con) BeforeCreate

func (c *Con) BeforeCreate(gormDB *gorm.DB) error

func (*Con) BeforeUpdate

func (c *Con) BeforeUpdate(gormDB *gorm.DB) error

BeforeUpdate BeforeUpdate、BeforeSave 函数都会因为 更新类的操作而被触发 如果baseModel 和 普通业务 model 都想使用回调函数,那么请设置不同的回调函数名,例如:这里设置 BeforeUpdate、普通业务model 设置 BeforeSave 即可

func (*Con) CountByCondition

func (c *Con) CountByCondition(condition map[string]interface{}) (int64, *errors.Error)

CountByCondition 根据条件查询数量

func (*Con) CountByField

func (c *Con) CountByField(fieldName string, value interface{}) (int64, *errors.Error)

CountByField 根据字段名称和值查询数量

func (*Con) CountByMatch

func (c *Con) CountByMatch(matchList []Match) (int64, *errors.Error)

CountByMatch 根据条件查询数量

func (*Con) Delete

func (c *Con) Delete(data Identifiable) *errors.Error

Delete 删除

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 (c *Con) GenerateID() int64

func (*Con) GenerateId

func (c *Con) GenerateId() int64

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) GetCon

func (c *Con) GetCon() *Con

func (*Con) GetConType

func (c *Con) GetConType() ConType

func (*Con) GetDB

func (c *Con) GetDB() any

func (*Con) GetID

func (c *Con) GetID() ID

func (*Con) HandleError

func (*Con) HandleError(tx *gorm.DB) (err *errors.Error)

func (*Con) HandleWithErr

func (c *Con) HandleWithErr(err error) (error *errors.Error)

func (*Con) MustGetDB

func (c *Con) MustGetDB() (any, *errors.Error)

func (*Con) SaveOrUpdate

func (c *Con) SaveOrUpdate(data Identifiable, newIDs ...int64) (id int64, err *errors.Error)

SaveOrUpdate 新增或者根据id更新

func (*Con) SetID added in v0.0.10

func (c *Con) SetID(id int64)

func (*Con) TableName

func (c *Con) TableName() string

func (*Con) UpdatePart

func (c *Con) UpdatePart(id int64, data map[string]interface{}) *errors.Error

UpdatePart 根据ID更新部分字段

type ConTable

type ConTable interface {
	TableName() string
	GetCon() *Con
}

type ConType

type ConType string
const (
	Mysql ConType = "mysql"
	Redis ConType = "redis"
	Mongo ConType = "mongo"
)

func (ConType) String

func (c ConType) String() string

type Converter

type Converter[T any] struct{}

func (*Converter[T]) FromPrimitiveD

func (c *Converter[T]) FromPrimitiveD(doc interface{}) (*T, *errors.Error)

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

func GetDBService(conType ConType) DBService

type ID

type ID int64

func (ID) Equal

func (i ID) Equal(id int64) bool

func (ID) GenerateID

func (i ID) GenerateID() int64

func (ID) GetID

func (i ID) GetID() ID

func (ID) Int64

func (i ID) Int64() int64

func (ID) IsNil

func (i ID) IsNil() bool

func (ID) IsZero

func (i ID) IsZero() bool

func (ID) New

func (i ID) New() *ID

func (ID) NotNil

func (i ID) NotNil() bool

func (ID) NotZero

func (i ID) NotZero() bool

func (ID) Reset

func (i ID) Reset()

func (ID) SetID

func (i ID) SetID(id int64)

type Identifiable

type Identifiable interface {
	GetID() ID
	SetID(id int64)
}

type IdxType

type IdxType string
const (
	Unique    IdxType = "unique"
	Idx       IdxType = "idx"
	Spatial2D IdxType = "2d"
)

type Index

type Index struct {
	IdxType IdxType
	Fields  []string
	IdxName string
}

func CtIdx

func CtIdx(idxType IdxType, fileds ...string) Index

type IndexFunc

type IndexFunc func() []Index

type Match

type Match struct {
	Field string
	Value interface{}
	Type  MatchType
}

func (*Match) ToNearMatch

func (h *Match) ToNearMatch() NearMatch

type MatchType

type MatchType string
const (
	MEq     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) Add

func (m *Matches) Add(field string, value interface{}, t MatchType, ignore ...bool) *Matches

func (*Matches) AddMatch

func (m *Matches) AddMatch(match *Match) *Matches

func (*Matches) AddMatches

func (m *Matches) AddMatches(matches *Matches) *Matches

func (*Matches) Eq

func (m *Matches) Eq(field string, value interface{}, ignore ...bool) *Matches

func (*Matches) Gt

func (m *Matches) Gt(field string, value interface{}, ignore ...bool) *Matches

func (*Matches) Gte

func (m *Matches) Gte(field string, value interface{}, ignore ...bool) *Matches

func (*Matches) In

func (m *Matches) In(field string, value interface{}, ignore ...bool) *Matches

func (*Matches) Like

func (m *Matches) Like(field string, value string, ignore ...bool) *Matches

func (*Matches) Lt

func (m *Matches) Lt(field string, value interface{}, ignore ...bool) *Matches

func (*Matches) Lte

func (m *Matches) Lte(field string, value interface{}, ignore ...bool) *Matches

func (*Matches) NEmpty

func (m *Matches) NEmpty(field string) *Matches

func (*Matches) Ne

func (m *Matches) Ne(field string, value interface{}, ignore ...bool) *Matches

func (*Matches) Near

func (m *Matches) Near(latFiled, lngFiled string, lat, lng, distance float64) *Matches

func (*Matches) NearLoc

func (m *Matches) NearLoc(localField string, lat, lng, distance float64) *Matches

func (*Matches) NotIn

func (m *Matches) NotIn(field string, value interface{}, ignore ...bool) *Matches

type Migration

type Migration struct {
	DBFunc func() ConTable
	Index  []Index
}

type NearMatch

type NearMatch struct {
	LatField string
	LngField string
	Lat      float64
	Lng      float64
	Distance float64
}

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 Result

type Result[T any] struct {
	Data T
}

type Sort

type Sort struct {
	Field  string
	Asc    bool
	Prefix string
}

type Sorts

type Sorts []*Sort

func (*Sorts) AddSort

func (s *Sorts) AddSort(field string, asc bool, prefix ...string) *Sorts

func (*Sorts) GetSort

func (s *Sorts) GetSort() []*Sort

func (*Sorts) SetSort

func (s *Sorts) SetSort(sort ...*Sort) *Sorts

type ValueField

type ValueField string

func (ValueField) Check

func (v ValueField) Check(sqlKeywords ...string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL