WIP: convert GORM to sqlc, for jobs/tasks #104304

Closed
Sybren A. Stüvel wants to merge 27 commits from sqlc-task into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 36 additions and 5 deletions
Showing only changes of commit 3a4851f94a - Show all commits

View File

@ -572,11 +572,18 @@ func (db *DB) SaveTask(ctx context.Context, t *Task) error {
} }
func (db *DB) SaveTaskStatus(ctx context.Context, t *Task) error { func (db *DB) SaveTaskStatus(ctx context.Context, t *Task) error {
tx := db.gormDB.WithContext(ctx). queries, err := db.queries()
Select("Status"). if err != nil {
Save(t) return err
if tx.Error != nil { }
return taskError(tx.Error, "saving task")
err = queries.UpdateTaskStatus(ctx, sqlc.UpdateTaskStatusParams{
UpdatedAt: db.now(),
Status: string(t.Status),
ID: int64(t.ID),
})
if err != nil {
return taskError(err, "saving task status")
} }
return nil return nil
} }

View File

@ -88,3 +88,9 @@ UPDATE tasks SET
commands = @commands, commands = @commands,
activity = @activity activity = @activity
WHERE id=@id; WHERE id=@id;
-- name: UpdateTaskStatus :exec
UPDATE tasks SET
updated_at = @updated_at,
status = @status
WHERE id=@id;

View File

@ -423,3 +423,21 @@ func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) error {
) )
return err return err
} }
const updateTaskStatus = `-- name: UpdateTaskStatus :exec
UPDATE tasks SET
updated_at = ?1,
status = ?2
WHERE id=?3
`
type UpdateTaskStatusParams struct {
UpdatedAt sql.NullTime
Status string
ID int64
}
func (q *Queries) UpdateTaskStatus(ctx context.Context, arg UpdateTaskStatusParams) error {
_, err := q.db.ExecContext(ctx, updateTaskStatus, arg.UpdatedAt, arg.Status, arg.ID)
return err
}