Feature 02 task 4: sqlc configuration and core queries (#13)
Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com> Co-committed-by: dev_agent <dev_agent@cubecraftlabs.com>
This commit was merged in pull request #13.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
-- name: CreateDinner :one
|
||||
INSERT INTO dinners (
|
||||
id, name, normalized_name, status, origin, method, minutes_total,
|
||||
difficulty, cuisine, is_favorite, recipe_id, photo_id, grounding_status,
|
||||
updated_by, created_at, updated_at
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetDinner :one
|
||||
SELECT * FROM dinners
|
||||
WHERE id = ?;
|
||||
|
||||
-- name: ListDinnersByStatus :many
|
||||
SELECT * FROM dinners
|
||||
WHERE status = ?
|
||||
ORDER BY normalized_name, id;
|
||||
|
||||
-- name: UpdateDinner :one
|
||||
-- An unknown id returns sql.ErrNoRows.
|
||||
UPDATE dinners
|
||||
SET name = ?,
|
||||
normalized_name = ?,
|
||||
status = ?,
|
||||
origin = ?,
|
||||
method = ?,
|
||||
minutes_total = ?,
|
||||
difficulty = ?,
|
||||
cuisine = ?,
|
||||
recipe_id = ?,
|
||||
photo_id = ?,
|
||||
grounding_status = ?,
|
||||
updated_by = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
RETURNING *;
|
||||
|
||||
-- name: ArchiveDinner :one
|
||||
-- An unknown id returns sql.ErrNoRows.
|
||||
UPDATE dinners
|
||||
SET status = 'archived',
|
||||
updated_by = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
RETURNING *;
|
||||
|
||||
-- name: SetDinnerFavorite :one
|
||||
-- An unknown id returns sql.ErrNoRows.
|
||||
UPDATE dinners
|
||||
SET is_favorite = ?,
|
||||
updated_by = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
RETURNING *;
|
||||
@@ -0,0 +1,17 @@
|
||||
-- name: CreatePhoto :one
|
||||
INSERT INTO photos (
|
||||
id, source_url, local_path, width, height, sha256, fetched_at,
|
||||
created_at, updated_at
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetPhotoBySHA256 :one
|
||||
-- Finds stored image bytes by content hash. The schema does not make sha256
|
||||
-- unique, so the earliest-created (lowest id) match is returned.
|
||||
SELECT * FROM photos
|
||||
WHERE sha256 = ?
|
||||
ORDER BY id
|
||||
LIMIT 1;
|
||||
@@ -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 = ?;
|
||||
@@ -0,0 +1,128 @@
|
||||
-- name: GetHouseholdSettings :one
|
||||
-- Returns sql.ErrNoRows until the row exists.
|
||||
SELECT * FROM household_settings
|
||||
WHERE id = 1;
|
||||
|
||||
-- name: UpsertHouseholdSettings :one
|
||||
-- Creates the single row (id 1) or replaces every column except id and
|
||||
-- created_at.
|
||||
INSERT INTO household_settings (
|
||||
id, timezone, dinner_time, reminder_time, review_time, plan_draft_dow,
|
||||
plan_draft_time, suggestions_dow, suggestions_time, chat_autosend_dow,
|
||||
chat_autosend_time, onboarding_completed_at, updates_seen_at,
|
||||
created_at, updated_at
|
||||
) VALUES (
|
||||
1, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
timezone = excluded.timezone,
|
||||
dinner_time = excluded.dinner_time,
|
||||
reminder_time = excluded.reminder_time,
|
||||
review_time = excluded.review_time,
|
||||
plan_draft_dow = excluded.plan_draft_dow,
|
||||
plan_draft_time = excluded.plan_draft_time,
|
||||
suggestions_dow = excluded.suggestions_dow,
|
||||
suggestions_time = excluded.suggestions_time,
|
||||
chat_autosend_dow = excluded.chat_autosend_dow,
|
||||
chat_autosend_time = excluded.chat_autosend_time,
|
||||
onboarding_completed_at = excluded.onboarding_completed_at,
|
||||
updates_seen_at = excluded.updates_seen_at,
|
||||
updated_at = excluded.updated_at
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetAISettings :one
|
||||
-- Returns sql.ErrNoRows until the row exists.
|
||||
SELECT * FROM ai_settings
|
||||
WHERE id = 1;
|
||||
|
||||
-- name: UpsertAISettings :one
|
||||
-- Creates the single row (id 1) or replaces every column except id and
|
||||
-- created_at.
|
||||
INSERT INTO ai_settings (
|
||||
id, provider, base_url, model, temperature, system_prompt, api_key_ct,
|
||||
api_key_last4, key_verified_at, created_at, updated_at
|
||||
) VALUES (
|
||||
1, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
provider = excluded.provider,
|
||||
base_url = excluded.base_url,
|
||||
model = excluded.model,
|
||||
temperature = excluded.temperature,
|
||||
system_prompt = excluded.system_prompt,
|
||||
api_key_ct = excluded.api_key_ct,
|
||||
api_key_last4 = excluded.api_key_last4,
|
||||
key_verified_at = excluded.key_verified_at,
|
||||
updated_at = excluded.updated_at
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetRecipeSearchSettings :one
|
||||
-- Returns sql.ErrNoRows until the row exists.
|
||||
SELECT * FROM recipe_search_settings
|
||||
WHERE id = 1;
|
||||
|
||||
-- name: UpsertRecipeSearchSettings :one
|
||||
-- Creates the single row (id 1) or replaces every column except id and
|
||||
-- created_at.
|
||||
INSERT INTO recipe_search_settings (
|
||||
id, provider, base_url, api_key_ct, created_at, updated_at
|
||||
) VALUES (
|
||||
1, ?, ?, ?, ?, ?
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
provider = excluded.provider,
|
||||
base_url = excluded.base_url,
|
||||
api_key_ct = excluded.api_key_ct,
|
||||
updated_at = excluded.updated_at
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetIntegrationsGoogle :one
|
||||
-- Returns sql.ErrNoRows until the row exists.
|
||||
SELECT * FROM integrations_google
|
||||
WHERE id = 1;
|
||||
|
||||
-- name: UpsertIntegrationsGoogle :one
|
||||
-- Creates the single row (id 1) or replaces every column except id and
|
||||
-- created_at.
|
||||
INSERT INTO integrations_google (
|
||||
id, refresh_token_ct, calendar_id, calendar_name, connected_at,
|
||||
last_sync_error, created_at, updated_at
|
||||
) VALUES (
|
||||
1, ?, ?, ?, ?,
|
||||
?, ?, ?
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
refresh_token_ct = excluded.refresh_token_ct,
|
||||
calendar_id = excluded.calendar_id,
|
||||
calendar_name = excluded.calendar_name,
|
||||
connected_at = excluded.connected_at,
|
||||
last_sync_error = excluded.last_sync_error,
|
||||
updated_at = excluded.updated_at
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetChatSettings :one
|
||||
-- Returns sql.ErrNoRows until the row exists.
|
||||
SELECT * FROM chat_settings
|
||||
WHERE id = 1;
|
||||
|
||||
-- name: UpsertChatSettings :one
|
||||
-- Creates the single row (id 1) or replaces every column except id and
|
||||
-- created_at.
|
||||
INSERT INTO chat_settings (
|
||||
id, webhook_url_ct, space_label, last_test_at, last_test_status,
|
||||
created_at, updated_at
|
||||
) VALUES (
|
||||
1, ?, ?, ?, ?,
|
||||
?, ?
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
webhook_url_ct = excluded.webhook_url_ct,
|
||||
space_label = excluded.space_label,
|
||||
last_test_at = excluded.last_test_at,
|
||||
last_test_status = excluded.last_test_status,
|
||||
updated_at = excluded.updated_at
|
||||
RETURNING *;
|
||||
Reference in New Issue
Block a user