- 0003_tablos.sql: tablos table with user_id FK + ON DELETE CASCADE + tablos_user_id_idx - tablos.sql: 5 named queries (ListTablosByUser, GetTabloByID, InsertTablo, UpdateTablo, DeleteTablo) - UpdateTablo sets updated_at = now() explicitly (Pitfall 7) - color not editable in UpdateTablo per Phase 3 scope - sqlc generates Tablo struct with pgtype.Text for description/color (not committed per .gitignore convention)
24 lines
709 B
SQL
24 lines
709 B
SQL
-- name: ListTablosByUser :many
|
|
SELECT id, user_id, title, description, color, created_at, updated_at
|
|
FROM tablos
|
|
WHERE user_id = $1
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: GetTabloByID :one
|
|
SELECT id, user_id, title, description, color, created_at, updated_at
|
|
FROM tablos
|
|
WHERE id = $1;
|
|
|
|
-- name: InsertTablo :one
|
|
INSERT INTO tablos (user_id, title, description, color)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING id, user_id, title, description, color, created_at, updated_at;
|
|
|
|
-- name: UpdateTablo :one
|
|
UPDATE tablos
|
|
SET title = $2, description = $3, updated_at = now()
|
|
WHERE id = $1
|
|
RETURNING id, user_id, title, description, color, created_at, updated_at;
|
|
|
|
-- name: DeleteTablo :exec
|
|
DELETE FROM tablos WHERE id = $1;
|