Create a view for rounding the floats
This commit is contained in:
@@ -32,7 +32,7 @@ order by date desc
|
|||||||
async GetAllForDate(date: Date) {
|
async GetAllForDate(date: Date) {
|
||||||
return await db.select<Food[]>(`
|
return await db.select<Food[]>(`
|
||||||
select ${columns.join(', ')}
|
select ${columns.join(', ')}
|
||||||
from food
|
from foodView
|
||||||
where strftime('%Y-%m-%d', date) = strftime('%Y-%m-%d', '2024-06-12')
|
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'))
|
or strftime('%Y-%m-%d', date) = strftime('%Y-%m-%d', date('2024-06-12', '-1 day'))
|
||||||
order by date DESC;
|
order by date DESC;
|
||||||
@@ -43,7 +43,7 @@ order by date DESC;
|
|||||||
if (!food.amount) throw [[food], 'food.amount is required']
|
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 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<Food[]>(`select ${columns.join(', ')} from food where rowid = $1`, [res.lastInsertId])
|
const row = await db.select<Food[]>(`select ${columns.join(', ')} from foodView where rowid = $1`, [res.lastInsertId])
|
||||||
|
|
||||||
return [row, null]
|
return [row, null]
|
||||||
},
|
},
|
||||||
@@ -51,7 +51,7 @@ order by date DESC;
|
|||||||
if (!food) return [-1, 'food is required']
|
if (!food) return [-1, 'food is required']
|
||||||
const rows: { per100: number }[] = await db.select<{ per100: number }[]>(`
|
const rows: { per100: number }[] = await db.select<{ per100: number }[]>(`
|
||||||
select per100
|
select per100
|
||||||
from food
|
from foodView
|
||||||
where food = $1
|
where food = $1
|
||||||
and per100 is not null
|
and per100 is not null
|
||||||
order by date desc
|
order by date desc
|
||||||
@@ -85,7 +85,7 @@ amount = $1,
|
|||||||
per100 = $2
|
per100 = $2
|
||||||
where rowid = $3
|
where rowid = $3
|
||||||
`, [food.amount, food.per100, food.rowid])
|
`, [food.amount, food.per100, food.rowid])
|
||||||
const res = await db.select<Food[]>(`select ${columns.join(', ')} from food where rowid = $1`, [food.rowid])
|
const res = await db.select<Food[]>(`select ${columns.join(', ')} from foodView where rowid = $1`, [food.rowid])
|
||||||
if (!res) return [food, 'no data found']
|
if (!res) return [food, 'no data found']
|
||||||
if (res.length == 0) return [food, 'no data found']
|
if (res.length == 0) return [food, 'no data found']
|
||||||
if (!res[0]) return [food, 'no data found']
|
if (!res[0]) return [food, 'no data found']
|
||||||
|
Reference in New Issue
Block a user