feat(chat): sqlc queries for conversations/messages/attachments/templates/endpoints/models/usage

This commit is contained in:
2026-05-04 09:52:06 +08:00
parent ca5a018cd4
commit a1d0fbc3d3
17 changed files with 1929 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
-- name: InsertConversation :one
INSERT INTO conversations (id, user_id, project_id, workspace_id, issue_id, model_id, system_prompt, title)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *;
-- name: GetConversation :one
SELECT * FROM conversations WHERE id = $1 AND deleted_at IS NULL;
-- name: ListConversationsByUser :many
SELECT * FROM conversations
WHERE user_id = $1 AND deleted_at IS NULL
AND ($2::uuid IS NULL OR project_id = $2)
AND ($3::uuid IS NULL OR workspace_id = $3)
AND ($4::uuid IS NULL OR issue_id = $4)
AND ($5::text = '' OR title ILIKE '%' || $5 || '%')
ORDER BY updated_at DESC
LIMIT $6;
-- name: UpdateConversationTitle :exec
UPDATE conversations SET title = $2, title_generated_at = NOW(), updated_at = NOW()
WHERE id = $1;
-- name: SetConversationTitleManual :exec
UPDATE conversations SET title = $2, updated_at = NOW() WHERE id = $1;
-- name: SoftDeleteConversation :exec
UPDATE conversations SET deleted_at = NOW(), updated_at = NOW()
WHERE id = $1 AND deleted_at IS NULL;