base增加基础约束
This commit is contained in:
parent
3eb6fb3991
commit
3766261de7
43
abstract/base.go
Normal file
43
abstract/base.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// Package abstract ...
|
||||||
|
//
|
||||||
|
// Description : abstract ...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 2023-10-14 15:06
|
||||||
|
package abstract
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.zhangdeman.cn/zhangdeman/database"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Base 定义base约束
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 15:06 2023/10/14
|
||||||
|
type Base interface {
|
||||||
|
// Create 创建数据
|
||||||
|
Create(dbInstance *gorm.DB, data interface{}, optionList ...database.SetOption) error
|
||||||
|
// Update 更新数据
|
||||||
|
Update(dbInstance *gorm.DB, updateData interface{}, optionFuncList ...database.SetOption) (int64, error)
|
||||||
|
// List 查询数据列表
|
||||||
|
List(dbInstance *gorm.DB, result interface{}, optionFuncList ...database.SetOption) error
|
||||||
|
// Delete 删除数据
|
||||||
|
Delete(dbInstance *gorm.DB, dataModel interface{}, optionFuncList ...database.SetOption) (int64, error)
|
||||||
|
// Detail 数据详情
|
||||||
|
Detail(dbInstance *gorm.DB, result interface{}, optionFuncList ...database.SetOption) error
|
||||||
|
// IsNotFound 错误是否为数据不存在
|
||||||
|
IsNotFound(err error) bool
|
||||||
|
// Count 查询数据数量
|
||||||
|
Count(dbInstance *gorm.DB, optionFuncList ...database.SetOption) (int64, error)
|
||||||
|
// Tx 执行事务
|
||||||
|
Tx(dbInstance *gorm.DB, txFunc func(dbInstance *gorm.DB) error) error
|
||||||
|
// Begin 开启事务
|
||||||
|
Begin(dbInstance *gorm.DB) *gorm.DB
|
||||||
|
// Commit 提交事务
|
||||||
|
Commit(db *gorm.DB) error
|
||||||
|
// Rollback 回滚事务
|
||||||
|
Rollback(db *gorm.DB) error
|
||||||
|
}
|
2
base.go
2
base.go
@ -84,7 +84,7 @@ func (b *BaseDao) Detail(dbInstance *gorm.DB, result interface{}, optionFuncList
|
|||||||
//
|
//
|
||||||
// Date : 15:57 2023/2/23
|
// Date : 15:57 2023/2/23
|
||||||
func (b *BaseDao) IsNotFound(err error) bool {
|
func (b *BaseDao) IsNotFound(err error) bool {
|
||||||
return err == gorm.ErrRecordNotFound
|
return errors.Is(err, gorm.ErrRecordNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count 查询数量
|
// Count 查询数量
|
||||||
|
Loading…
Reference in New Issue
Block a user