41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"prompts-core/consts/public"
|
|
"prompts-core/model/entity"
|
|
|
|
"gitea.com/red-future/common/db/gfdb"
|
|
)
|
|
|
|
var Model = &modelDao{}
|
|
|
|
type modelDao struct{}
|
|
|
|
// Get 获取模型
|
|
func (d *modelDao) Get(ctx context.Context, req *entity.AsynchModel, fields ...string) (m *entity.AsynchModel, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameModel).
|
|
OmitEmpty().
|
|
Where(entity.AsynchModelCol.Creator, req.Creator).
|
|
Where(entity.AsynchModelCol.IsChatModel, req.IsChatModel).
|
|
Where(entity.AsynchModelCol.ModelName, req.ModelName).
|
|
Fields(fields).One()
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = r.Struct(&m)
|
|
return
|
|
}
|
|
|
|
// GetsByModelName 批量获取模型
|
|
func (d *modelDao) GetsByModelName(ctx context.Context, creator string, modelNames []string, fields ...string) (list []*entity.AsynchModel, err error) {
|
|
err = gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameModel).
|
|
OmitEmpty().
|
|
Where(entity.AsynchModelCol.Creator, creator).
|
|
WhereIn(entity.AsynchModelCol.ModelName, modelNames).
|
|
Fields(fields).
|
|
Scan(&list)
|
|
|
|
return
|
|
}
|