-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathapp_database.dart
81 lines (67 loc) · 2.43 KB
/
app_database.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import 'package:drift/drift.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
// Conditional import implementation based on the Drift Flutter web example:
// https://github.com/simolus3/drift/tree/develop/examples/app
import 'connection/connection.dart' as impl;
part 'app_database.g.dart';
// * Table definitions
/// Represents a new app created by the user
@DataClassName('AppData')
class Apps extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text().withLength(min: 1, max: 100)();
}
/// Epic definition data (synced from the JSON template)
@DataClassName('EpicData')
class Epics extends Table {
TextColumn get id =>
text().withLength(min: 1, max: 8).customConstraint('UNIQUE NOT NULL')();
IntColumn get order => integer().customConstraint('UNIQUE NOT NULL')();
TextColumn get name => text().withLength(min: 1, max: 100)();
@override
Set<Column> get primaryKey => {id};
}
/// Task definition data (synced from the JSON template)
@DataClassName('TaskData')
class Tasks extends Table {
TextColumn get id => text().withLength(min: 1, max: 8)();
TextColumn get epicId => text()
.withLength(min: 1, max: 8)
.customConstraint('NOT NULL REFERENCES epics(id)')();
IntColumn get order => integer().customConstraint('UNIQUE NOT NULL')();
TextColumn get name => text().withLength(min: 1, max: 100)();
@override
Set<Column> get primaryKey => {id};
}
/// Task completed status for a given app and epic
@DataClassName('TaskStatusData')
class TaskStatuses extends Table {
IntColumn get appId =>
integer().customConstraint('NOT NULL REFERENCES apps(id)')();
TextColumn get taskId => text()
.withLength(min: 1, max: 8)
.customConstraint('NOT NULL REFERENCES tasks(id)')();
BoolColumn get completed => boolean().withDefault(const Constant(false))();
@override
Set<Column> get primaryKey => {taskId, appId};
@override
List<String> get customConstraints => ['UNIQUE (app_id, task_id)'];
}
/// The database class declaring all the tables used in this project
@DriftDatabase(tables: [
Apps,
Epics,
Tasks,
TaskStatuses,
])
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(impl.connect());
@override
int get schemaVersion => 1;
}
@Riverpod(keepAlive: true)
AppDatabase appDatabase(Ref ref) {
return AppDatabase();
}
// ignore_for_file:prefer-declaring-const-constructor