feat(02-01): add sqlc queries + citext/uuid overrides; generate bindings

- sqlc.yaml: overrides citext→string and uuid→uuid.UUID (Pattern 10, Pitfall 3)
- users.sql: InsertUser :one and GetUserByEmail :one
- sessions.sql: InsertSession :exec, GetSessionWithUser :one (expires_at > now() per D-07),
  DeleteSession :exec, DeleteSessionsByUser :exec, ExtendSession :exec
- sqlc generate produces Email string (not pgtype.Text) and uuid.UUID in bindings
- go build ./internal/db/... exits 0
This commit is contained in:
Arthur Belleville 2026-05-14 21:52:48 +02:00
parent 513044de58
commit 799c26099e
No known key found for this signature in database
3 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,19 @@
-- name: InsertSession :exec
INSERT INTO sessions (id, user_id, expires_at)
VALUES ($1, $2, $3);
-- name: GetSessionWithUser :one
SELECT s.id, s.user_id, s.created_at, s.expires_at,
u.id AS u_id, u.email, u.password_hash, u.created_at AS u_created_at, u.updated_at AS u_updated_at
FROM sessions s
JOIN users u ON u.id = s.user_id
WHERE s.id = $1 AND s.expires_at > now();
-- name: DeleteSession :exec
DELETE FROM sessions WHERE id = $1;
-- name: DeleteSessionsByUser :exec
DELETE FROM sessions WHERE user_id = $1;
-- name: ExtendSession :exec
UPDATE sessions SET expires_at = $2 WHERE id = $1;

View file

@ -0,0 +1,9 @@
-- name: InsertUser :one
INSERT INTO users (email, password_hash)
VALUES ($1, $2)
RETURNING id, email, password_hash, created_at, updated_at;
-- name: GetUserByEmail :one
SELECT id, email, password_hash, created_at, updated_at
FROM users
WHERE email = $1;

View file

@ -10,3 +10,10 @@ sql:
sql_package: "pgx/v5"
emit_json_tags: false
emit_interface: false
overrides:
- db_type: "citext"
go_type: "string"
- db_type: "uuid"
go_type:
import: "github.com/google/uuid"
type: "UUID"