2019-03-09 07:37:22 -08:00
|
|
|
import 'package:moor/moor.dart';
|
2019-02-14 07:01:57 -08:00
|
|
|
|
2019-02-14 07:53:52 -08:00
|
|
|
part 'todos.g.dart';
|
|
|
|
|
2019-02-14 07:01:57 -08:00
|
|
|
@DataClassName('TodoEntry')
|
|
|
|
class TodosTable extends Table {
|
2019-02-14 07:53:52 -08:00
|
|
|
@override
|
|
|
|
String get tableName => 'todos';
|
|
|
|
|
2019-02-14 07:01:57 -08:00
|
|
|
IntColumn get id => integer().autoIncrement()();
|
2019-02-14 07:53:52 -08:00
|
|
|
TextColumn get title => text().withLength(min: 4, max: 16).nullable()();
|
2019-02-14 07:01:57 -08:00
|
|
|
TextColumn get content => text()();
|
2019-06-04 13:04:21 -07:00
|
|
|
@JsonKey('target_date')
|
2019-02-14 11:46:25 -08:00
|
|
|
DateTimeColumn get targetDate => dateTime().nullable()();
|
2019-02-14 07:01:57 -08:00
|
|
|
|
2019-02-14 07:53:52 -08:00
|
|
|
IntColumn get category => integer().nullable()();
|
|
|
|
}
|
|
|
|
|
|
|
|
class Users extends Table {
|
|
|
|
IntColumn get id => integer().autoIncrement()();
|
|
|
|
TextColumn get name => text().withLength(min: 6, max: 32)();
|
2019-05-09 06:30:17 -07:00
|
|
|
BoolColumn get isAwesome => boolean().withDefault(const Constant(true))();
|
2019-03-10 11:45:32 -07:00
|
|
|
|
|
|
|
BlobColumn get profilePicture => blob()();
|
2019-04-01 06:19:21 -07:00
|
|
|
DateTimeColumn get creationTime =>
|
|
|
|
dateTime().withDefault(currentDateAndTime)();
|
2019-02-14 07:53:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@DataClassName('Category')
|
|
|
|
class Categories extends Table {
|
|
|
|
IntColumn get id => integer().autoIncrement()();
|
2019-03-27 10:37:29 -07:00
|
|
|
TextColumn get description =>
|
|
|
|
text().named('desc').customConstraint('NOT NULL UNIQUE')();
|
2019-02-14 07:53:52 -08:00
|
|
|
}
|
|
|
|
|
2019-03-06 12:43:16 -08:00
|
|
|
class SharedTodos extends Table {
|
|
|
|
IntColumn get todo => integer()();
|
|
|
|
IntColumn get user => integer()();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Set<Column> get primaryKey => {todo, user};
|
2019-04-19 11:38:58 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<String> get customConstraints => [
|
|
|
|
'FOREIGN KEY (todo) REFERENCES todos(id)',
|
|
|
|
'FOREIGN KEY (user) REFERENCES users(id)'
|
|
|
|
];
|
2019-03-06 12:43:16 -08:00
|
|
|
}
|
|
|
|
|
2019-04-29 09:04:40 -07:00
|
|
|
class TableWithoutPK extends Table {
|
|
|
|
IntColumn get notReallyAnId => integer()();
|
2019-05-12 01:52:02 -07:00
|
|
|
RealColumn get someFloat => real()();
|
2019-04-29 09:04:40 -07:00
|
|
|
}
|
|
|
|
|
2019-06-28 14:41:27 -07:00
|
|
|
@UseMoor(
|
|
|
|
tables: [TodosTable, Categories, Users, SharedTodos, TableWithoutPK],
|
|
|
|
queries: [
|
|
|
|
Sql(
|
|
|
|
'allTodosWithCategory',
|
|
|
|
'SELECT t.*, c.id as catId, c."desc" as catDesc '
|
|
|
|
'FROM todos t INNER JOIN categories c ON c.id = t.category'),
|
|
|
|
],
|
|
|
|
)
|
2019-02-14 07:53:52 -08:00
|
|
|
class TodoDb extends _$TodoDb {
|
|
|
|
TodoDb(QueryExecutor e) : super(e);
|
|
|
|
|
|
|
|
@override
|
|
|
|
MigrationStrategy get migration => MigrationStrategy();
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get schemaVersion => 1;
|
2019-02-14 08:55:31 -08:00
|
|
|
}
|