feat(workspace): sqlc queries for workspace/worktree/credential

This commit is contained in:
2026-05-02 07:07:33 +08:00
parent e5800ef5dc
commit 08845f92d7
9 changed files with 838 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
-- name: CreateWorktree :one
INSERT INTO workspace_worktrees (
id, workspace_id, branch, path, status, active_holder, acquired_at
) VALUES ($1,$2,$3,$4,$5,$6,$7)
RETURNING *;
-- name: GetWorktreeByID :one
SELECT * FROM workspace_worktrees WHERE id = $1;
-- name: GetWorktreeByBranchForUpdate :one
SELECT * FROM workspace_worktrees
WHERE workspace_id = $1 AND branch = $2
FOR UPDATE;
-- name: ListWorktreesByWorkspace :many
SELECT * FROM workspace_worktrees
WHERE workspace_id = $1
ORDER BY created_at DESC;
-- name: SetWorktreeActive :one
UPDATE workspace_worktrees
SET status = 'active', active_holder = $2, acquired_at = now(), last_used_at = now()
WHERE id = $1
RETURNING *;
-- name: SetWorktreeIdle :one
UPDATE workspace_worktrees
SET status = 'idle', active_holder = NULL, acquired_at = NULL, last_used_at = now()
WHERE id = $1
RETURNING *;
-- name: SetWorktreePruning :one
UPDATE workspace_worktrees
SET status = 'pruning', last_used_at = now()
WHERE id = $1
RETURNING *;
-- name: DeleteWorktree :exec
DELETE FROM workspace_worktrees WHERE id = $1;