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 35 additions and 4 deletions
Showing only changes of commit c31d492b7a - Show all commits

View File

@ -589,10 +589,17 @@ func (db *DB) SaveTaskStatus(ctx context.Context, t *Task) error {
} }
func (db *DB) SaveTaskActivity(ctx context.Context, t *Task) error { func (db *DB) SaveTaskActivity(ctx context.Context, t *Task) error {
if err := db.gormDB.WithContext(ctx). queries, err := db.queries()
Model(t). if err != nil {
Select("Activity"). return err
Updates(Task{Activity: t.Activity}).Error; err != nil { }
err = queries.UpdateTaskActivity(ctx, sqlc.UpdateTaskActivityParams{
UpdatedAt: db.now(),
Activity: t.Activity,
ID: int64(t.ID),
})
if err != nil {
return taskError(err, "saving task activity") return taskError(err, "saving task activity")
} }
return nil return nil

View File

@ -94,3 +94,9 @@ UPDATE tasks SET
updated_at = @updated_at, updated_at = @updated_at,
status = @status status = @status
WHERE id=@id; WHERE id=@id;
-- name: UpdateTaskActivity :exec
UPDATE tasks SET
updated_at = @updated_at,
activity = @activity
WHERE id=@id;

View File

@ -424,6 +424,24 @@ func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) error {
return err return err
} }
const updateTaskActivity = `-- name: UpdateTaskActivity :exec
UPDATE tasks SET
updated_at = ?1,
activity = ?2
WHERE id=?3
`
type UpdateTaskActivityParams struct {
UpdatedAt sql.NullTime
Activity string
ID int64
}
func (q *Queries) UpdateTaskActivity(ctx context.Context, arg UpdateTaskActivityParams) error {
_, err := q.db.ExecContext(ctx, updateTaskActivity, arg.UpdatedAt, arg.Activity, arg.ID)
return err
}
const updateTaskStatus = `-- name: UpdateTaskStatus :exec const updateTaskStatus = `-- name: UpdateTaskStatus :exec
UPDATE tasks SET UPDATE tasks SET
updated_at = ?1, updated_at = ?1,