From 3766261de7eb2ff983d298136460a57b8e2d8dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 14 Oct 2023 15:14:05 +0800 Subject: [PATCH] =?UTF-8?q?base=E5=A2=9E=E5=8A=A0=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abstract/base.go | 43 +++++++++++++++++++++++++++++++++++++++++++ base.go | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 abstract/base.go diff --git a/abstract/base.go b/abstract/base.go new file mode 100644 index 0000000..9fea75e --- /dev/null +++ b/abstract/base.go @@ -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 +} diff --git a/base.go b/base.go index a9c506f..92ee4a4 100644 --- a/base.go +++ b/base.go @@ -84,7 +84,7 @@ func (b *BaseDao) Detail(dbInstance *gorm.DB, result interface{}, optionFuncList // // Date : 15:57 2023/2/23 func (b *BaseDao) IsNotFound(err error) bool { - return err == gorm.ErrRecordNotFound + return errors.Is(err, gorm.ErrRecordNotFound) } // Count 查询数量