Documentation ¶
Index ¶
- Constants
- Variables
- func AddConnection(ctx *gin.Context, name string, connection drivers.DriverInterface) error
- func Client[T DBClient](ctx *gin.Context, name string) T
- func StartTransaction(ctx *gin.Context, name string, f func(ctx *gin.Context, tx *gorm.DB) error) error
- func StartTransactionWithModel(ctx *gin.Context, model ModelInterface, ...) error
- func WithContextModel(ctx *gin.Context, model ModelInterface) *gorm.DB
- func WithContextTable(ctx *gin.Context, model ModelInterface) *gorm.DB
- type DBClient
- type DBComponent
- type DBContainer
- func (i *DBContainer) Get(name string) any
- func (i *DBContainer) GetConnector(name string) drivers.ConnectorInterface
- func (i *DBContainer) Is(instance any) bool
- func (i *DBContainer) Range(f func(instance any))
- func (i *DBContainer) Remove(name string) bool
- func (i *DBContainer) Save(instance any) bool
- type DatabaseConf
- type GormBuilder
- type Model
- func (i Model[T]) CountByConditions(ctx *gin.Context, conditions map[string]any) (total int64, err error)
- func (i Model[T]) Create(ctx *gin.Context, data T) (err error)
- func (i Model[T]) CreateOrIgnore(ctx *gin.Context, data T, fields []string) (err error)
- func (i Model[T]) DeleteByConditions(ctx *gin.Context, conditions map[string]any) (err error)
- func (i Model[T]) FindByConditions(ctx *gin.Context, conditions map[string]any) (result T, err error)
- func (i Model[T]) FirstOrCreate(ctx *gin.Context, data T, conditions map[string]any) (created int64, err error)
- func (i Model[T]) GetByBuilder(ctx *gin.Context, builder GormBuilder) (result []T, err error)
- func (i Model[T]) GetByConditions(ctx *gin.Context, conditions map[string]any) (result []T, err error)
- func (i Model[T]) Insert(ctx *gin.Context, data []T) (err error)
- func (i Model[T]) InsertOrIgnore(ctx *gin.Context, data []T, fields []string) (err error)
- func (i Model[T]) InsertOrUpdate(ctx *gin.Context, data []T, fields []string) (err error)
- func (i Model[T]) ListByBuilder(ctx *gin.Context, builder GormBuilder) (result []T, err error)
- func (i Model[T]) ListByConditions(ctx *gin.Context, conditions map[string]any, page, size int64, order string) (result []T, err error)
- func (i Model[T]) Save(ctx *gin.Context, data T) (err error)
- func (i Model[T]) StartTransaction(ctx *gin.Context, f func(ctx *gin.Context, tx *gorm.DB) (err error)) (err error)
- func (i Model[T]) UpdateByConditions(ctx *gin.Context, conditions map[string]any, fields map[string]any) (err error)
- func (i Model[T]) UpdateOrCreate(ctx *gin.Context, data T, fields []string) (err error)
- type ModelInterface
Constants ¶
View Source
const (
Context_GormDBTransaction = "gorm.db.transaction"
)
View Source
const (
DatabaseConfigName = "DatabaseConf"
)
Variables ¶
View Source
var Component = &DBComponent{}
Functions ¶
func AddConnection ¶ added in v0.4.0
func StartTransaction ¶ added in v0.4.19
func StartTransactionWithModel ¶ added in v0.4.27
func WithContextModel ¶ added in v0.0.52
func WithContextModel(ctx *gin.Context, model ModelInterface) *gorm.DB
WithContextModel 仅用于 gorm,使用model实体进行查询
func WithContextTable ¶ added in v0.4.16
func WithContextTable(ctx *gin.Context, model ModelInterface) *gorm.DB
WithContextTable 仅用于 gorm,使用table进行查询
Types ¶
type DBComponent ¶ added in v0.3.2
type DBComponent struct{}
func (*DBComponent) Inject ¶ added in v0.3.2
func (i *DBComponent) Inject(instance any) bool
func (*DBComponent) InjectConf ¶ added in v0.4.0
func (i *DBComponent) InjectConf(config cComponents.ConfigInterface) bool
func (*DBComponent) Listen ¶ added in v0.4.0
func (i *DBComponent) Listen() []*cComponents.ConfigListener
func (*DBComponent) Load ¶ added in v0.3.2
func (i *DBComponent) Load()
type DBContainer ¶ added in v0.4.0
type DBContainer struct {
// contains filtered or unexported fields
}
func (*DBContainer) Get ¶ added in v0.4.0
func (i *DBContainer) Get(name string) any
func (*DBContainer) GetConnector ¶ added in v0.4.0
func (i *DBContainer) GetConnector(name string) drivers.ConnectorInterface
func (*DBContainer) Is ¶ added in v0.4.0
func (i *DBContainer) Is(instance any) bool
func (*DBContainer) Range ¶ added in v0.4.0
func (i *DBContainer) Range(f func(instance any))
func (*DBContainer) Remove ¶ added in v0.4.0
func (i *DBContainer) Remove(name string) bool
func (*DBContainer) Save ¶ added in v0.4.0
func (i *DBContainer) Save(instance any) bool
type DatabaseConf ¶
type DatabaseConf struct {
Connections map[string]drivers.DriverInterface `json:"connections"`
}
func (*DatabaseConf) ConfigName ¶
func (i *DatabaseConf) ConfigName() string
func (*DatabaseConf) Decode ¶ added in v0.4.8
func (i *DatabaseConf) Decode(data string) error
type GormBuilder ¶ added in v0.4.28
type Model ¶ added in v0.4.20
type Model[T ModelInterface] struct{}
func (Model[T]) CountByConditions ¶ added in v0.4.20
func (i Model[T]) CountByConditions(ctx *gin.Context, conditions map[string]any) (total int64, err error)
CountByConditions 根据条件统计数量
func (Model[T]) CreateOrIgnore ¶ added in v0.4.21
CreateOrIgnore 新建单条数据或忽略,必须要有唯一索引才生效
func (Model[T]) DeleteByConditions ¶ added in v0.4.20
DeleteByConditions 根据条件删除数据
func (Model[T]) FindByConditions ¶ added in v0.4.20
func (i Model[T]) FindByConditions(ctx *gin.Context, conditions map[string]any) (result T, err error)
FindByConditions 根据条件查询单条数据
func (Model[T]) FirstOrCreate ¶ added in v0.4.20
func (i Model[T]) FirstOrCreate(ctx *gin.Context, data T, conditions map[string]any) (created int64, err error)
FirstOrCreate 查找或新增单条数据
func (Model[T]) GetByBuilder ¶ added in v0.4.28
func (i Model[T]) GetByBuilder(ctx *gin.Context, builder GormBuilder) (result []T, err error)
GetByConditions 根据条件查询多条数据,条件不存在则查询所有数据
func (Model[T]) GetByConditions ¶ added in v0.4.20
func (i Model[T]) GetByConditions(ctx *gin.Context, conditions map[string]any) (result []T, err error)
GetByConditions 根据条件查询多条数据,条件不存在则查询所有数据
func (Model[T]) InsertOrIgnore ¶ added in v0.4.21
InsertOrIgnore 批量添加数据,存在则忽略
func (Model[T]) InsertOrUpdate ¶ added in v0.4.21
InsertOrUpdate 批量添加数据,存在则更新
func (Model[T]) ListByBuilder ¶ added in v0.4.28
func (i Model[T]) ListByBuilder(ctx *gin.Context, builder GormBuilder) (result []T, err error)
ListByBuilder 根据构造器查询
func (Model[T]) ListByConditions ¶ added in v0.4.20
func (i Model[T]) ListByConditions(ctx *gin.Context, conditions map[string]any, page, size int64, order string) (result []T, err error)
ListByConditions 根据条件分页查询
func (Model[T]) StartTransaction ¶ added in v0.4.27
Source Files ¶
Click to show internal directories.
Click to hide internal directories.