Use a mixin for auto increment columns in test file

This commit is contained in:
Simon Binder 2019-10-11 22:12:28 +02:00
parent ff7d587339
commit 438f979ed1
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 8 additions and 8 deletions

View File

@ -2,12 +2,15 @@ import 'package:moor/moor.dart';
part 'todos.g.dart'; part 'todos.g.dart';
mixin AutoIncrement on Table {
IntColumn get id => integer().autoIncrement()();
}
@DataClassName('TodoEntry') @DataClassName('TodoEntry')
class TodosTable extends Table { class TodosTable extends Table with AutoIncrement {
@override @override
String get tableName => 'todos'; String get tableName => 'todos';
IntColumn get id => integer().autoIncrement()();
TextColumn get title => text().withLength(min: 4, max: 16).nullable()(); TextColumn get title => text().withLength(min: 4, max: 16).nullable()();
TextColumn get content => text()(); TextColumn get content => text()();
@JsonKey('target_date') @JsonKey('target_date')
@ -16,8 +19,7 @@ class TodosTable extends Table {
IntColumn get category => integer().nullable()(); IntColumn get category => integer().nullable()();
} }
class Users extends Table { class Users extends Table with AutoIncrement {
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text().withLength(min: 6, max: 32)(); TextColumn get name => text().withLength(min: 6, max: 32)();
BoolColumn get isAwesome => boolean().withDefault(const Constant(true))(); BoolColumn get isAwesome => boolean().withDefault(const Constant(true))();
@ -27,8 +29,7 @@ class Users extends Table {
} }
@DataClassName('Category') @DataClassName('Category')
class Categories extends Table { class Categories extends Table with AutoIncrement {
IntColumn get id => integer().autoIncrement()();
TextColumn get description => TextColumn get description =>
text().named('desc').customConstraint('NOT NULL UNIQUE')(); text().named('desc').customConstraint('NOT NULL UNIQUE')();
} }
@ -54,8 +55,7 @@ class TableWithoutPK extends Table {
TextColumn get custom => text().map(const CustomConverter())(); TextColumn get custom => text().map(const CustomConverter())();
} }
class PureDefaults extends Table { class PureDefaults extends Table with AutoIncrement {
IntColumn get id => integer().autoIncrement()();
TextColumn get txt => text().nullable()(); TextColumn get txt => text().nullable()();
} }