56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"prompts-core/consts/public"
|
|
"prompts-core/model/entity"
|
|
|
|
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
var ComposeTask = &composeTaskDao{}
|
|
|
|
type composeTaskDao struct{}
|
|
|
|
// Insert 插入
|
|
func (d *composeTaskDao) Insert(ctx context.Context, req *entity.ComposeTask) (id int64, err error) {
|
|
var m = new(entity.ComposeTask)
|
|
err = gconv.Struct(req, &m)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeTask).
|
|
Insert(m)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.LastInsertId()
|
|
}
|
|
|
|
// Get 获取
|
|
func (d *composeTaskDao) Get(ctx context.Context, req *entity.ComposeTask, fields ...string) (m *entity.ComposeTask, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeTask).
|
|
OmitEmpty().
|
|
Where(entity.ComposeTaskCol.TaskId, req.TaskId).
|
|
Fields(fields).One()
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = r.Struct(&m)
|
|
return
|
|
}
|
|
|
|
// Update 更新
|
|
func (d *composeTaskDao) Update(ctx context.Context, req *entity.ComposeTask) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeTask).
|
|
OmitEmpty().
|
|
Data(&req).
|
|
Where(entity.ComposeTaskCol.TaskId, req.TaskId).
|
|
Update()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|