Add sqlc configuration and core queries
CI / ci (push) Successful in 1m25s
Independent review Codex gpt-6-sol high: APPROVED (0 findings)
CI / ci (pull_request) Successful in 1m25s

sqlc.yaml (sqlite, schema migrations/, queries migrations/queries/)
generates internal/db with emit_interface. Queries cover dinners (create,
get, list by status, update, archive, set favorite), recipes with
ingredients and steps (upsert by source_url, get, replace children),
photos (insert, get by sha256) and get/upsert for the five settings
singletons. Repository tests run every query against a migrated temp
database.

make sqlc regenerates with the pinned sqlc v1.31.1 (dev tool only, not in
go.mod); make sqlc-check regenerates and fails on any drift in
internal/db, and CI runs it after make test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-03 09:11:18 -04:00
co-authored by Claude Opus 5.5
parent fa7c6b7218
commit 85ea9c5da4
15 changed files with 2421 additions and 2 deletions
+65
View File
@@ -0,0 +1,65 @@
-- name: UpsertRecipe :one
-- A recipe is keyed by source_url: re-fetching the same URL updates the
-- existing row and keeps its id and created_at, which the returned row
-- carries. Replace its ingredients and steps in the same transaction with
-- DeleteRecipeIngredients/DeleteRecipeSteps then the Create queries.
INSERT INTO recipes (
id, source_url, site_name, title, total_minutes, prep_minutes,
cook_minutes, yield, raw_jsonld, fetched_at, created_at, updated_at
) VALUES (
?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?
)
ON CONFLICT (source_url) DO UPDATE SET
site_name = excluded.site_name,
title = excluded.title,
total_minutes = excluded.total_minutes,
prep_minutes = excluded.prep_minutes,
cook_minutes = excluded.cook_minutes,
yield = excluded.yield,
raw_jsonld = excluded.raw_jsonld,
fetched_at = excluded.fetched_at,
updated_at = excluded.updated_at
RETURNING *;
-- name: GetRecipe :one
SELECT * FROM recipes
WHERE id = ?;
-- name: GetRecipeBySourceURL :one
SELECT * FROM recipes
WHERE source_url = ?;
-- name: CreateRecipeIngredient :exec
INSERT INTO recipe_ingredients (
id, recipe_id, position, raw_text, name, qty, unit, note,
created_at, updated_at
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?,
?, ?
);
-- name: ListRecipeIngredients :many
SELECT * FROM recipe_ingredients
WHERE recipe_id = ?
ORDER BY position, id;
-- name: DeleteRecipeIngredients :exec
DELETE FROM recipe_ingredients
WHERE recipe_id = ?;
-- name: CreateRecipeStep :exec
INSERT INTO recipe_steps (
id, recipe_id, position, text, created_at, updated_at
) VALUES (
?, ?, ?, ?, ?, ?
);
-- name: ListRecipeSteps :many
SELECT * FROM recipe_steps
WHERE recipe_id = ?
ORDER BY position, id;
-- name: DeleteRecipeSteps :exec
DELETE FROM recipe_steps
WHERE recipe_id = ?;