49 lines
1.1 KiB
Go
49 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 ComposeTask = &composeTaskDao{}
|
||
|
|
|
||
|
|
type composeTaskDao struct{}
|
||
|
|
|
||
|
|
func (d *composeTaskDao) Insert(ctx context.Context, m *entity.ComposeTask) (id int64, err error) {
|
||
|
|
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeTask).Data(m).Insert()
|
||
|
|
if err != nil {
|
||
|
|
return 0, err
|
||
|
|
}
|
||
|
|
return r.LastInsertId()
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d *composeTaskDao) GetByTaskId(ctx context.Context, taskId string) (m *entity.ComposeTask, err error) {
|
||
|
|
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeTask).
|
||
|
|
Where(entity.ComposeTaskCol.TaskId, taskId).
|
||
|
|
One()
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if r.IsEmpty() {
|
||
|
|
return nil, nil
|
||
|
|
}
|
||
|
|
err = r.Struct(&m)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d *composeTaskDao) UpdateByTaskId(ctx context.Context, taskId string, data map[string]any) (rows int64, err error) {
|
||
|
|
data[entity.ComposeTaskCol.Updater] = ""
|
||
|
|
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeTask).
|
||
|
|
Where(entity.ComposeTaskCol.TaskId, taskId).
|
||
|
|
Data(data).
|
||
|
|
Update()
|
||
|
|
if err != nil {
|
||
|
|
return 0, err
|
||
|
|
}
|
||
|
|
return r.RowsAffected()
|
||
|
|
}
|