From 3164f53b99d48542a6f34525e3cf4405b40e4b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 15 Oct 2023 14:15:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=B9=E6=8D=AE=E4=B8=BB?= =?UTF-8?q?=E9=94=AEID=E6=9F=A5=E8=AF=A2=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.go | 15 +++++++++++++++ error.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/base.go b/base.go index 92ee4a4..5f8383d 100644 --- a/base.go +++ b/base.go @@ -78,6 +78,21 @@ func (b *BaseDao) Detail(dbInstance *gorm.DB, result interface{}, optionFuncList return dbInstance.First(result).Error } +// DetailByPrimaryID ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:14 2023/10/15 +func (b *BaseDao) DetailByPrimaryID(dbInstance *gorm.DB, result interface{}, primaryID interface{}, primaryKey ...string) error { + primaryKeyField := "id" + if len(primaryKey) > 0 { + primaryKeyField = primaryKey[0] + } + return b.Detail(dbInstance, result, WithWhere(map[string]interface{}{ + primaryKeyField: primaryID, + })) +} + // IsNotFound 增加结果是否为数据不存在的判断 // // Author : go_developer@163.com<白茶清欢> diff --git a/error.go b/error.go index db0b14c..ba0bf0a 100644 --- a/error.go +++ b/error.go @@ -1,4 +1,4 @@ -// package database... +// Package database ... // // Description : 异常定义 //