diff --git a/frontend/js/db.js b/frontend/js/db.js index 4f46c8a..a78e309 100644 --- a/frontend/js/db.js +++ b/frontend/js/db.js @@ -205,12 +205,14 @@ async function getRecipeIngredients(recipeId) { } async function saveRecipe(name, cookingMethodId, servings, notes) { - const r = await execute( + await execute( `INSERT INTO recipes (name, cooking_method_id, servings, notes, created_at) VALUES (?1, ?2, ?3, ?4, datetime('now'))`, [name, cookingMethodId ?? null, servings ?? 1, notes ?? null] ); - return r.lastInsertId; + // lastInsertId from tauri-plugin-sql is unreliable; query the actual id + const rows = await select("SELECT id FROM recipes ORDER BY id DESC LIMIT 1"); + return rows[0]?.id; } async function updateRecipe(id, name, cookingMethodId, servings, notes) {