database/abstract/database.go

48 lines
1.6 KiB
Go
Raw Normal View History

2023-10-14 15:14:05 +08:00
// Package abstract ...
//
// Description : abstract ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-10-14 15:06
package abstract
import (
2024-08-23 17:54:48 +08:00
"git.zhangdeman.cn/zhangdeman/database/define"
2023-10-14 15:14:05 +08:00
"gorm.io/gorm"
)
2024-08-12 18:16:07 +08:00
// IDatabase 定义base约束
2023-10-14 15:14:05 +08:00
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:06 2023/10/14
2024-08-12 18:16:07 +08:00
type IDatabase interface {
2023-10-14 15:14:05 +08:00
// Create 创建数据
2024-08-23 17:54:48 +08:00
Create(dbInstance *gorm.DB, data any, optionList ...define.SetOption) error
2023-10-14 15:14:05 +08:00
// Update 更新数据
2024-08-23 17:54:48 +08:00
Update(dbInstance *gorm.DB, updateData any, optionFuncList ...define.SetOption) (int64, error)
2024-01-13 17:08:47 +08:00
// UpdateOne 更新一条数据
2024-08-23 17:54:48 +08:00
UpdateOne(dbInstance *gorm.DB, updateData any, optionFuncList ...define.SetOption) (int64, error)
2023-10-14 15:14:05 +08:00
// List 查询数据列表
2024-08-23 17:54:48 +08:00
List(dbInstance *gorm.DB, result any, optionFuncList ...define.SetOption) error
2023-10-14 15:14:05 +08:00
// Delete 删除数据
2024-08-23 17:54:48 +08:00
Delete(dbInstance *gorm.DB, dataModel any, optionFuncList ...define.SetOption) (int64, error)
2023-10-14 15:14:05 +08:00
// Detail 数据详情
2024-08-23 17:54:48 +08:00
Detail(dbInstance *gorm.DB, result any, optionFuncList ...define.SetOption) error
2023-10-14 15:14:05 +08:00
// IsNotFound 错误是否为数据不存在
IsNotFound(err error) bool
// Count 查询数据数量
2024-08-23 17:54:48 +08:00
Count(dbInstance *gorm.DB, optionFuncList ...define.SetOption) (int64, error)
2023-10-14 15:14:05 +08:00
// 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
2024-08-12 18:16:07 +08:00
// DetailByPrimaryID 根据主键ID, 查询任意表的数据详情
DetailByPrimaryID(dbInstance *gorm.DB, result any, primaryID any, primaryKey ...string) error
2023-10-14 15:14:05 +08:00
}