diff --git a/src/lib/database/food.ts b/src/lib/database/food.ts index 6c52004..a7dc71c 100644 --- a/src/lib/database/food.ts +++ b/src/lib/database/food.ts @@ -32,7 +32,7 @@ order by date desc async GetAllForDate(date: Date) { return await db.select(` select ${columns.join(', ')} -from food +from foodView where strftime('%Y-%m-%d', date) = strftime('%Y-%m-%d', '2024-06-12') or strftime('%Y-%m-%d', date) = strftime('%Y-%m-%d', date('2024-06-12', '-1 day')) order by date DESC; @@ -43,7 +43,7 @@ order by date DESC; if (!food.amount) throw [[food], 'food.amount is required'] const res = await db.execute(`insert into food (food, description, amount) values ($1, $2, $3)`, [food.food, food.description, food.amount]) - const row = await db.select(`select ${columns.join(', ')} from food where rowid = $1`, [res.lastInsertId]) + const row = await db.select(`select ${columns.join(', ')} from foodView where rowid = $1`, [res.lastInsertId]) return [row, null] }, @@ -51,7 +51,7 @@ order by date DESC; if (!food) return [-1, 'food is required'] const rows: { per100: number }[] = await db.select<{ per100: number }[]>(` select per100 -from food +from foodView where food = $1 and per100 is not null order by date desc @@ -85,7 +85,7 @@ amount = $1, per100 = $2 where rowid = $3 `, [food.amount, food.per100, food.rowid]) - const res = await db.select(`select ${columns.join(', ')} from food where rowid = $1`, [food.rowid]) + const res = await db.select(`select ${columns.join(', ')} from foodView where rowid = $1`, [food.rowid]) if (!res) return [food, 'no data found'] if (res.length == 0) return [food, 'no data found'] if (!res[0]) return [food, 'no data found']