- 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
19 lines
605 B
SQL
19 lines
605 B
SQL
-- 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;
|