增加根据主键ID查询详情

This commit is contained in:
白茶清欢 2023-10-15 14:15:03 +08:00
parent 2a7f06060d
commit 3164f53b99
2 changed files with 16 additions and 1 deletions

15
base.go
View File

@ -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<白茶清欢>

View File

@ -1,4 +1,4 @@
// package database...
// Package database ...
//
// Description : 异常定义
//