新增 TakeBusinessFields、WriteBusinessFields、SetByPath 与 GetByPath 等工具,支持按映射路径写入请求体与解析响应,并更新相关依赖。
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package dao
|
||
|
||
import (
|
||
"context"
|
||
"model-gateway/consts/public"
|
||
"model-gateway/model/dto"
|
||
"model-gateway/model/entity"
|
||
|
||
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
)
|
||
|
||
var ModelSession = &modelSessionDao{}
|
||
|
||
type modelSessionDao struct{}
|
||
|
||
// Insert 插入
|
||
func (d *modelSessionDao) Insert(ctx context.Context, req *dto.CreateModelSessionReq) (id int64, err error) {
|
||
m := new(entity.ModelSession)
|
||
err = gconv.Struct(req, &m)
|
||
if err != nil {
|
||
return
|
||
}
|
||
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameModelSession).Insert(m)
|
||
if err != nil {
|
||
return
|
||
}
|
||
return r.LastInsertId()
|
||
}
|
||
|
||
// Update 更新(按ID)
|
||
func (d *modelSessionDao) Update(ctx context.Context, req *dto.UpdateModelSessionReq) (rows int64, err error) {
|
||
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameModelSession).
|
||
OmitEmpty().
|
||
Data(req).
|
||
Where(entity.ModelSessionCol.Id, req.Id).
|
||
Update()
|
||
if err != nil {
|
||
return
|
||
}
|
||
return r.RowsAffected()
|
||
}
|