Compare commits

...

2 Commits

Author SHA1 Message Date
sk 108691267d 解决冲突 2024-12-05 13:42:55 +08:00
sk b0d88175c8 提交mongoctl工具 2024-12-05 13:36:53 +08:00
1 changed files with 2 additions and 2 deletions

View File

@ -143,13 +143,13 @@ func GetTableName(model any) string {
// GetCollectionDao 获取文档操作接口 // GetCollectionDao 获取文档操作接口
// key: 平台id 或 KeyGlobal // key: 平台id 或 KeyGlobal
// database: 数据库类型 DatabaseType // database: 数据库类型 DatabaseType
// f: 文档接口创建函数 // f: 文档接口创建函数; 结合 tools/mongoctl 生成
func GetCollectionDao[T any](key string, database DatabaseType, model any, f func(database *mongo.Database, c *mongo.Collection) T) (T, error) { func GetCollectionDao[T any](key string, database DatabaseType, model any, f func(database *mongo.Database, c *mongo.Collection) T) (T, error) {
collectionName := GetTableName(model) collectionName := GetTableName(model)
c, err := GetCollection(key, database, collectionName) c, err := GetCollection(key, database, collectionName)
if err != nil { if err != nil {
var z T var z T
logger.Logger.Errorf("GetCollectionModel key:%v database:%v model:%v error: %v", key, database, collectionName, err) logger.Logger.Errorf("GetCollectionDao key:%v database:%v model:%v error: %v", key, database, collectionName, err)
return z, err return z, err
} }
return f(c.Database.Database, c.Collection), nil return f(c.Database.Database, c.Collection), nil