Experiments in applying Entity-Component-System patterns to durable data storage APIs.
1create table if not exists components (
2 entity integer not null,
3 component text not null,
4 data blob,
5 last_modified rfc3339 not null default (strftime ('%Y-%m-%dT%H:%M:%fZ'))
6);
7
8create unique index if not exists components_entity_component_unqiue_idx on components (entity, component);
9
10create index if not exists components_component_idx on components (component);
11
12create trigger if not exists components_last_modified_trigger before
13update on components for each row begin
14update components
15set
16 last_modified = strftime ('%Y-%m-%dT%H:%M:%fZ')
17where
18 entity = new.entity
19 and component = new.component;
20
21end;
22
23create table if not exists changes (
24 sequence integer primary key autoincrement,
25 entity integer not null,
26 component text,
27 change text not null
28);
29
30create table if not exists resources (
31 name text not null unique,
32 data blob,
33 last_modified rfc3339 not null default (strftime ('%Y-%m-%dT%H:%M:%fZ'))
34);
35
36create trigger if not exists resources_last_modified_trigger before
37update on resources for each row begin
38update resources
39set
40 last_modified = strftime ('%Y-%m-%dT%H:%M:%fZ')
41where
42 name = new.name;
43
44end;