Skip to content

Commit 4bd0114

Browse files
committed
example app uses migration tooling
1 parent 7f18724 commit 4bd0114

File tree

16 files changed

+2264
-133
lines changed

16 files changed

+2264
-133
lines changed

examples/app/build.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ targets:
1616
drift_dev:
1717
# These options change how drift generates code
1818
options:
19+
databases:
20+
default: lib/database/database.dart
1921
# Drift analyzes SQL queries at compile-time. For this purpose, it needs to know which sqlite3
2022
# features will be available. We depend on `sqlite3_flutter_libs`, which lets us use the latest
2123
# version with fts5 enabled.
@@ -41,13 +43,13 @@ targets:
4143
dependencies: [$default]
4244
builders:
4345
":copy_compiled_worker_js":
44-
enabled: true
46+
enabled: true
4547

4648
# build_web_compilers writes a hidden asset, but we want an asset in `web/` for
4749
# flutter to see. So, copy that output. Again, this is not needed for most apps.
4850
builders:
4951
copy_compiled_worker_js:
50-
import: 'tool/builder.dart'
52+
import: "tool/builder.dart"
5153
builder_factories: ["CopyCompiledJs.new"]
5254
build_to: source
53-
build_extensions: {'web/worker.dart.js': ['web/drift_worker.js']}
55+
build_extensions: { "web/worker.dart.js": ["web/drift_worker.js"] }
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"_meta": {
3+
"description": "This file contains a serialized version of schema entities for moor.",
4+
"version": "0.1.0-dev-preview"
5+
},
6+
"entities": [
7+
{
8+
"id": 0,
9+
"references": [],
10+
"type": "table",
11+
"data": {
12+
"name": "categories",
13+
"was_declared_in_moor": false,
14+
"columns": [
15+
{
16+
"name": "id",
17+
"getter_name": "id",
18+
"moor_type": "ColumnType.integer",
19+
"nullable": false,
20+
"customConstraints": null,
21+
"default_dart": null,
22+
"default_client_dart": null,
23+
"dsl_features": ["auto-increment", "primary-key"]
24+
},
25+
{
26+
"name": "name",
27+
"getter_name": "name",
28+
"moor_type": "ColumnType.text",
29+
"nullable": false,
30+
"customConstraints": null,
31+
"default_dart": null,
32+
"default_client_dart": null,
33+
"dsl_features": []
34+
},
35+
{
36+
"name": "color",
37+
"getter_name": "color",
38+
"moor_type": "ColumnType.integer",
39+
"nullable": false,
40+
"customConstraints": null,
41+
"default_dart": null,
42+
"default_client_dart": null,
43+
"dsl_features": [],
44+
"type_converter": {
45+
"dart_expr": "const ColorConverter()",
46+
"dart_type_name": "Color"
47+
}
48+
}
49+
],
50+
"is_virtual": false
51+
}
52+
},
53+
{
54+
"id": 1,
55+
"references": [0],
56+
"type": "table",
57+
"data": {
58+
"name": "todo_entries",
59+
"was_declared_in_moor": false,
60+
"columns": [
61+
{
62+
"name": "id",
63+
"getter_name": "id",
64+
"moor_type": "ColumnType.integer",
65+
"nullable": false,
66+
"customConstraints": null,
67+
"default_dart": null,
68+
"default_client_dart": null,
69+
"dsl_features": ["auto-increment", "primary-key"]
70+
},
71+
{
72+
"name": "description",
73+
"getter_name": "description",
74+
"moor_type": "ColumnType.text",
75+
"nullable": false,
76+
"customConstraints": null,
77+
"default_dart": null,
78+
"default_client_dart": null,
79+
"dsl_features": []
80+
},
81+
{
82+
"name": "category",
83+
"getter_name": "category",
84+
"moor_type": "ColumnType.integer",
85+
"nullable": true,
86+
"customConstraints": null,
87+
"default_dart": null,
88+
"default_client_dart": null,
89+
"dsl_features": ["unknown"]
90+
},
91+
{
92+
"name": "due_date",
93+
"getter_name": "dueDate",
94+
"moor_type": "ColumnType.datetime",
95+
"nullable": true,
96+
"customConstraints": null,
97+
"default_dart": null,
98+
"default_client_dart": null,
99+
"dsl_features": []
100+
}
101+
],
102+
"is_virtual": false
103+
}
104+
},
105+
{
106+
"id": 2,
107+
"references": [],
108+
"type": "table",
109+
"data": {
110+
"name": "text_entries",
111+
"was_declared_in_moor": true,
112+
"columns": [
113+
{
114+
"name": "description",
115+
"getter_name": "description",
116+
"moor_type": "ColumnType.text",
117+
"nullable": false,
118+
"customConstraints": "",
119+
"default_dart": null,
120+
"default_client_dart": null,
121+
"dsl_features": []
122+
}
123+
],
124+
"is_virtual": true,
125+
"create_virtual_stmt": "CREATE VIRTUAL TABLE text_entries USING fts5 (\n description,\n content=todo_entries,\n content_rowid=id\n);"
126+
}
127+
},
128+
{
129+
"id": 3,
130+
"references": [1, 2],
131+
"type": "trigger",
132+
"data": {
133+
"on": 1,
134+
"refences_in_body": [2, 1],
135+
"name": "todos_insert",
136+
"sql": "CREATE TRIGGER todos_insert AFTER INSERT ON todo_entries BEGIN\n INSERT INTO text_entries(rowid, description) VALUES (new.id, new.description);\nEND;"
137+
}
138+
}
139+
]
140+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_meta":{"description":"This file contains a serialized version of schema entities for drift.","version":"1.2.0"},"options":{"store_date_time_values_as_text":false},"entities":[{"id":0,"references":[],"type":"table","data":{"name":"categories","was_declared_in_moor":false,"columns":[{"name":"id","getter_name":"id","moor_type":"int","nullable":false,"customConstraints":null,"defaultConstraints":"PRIMARY KEY AUTOINCREMENT","dialectAwareDefaultConstraints":{"sqlite":"PRIMARY KEY AUTOINCREMENT"},"default_dart":null,"default_client_dart":null,"dsl_features":["auto-increment"]},{"name":"name","getter_name":"name","moor_type":"string","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"color","getter_name":"color","moor_type":"int","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[],"type_converter":{"dart_expr":"const ColorConverter()","dart_type_name":"Color"}}],"is_virtual":false,"without_rowid":false,"constraints":[]}},{"id":1,"references":[0],"type":"table","data":{"name":"todo_entries","was_declared_in_moor":false,"columns":[{"name":"id","getter_name":"id","moor_type":"int","nullable":false,"customConstraints":null,"defaultConstraints":"PRIMARY KEY AUTOINCREMENT","dialectAwareDefaultConstraints":{"sqlite":"PRIMARY KEY AUTOINCREMENT"},"default_dart":null,"default_client_dart":null,"dsl_features":["auto-increment"]},{"name":"description","getter_name":"description","moor_type":"string","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"category","getter_name":"category","moor_type":"int","nullable":true,"customConstraints":null,"defaultConstraints":"REFERENCES categories (id)","dialectAwareDefaultConstraints":{"sqlite":"REFERENCES categories (id)"},"default_dart":null,"default_client_dart":null,"dsl_features":["unknown"]},{"name":"due_date","getter_name":"dueDate","moor_type":"dateTime","nullable":true,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]}],"is_virtual":false,"without_rowid":false,"constraints":[]}},{"id":2,"references":[1],"type":"table","data":{"name":"text_entries","was_declared_in_moor":true,"columns":[{"name":"description","getter_name":"description","moor_type":"string","nullable":false,"customConstraints":"","default_dart":null,"default_client_dart":null,"dsl_features":[]}],"is_virtual":true,"create_virtual_stmt":"CREATE VIRTUAL TABLE \"text_entries\" USING fts5(description, content=todo_entries, content_rowid=id)","without_rowid":false,"constraints":[]}},{"id":3,"references":[1,2],"type":"trigger","data":{"on":1,"references_in_body":[1,2],"name":"todos_insert","sql":"CREATE TRIGGER todos_insert AFTER INSERT ON todo_entries BEGIN\r\n INSERT INTO text_entries(rowid, description) VALUES (new.id, new.description);\r\nEND;"}},{"id":4,"references":[1,2],"type":"trigger","data":{"on":1,"references_in_body":[1,2],"name":"todos_delete","sql":"CREATE TRIGGER todos_delete AFTER DELETE ON todo_entries BEGIN\r\n INSERT INTO text_entries(text_entries, rowid, description) VALUES ('delete', old.id, old.description);\r\nEND;"}},{"id":5,"references":[1,2],"type":"trigger","data":{"on":1,"references_in_body":[1,2],"name":"todos_update","sql":"CREATE TRIGGER todos_update AFTER UPDATE ON todo_entries BEGIN\r\n INSERT INTO text_entries(text_entries, rowid, description) VALUES ('delete', new.id, new.description);\r\n INSERT INTO text_entries(rowid, description) VALUES (new.id, new.description);\r\nEND;"}}]}

examples/app/drift_schemas/drift_schema_v2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/app/drift_schemas/drift_schema_v3.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/app/lib/database/database.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@ part 'database.g.dart';
1616

1717
@DriftDatabase(tables: [TodoEntries, Categories], include: {'sql.drift'})
1818
class AppDatabase extends _$AppDatabase {
19-
AppDatabase()
19+
AppDatabase([QueryExecutor? e])
2020
: super(
21-
driftDatabase(
22-
name: 'todo-app',
23-
web: DriftWebOptions(
24-
sqlite3Wasm: Uri.parse('sqlite3.wasm'),
25-
driftWorker: Uri.parse('drift_worker.js'),
26-
onResult: (result) {
27-
if (result.missingFeatures.isNotEmpty) {
28-
debugPrint(
29-
'Using ${result.chosenImplementation} due to unsupported '
30-
'browser features: ${result.missingFeatures}');
31-
}
32-
}),
33-
),
21+
e ??
22+
driftDatabase(
23+
name: 'todo-app',
24+
web: DriftWebOptions(
25+
sqlite3Wasm: Uri.parse('sqlite3.wasm'),
26+
driftWorker: Uri.parse('drift_worker.js'),
27+
onResult: (result) {
28+
if (result.missingFeatures.isNotEmpty) {
29+
debugPrint(
30+
'Using ${result.chosenImplementation} due to unsupported '
31+
'browser features: ${result.missingFeatures}');
32+
}
33+
}),
34+
),
3435
);
3536

3637
AppDatabase.forTesting(DatabaseConnection super.connection);

0 commit comments

Comments
 (0)