diff --git a/food.ddl b/food.ddl index 3a9be29..2fc1e69 100644 --- a/food.ddl +++ b/food.ddl @@ -5,17 +5,6 @@ create table weight ( weight real not null ); --- begin TRANSACTION; --- drop table if exists weight2; --- create table weight2 ( --- date datetime default (datetime('now', '+2 hours')), --- weight real not null --- ); --- insert into weight2(date, weight) --- select date, weight from weight; --- drop table weight; --- alter table weight2 rename to weight; --- commit; create index weightDateIdx on weight(date); create index weightDailyIdx on weight(strftime('%Y-%m-%d', date)); @@ -36,7 +25,6 @@ select rowid, from weight order by date desc; --- Daily Summary View create view weightDaily as select strftime('%Y-%m-%d', date) as period, round(avg(weight), 2) as amount @@ -44,7 +32,6 @@ select strftime('%Y-%m-%d', date) as period, group by strftime('%Y-%m-%d', date) order by date desc; --- Weekly Summary View create view weightWeekly as select strftime('%Y-%W', date) as period, round(avg(weight), 2) as amount @@ -52,7 +39,6 @@ select strftime('%Y-%W', date) as period, group by strftime('%Y-%W', date) order by date desc; --- Monthly Summary View create view weightMonthly as select strftime('%Y-%m', date) as period, round(avg(weight), 2) as amount @@ -60,7 +46,6 @@ select strftime('%Y-%m', date) as period, group by strftime('%Y-%m', date) order by date desc; --- Yearly Summary View create view weightYearly as select strftime('%Y', date) as period, round(avg(weight), 2) as amount @@ -77,21 +62,6 @@ create table food( energy generated always as (coalesce(amount, 0) * coalesce(per100, 0) / 100) stored ); --- begin transaction; --- drop table if exists food2; --- create table food2( --- date datetime default (datetime('now', '+2 hours')), --- food varchar not null, --- description varchar, --- amount real not null, --- per100 real default 0, --- energy generated always as (coalesce(amount, 0) * coalesce(per100, 0) / 100) stored --- ); --- insert into food2(date, food, description, amount, per100) --- select date, food, description, amount, per100 from food; --- drop table food; --- alter table food2 rename to food; --- commit; create index dailyIdx on food(strftime('%Y-%m-%d', date)); create index weeklyIdx on food(strftime('%Y-%W', date)); create index monthlyIdx on food(strftime('%Y-%m', date)); @@ -100,11 +70,11 @@ create index dateIdx on food(date); create index foodIdx on food(food); drop view if exists foodView; -drop view if exists daily; -drop view if exists weekly; -drop view if exists monthly; -drop view if exists yearly; -drop view if exists recent; +drop view if exists foodDaily; +drop view if exists foodWeekly; +drop view if exists foodMonthly; +drop view if exists foodYearly; +drop view if exists foodRecent; create view foodView as select rowid, @@ -116,8 +86,7 @@ select rowid, round(energy, 2) as energy from food; --- Daily Summary View -create view daily as +create view foodDaily as select strftime('%Y-%m-%d', date) as period, round(sum(amount), 2) as amount, round(avg(per100), 2) as avgPer100, @@ -126,8 +95,7 @@ from food group by strftime('%Y-%m-%d', date) order by date desc; --- Weekly Summary View -create view weekly as +create view foodWeekly as select strftime('%Y-%W', date) as period, round(sum(amount), 2) as amount, round(avg(per100), 2) as avgPer100, @@ -136,8 +104,7 @@ from food group by strftime('%Y-%W', date) order by date desc; --- Monthly Summary View -create view monthly as +create view foodMonthly as select strftime('%Y-%m', date) as period, round(sum(amount), 2) as amount, round(avg(per100), 2) as avgPer100, @@ -146,8 +113,7 @@ from food group by strftime('%Y-%m', date) order by date desc; --- Yearly Summary View -create view yearly as +create view foodYearly as select strftime('%Y', date) as period, round(sum(amount), 2) as amount, round(avg(per100), 2) as avgPer100, @@ -156,8 +122,7 @@ from food group by strftime('%Y', date) order by date desc; --- Recent -create view recent as +create view foodRecent as select rowid, * from food @@ -183,5 +148,4 @@ set per100 = coalesce( where rowid = new .rowid; end; -create table settings (key text, value text) --rollback; commit; \ No newline at end of file