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 : 异常定义 //