Documentation ¶
Index ¶
- func RawDB() *gorm.DB
- type BaseMapper
- func (b *BaseMapper[T]) ModifyByCondition(updated, condition T) (int64, error)
- func (b *BaseMapper[T]) ModifyById(updated T) (int64, error)
- func (b *BaseMapper[T]) ModifyMapById(id any, updated map[string]any) (int64, error)
- func (b *BaseMapper[T]) PageCondition(condition T, pageNumber, pageSize int, result *[]*T) (total int64, err error)
- func (b *BaseMapper[T]) PageConditionMap(condition map[string]any, pageNumber, pageSize int, result *[]*T) (total int64, err error)
- func (b *BaseMapper[T]) QueryByCondition(condition T, result *[]*T) (int64, error)
- func (b *BaseMapper[T]) QueryByConditionMap(condition map[string]any, result *[]*T) (int64, error)
- func (b *BaseMapper[T]) QueryById(id any, result *T) (int64, error)
- func (b *BaseMapper[T]) RemoveById(id ...any) (int64, error)
- func (b *BaseMapper[T]) Save(entity *T, excludeColumns ...string) (int64, error)
- func (b *BaseMapper[T]) SaveOrUpdate(entity *T, excludeColumns ...string) (int64, error)
- type BaseModel
- type DBExecutor
- type DBType
- type GormModule
- type GromConfig
- type IBaseModel
- type Transaction
- func (t *Transaction) Customize(executors ...DBExecutor) *Transaction
- func (t *Transaction) Execute() (bool, error)
- func (t *Transaction) ModifyByCondition(updated any, where interface{}, args ...interface{}) *Transaction
- func (t *Transaction) ModifyByConditionMap(model any, updated map[string]interface{}, where interface{}, ...) *Transaction
- func (t *Transaction) ModifyById(condition, updated any) *Transaction
- func (t *Transaction) QueryByCondition(condition any, result any) *Transaction
- func (t *Transaction) QueryByConditionMap(model any, condition map[string]any, result any) *Transaction
- func (t *Transaction) QueryById(model any, id any) *Transaction
- func (t *Transaction) RemoveByCondition(model any, where interface{}, args ...interface{}) *Transaction
- func (t *Transaction) RemoveById(condition any) *Transaction
- func (t *Transaction) Rollback()
- func (t *Transaction) Save(entity any) *Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseMapper ¶
type BaseMapper[T IBaseModel] struct { Value T }
func (*BaseMapper[T]) ModifyByCondition ¶ added in v0.0.2
func (b *BaseMapper[T]) ModifyByCondition(updated, condition T) (int64, error)
ModifyByCondition 通过非零实体条件,更新非零实体字段
func (*BaseMapper[T]) ModifyById ¶
func (b *BaseMapper[T]) ModifyById(updated T) (int64, error)
ModifyById 通过ID更新非零值字段
func (*BaseMapper[T]) ModifyMapById ¶
ModifyMapById 通过ID更新所有map中指定的列和值
func (*BaseMapper[T]) PageCondition ¶ added in v0.0.7
func (b *BaseMapper[T]) PageCondition(condition T, pageNumber, pageSize int, result *[]*T) (total int64, err error)
PageCondition 通过指定的非零值条件分页查询
func (*BaseMapper[T]) PageConditionMap ¶ added in v0.0.7
func (b *BaseMapper[T]) PageConditionMap(condition map[string]any, pageNumber, pageSize int, result *[]*T) (total int64, err error)
PageConditionMap 通过指定字段与值查询数据分页查询 解决零值条件问题
func (*BaseMapper[T]) QueryByCondition ¶ added in v0.0.2
func (b *BaseMapper[T]) QueryByCondition(condition T, result *[]*T) (int64, error)
QueryByCondition 通过非零条件查询
func (*BaseMapper[T]) QueryByConditionMap ¶ added in v0.0.2
func (b *BaseMapper[T]) QueryByConditionMap(condition map[string]any, result *[]*T) (int64, error)
QueryByConditionMap 通过指定字段与值查询数据 解决零值条件问题
func (*BaseMapper[T]) QueryById ¶ added in v0.0.2
func (b *BaseMapper[T]) QueryById(id any, result *T) (int64, error)
QueryById 通过主键查询数据
func (*BaseMapper[T]) RemoveById ¶
func (b *BaseMapper[T]) RemoveById(id ...any) (int64, error)
RemoveById 通过ID删除相关数据
func (*BaseMapper[T]) Save ¶
func (b *BaseMapper[T]) Save(entity *T, excludeColumns ...string) (int64, error)
Save 保存数据 零值也将参与保存
exclude 手动指定需要排除的字段
func (*BaseMapper[T]) SaveOrUpdate ¶ added in v0.0.9
func (b *BaseMapper[T]) SaveOrUpdate(entity *T, excludeColumns ...string) (int64, error)
SaveOrUpdate 保存/更新数据 零值也将参与保存
exclude 手动指定需要排除的字段(如果触发的是update 创建时间可能会被错误的修改,可以通过excludeColumns来指定排除创建时间字段)
type BaseModel ¶
type BaseModel[IdType any] struct { ID IdType `gorm:"<-:create,primaryKey" json:"id"` }
type GormModule ¶
type GormModule struct { // GromConfig 配置 GromConfig GromConfig // 懒加载函数,用于在实际执行时动态获取配置 该权重高于GormConfig的直接配置 LazyGromConfig func() GromConfig GormModuleConfig *declaration.ModuleConfig GormInterceptor func(instance *gorm.DB) }
func (*GormModule) ModuleConfig ¶
func (g *GormModule) ModuleConfig() *declaration.ModuleConfig
func (*GormModule) Register ¶
func (g *GormModule) Register() (interface{}, error)
func (*GormModule) Unregister ¶
func (g *GormModule) Unregister(maxWaitSeconds uint) (gracefully bool, err error)
type GromConfig ¶ added in v0.0.7
type GromConfig struct { Username string Password string Host string Port uint Database string Charset string // default charset : utf8mb4 TimeUTC bool // true: create/update UTC time; false LOCAL time DryRun bool // create sql not exec UseDefaultLog bool UrlParam string // more Param such as `allowNativePasswords=false&checkConnLiveness=false` https://github.com/go-sql-driver/mysql?tab=readme-ov-file#dsn-data-source-name }
type IBaseModel ¶
type IBaseModel interface {
TableName() string
}
type Transaction ¶ added in v0.0.4
type Transaction struct {
// contains filtered or unexported fields
}
func NewTransaction ¶
func NewTransaction(allowZeroAffRow ...bool) *Transaction
NewTransaction 创建一个事务执行链 整个事务链将在任何一个DML发生异常(或执行的结果不满足要求时)被标记为回滚,且在该事务链后面的DML操作将自动忽略执行 allowZeroAffRow 是否允许执行影响行数为0 如果为false 则遇到执行行数为0时回滚整个事务
func NewTransactionPrepare ¶ added in v0.0.4
func NewTransactionPrepare(allowZeroAffRow ...bool) *Transaction
NewTransactionPrepare 创建一个新的事务预执行链 该事务的执行方式将在执行Execute统一执行所有预设的DML过程 任何在该事务链中的对数据库操作均处于预备执行阶段,仅在调用Execute后才全部执行 整个事务链将在任何一个DML发生异常(或执行的结果不满足要求时)被标记为回滚,且在该事务链后面的DML操作将自动忽略执行 allowZeroAffRow 是否允许执行影响行数为0 如果为false 则遇到执行行数为0时回滚整个事务
func (*Transaction) Customize ¶ added in v0.0.4
func (t *Transaction) Customize(executors ...DBExecutor) *Transaction
Customize 执行自定义的SQL逻辑
func (*Transaction) Execute ¶ added in v0.0.4
func (t *Transaction) Execute() (bool, error)
Execute 执行所有装载的SQL链 bool true: committed false: rolled back
func (*Transaction) ModifyByCondition ¶ added in v0.0.4
func (t *Transaction) ModifyByCondition(updated any, where interface{}, args ...interface{}) *Transaction
ModifyByCondition 通过条件更新 updated 作为需要更新数据 仅更新updated非零值字段数据 零值会被自动忽略 可传入map[string]interface{}代替struct where sql部分条件 也可以是一个model非零参数条件
func (*Transaction) ModifyByConditionMap ¶ added in v0.0.4
func (t *Transaction) ModifyByConditionMap(model any, updated map[string]interface{}, where interface{}, args ...interface{}) *Transaction
ModifyByConditionMap 通过条件更新 request updated 作为需要更新数据 传入map[string]interface{}代替struct防止忽略零值
where sql部分条件 也可以是一个model非零参数条件
func (*Transaction) ModifyById ¶ added in v0.0.4
func (t *Transaction) ModifyById(condition, updated any) *Transaction
ModifyById 预设的更新功能 通过Id更新 request condition 作为更新时条件 需要指定主键
updated 作为需要更新数据 仅更新updated非零值字段数据 零值会被自动忽略 可传入map[string]interface{}代替struct
func (*Transaction) QueryByCondition ¶ added in v0.0.4
func (t *Transaction) QueryByCondition(condition any, result any) *Transaction
QueryByCondition 通过Id查询数据 condition model非零参数条件 result 返回数据指针
func (*Transaction) QueryByConditionMap ¶ added in v0.0.4
func (t *Transaction) QueryByConditionMap(model any, condition map[string]any, result any) *Transaction
QueryByConditionMap 通过Id查询数据 model 实体 condition 指定字段与值查询数据 result 返回数据指针
func (*Transaction) QueryById ¶ added in v0.0.4
func (t *Transaction) QueryById(model any, id any) *Transaction
QueryById 通过Id查询数据 model对象指针,用于指定数据表&接收返回结果
func (*Transaction) RemoveByCondition ¶ added in v0.0.4
func (t *Transaction) RemoveByCondition(model any, where interface{}, args ...interface{}) *Transaction
RemoveByCondition 预设删除功能 根据条件删除
func (*Transaction) RemoveById ¶ added in v0.0.4
func (t *Transaction) RemoveById(condition any) *Transaction
RemoveById 预设的删除功能 根据id或则ids删除 request 传入一个model,则其主键必须指定 调用通过主键删除
传入model切片(每个model需要指定主键) 批量通过主键删除
func (*Transaction) Save ¶ added in v0.0.4
func (t *Transaction) Save(entity any) *Transaction
Save 预设的保存功能 传入变量指针