prompts-core

This commit is contained in:
2026-05-15 09:45:51 +08:00
parent c4b8382dbb
commit 6497629fd0
18 changed files with 804 additions and 1643 deletions

View File

@@ -21,41 +21,11 @@ func (d *composeSessionDao) Insert(ctx context.Context, m *entity.ComposeSession
return r.LastInsertId()
}
func (d *composeSessionDao) GetById(ctx context.Context, Id int64) (m *entity.ComposeSession, err error) {
func (d *composeSessionDao) Update(ctx context.Context, m *entity.ComposeSession) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeSession).
Where("deleted_at IS NULL").
Where(entity.ComposeSessionCol.Id, Id).
One()
if err != nil {
return nil, err
}
if r.IsEmpty() {
return nil, nil
}
err = r.Struct(&m)
return
}
func (d *composeSessionDao) GetBySessionId(ctx context.Context, sessionId string) (m *entity.ComposeSession, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeSession).
Where("deleted_at IS NULL").
Where(entity.ComposeSessionCol.SessionId, sessionId).
One()
if err != nil {
return nil, err
}
if r.IsEmpty() {
return nil, nil
}
err = r.Struct(&m)
return
}
func (d *composeSessionDao) UpdateById(ctx context.Context, id int64, data map[string]any) (rows int64, err error) {
data[entity.ComposeSessionCol.Updater] = ""
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeSession).
Where(entity.ComposeSessionCol.Id, id).
Data(data).
Where(entity.ComposeSessionCol.Id, m.Id).
Data(m).
OmitEmpty().
Update()
if err != nil {
return 0, err
@@ -86,6 +56,52 @@ func (d *composeSessionDao) List(ctx context.Context, page, size int, where map[
return
}
func (d *composeSessionDao) GetListBySessionId(ctx context.Context, sessionId string, limit int) ([]*entity.ComposeSession, error) {
var sessions []*entity.ComposeSession
err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeSession).
Where(entity.ComposeSessionCol.SessionId, sessionId).
WhereNull(entity.ComposeSessionCol.DeletedAt).
OrderDesc(entity.ComposeSessionCol.Id).
Limit(limit).
Scan(&sessions)
if err != nil {
return nil, err
}
// 反转成时间正序
for i, j := 0, len(sessions)-1; i < j; i, j = i+1, j-1 {
sessions[i], sessions[j] = sessions[j], sessions[i]
}
return sessions, nil
}
func (d *composeSessionDao) GetById(ctx context.Context, Id int64) (m *entity.ComposeSession, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeSession).
Where(entity.ComposeSessionCol.Id, Id).
One()
if err != nil {
return nil, err
}
if r.IsEmpty() {
return nil, nil
}
err = r.Struct(&m)
return
}
func (d *composeSessionDao) GetBySessionId(ctx context.Context, sessionId string) (m *entity.ComposeSession, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeSession).
Where(entity.ComposeSessionCol.SessionId, sessionId).
One()
if err != nil {
return nil, err
}
if r.IsEmpty() {
return nil, nil
}
err = r.Struct(&m)
return
}
func (d *composeSessionDao) DeleteBySessionId(ctx context.Context, sessionId string) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeSession).
Where(entity.ComposeSessionCol.SessionId, sessionId).