Formatting, fixing tests

This commit is contained in:
Simon Binder 2019-03-05 20:59:10 +01:00
parent 2b24684abb
commit 0de6005ad7
No known key found for this signature in database
GPG Key ID: B807FDF954BA00CF
4 changed files with 37 additions and 13 deletions

View File

@ -154,7 +154,7 @@ abstract class GeneratedDatabase extends DatabaseConnectionUser
GeneratedDatabase(SqlTypeSystem types, QueryExecutor executor, GeneratedDatabase(SqlTypeSystem types, QueryExecutor executor,
{StreamQueryStore streamStore}) {StreamQueryStore streamStore})
: super(types, executor, streamQueries: streamStore) { : super(types, executor, streamQueries: streamStore) {
executor.databaseInfo = this; executor?.databaseInfo = this;
} }
/// Creates a migrator with the provided query executor. We sometimes can't /// Creates a migrator with the provided query executor. We sometimes can't

View File

@ -26,6 +26,19 @@ class TodoEntry {
category: intType.mapFromDatabaseResponse(data['category']), category: intType.mapFromDatabaseResponse(data['category']),
); );
} }
TodoEntry copyWith(
{int id,
String title,
String content,
DateTime targetDate,
int category}) =>
TodoEntry(
id: id ?? this.id,
title: title ?? this.title,
content: content ?? this.content,
targetDate: targetDate ?? this.targetDate,
category: category ?? this.category,
);
@override @override
int get hashCode => int get hashCode =>
((((id.hashCode) * 31 + title.hashCode) * 31 + content.hashCode) * 31 + ((((id.hashCode) * 31 + title.hashCode) * 31 + content.hashCode) * 31 +
@ -43,10 +56,10 @@ class TodoEntry {
other.category == category); other.category == category);
} }
class _$TodosTableTable extends TodosTable class $TodosTableTable extends TodosTable
implements TableInfo<TodosTable, TodoEntry> { implements TableInfo<TodosTable, TodoEntry> {
final GeneratedDatabase _db; final GeneratedDatabase _db;
_$TodosTableTable(this._db); $TodosTableTable(this._db);
@override @override
GeneratedIntColumn get id => GeneratedIntColumn get id =>
GeneratedIntColumn('id', false, hasAutoIncrement: true); GeneratedIntColumn('id', false, hasAutoIncrement: true);
@ -125,6 +138,10 @@ class Category {
description: stringType.mapFromDatabaseResponse(data['`desc`']), description: stringType.mapFromDatabaseResponse(data['`desc`']),
); );
} }
Category copyWith({int id, String description}) => Category(
id: id ?? this.id,
description: description ?? this.description,
);
@override @override
int get hashCode => (id.hashCode) * 31 + description.hashCode; int get hashCode => (id.hashCode) * 31 + description.hashCode;
@override @override
@ -133,10 +150,10 @@ class Category {
(other is Category && other.id == id && other.description == description); (other is Category && other.id == id && other.description == description);
} }
class _$CategoriesTable extends Categories class $CategoriesTable extends Categories
implements TableInfo<Categories, Category> { implements TableInfo<Categories, Category> {
final GeneratedDatabase _db; final GeneratedDatabase _db;
_$CategoriesTable(this._db); $CategoriesTable(this._db);
@override @override
GeneratedIntColumn get id => GeneratedIntColumn get id =>
GeneratedIntColumn('id', false, hasAutoIncrement: true); GeneratedIntColumn('id', false, hasAutoIncrement: true);
@ -190,6 +207,11 @@ class User {
isAwesome: boolType.mapFromDatabaseResponse(data['is_awesome']), isAwesome: boolType.mapFromDatabaseResponse(data['is_awesome']),
); );
} }
User copyWith({int id, String name, bool isAwesome}) => User(
id: id ?? this.id,
name: name ?? this.name,
isAwesome: isAwesome ?? this.isAwesome,
);
@override @override
int get hashCode => int get hashCode =>
((id.hashCode) * 31 + name.hashCode) * 31 + isAwesome.hashCode; ((id.hashCode) * 31 + name.hashCode) * 31 + isAwesome.hashCode;
@ -202,9 +224,9 @@ class User {
other.isAwesome == isAwesome); other.isAwesome == isAwesome);
} }
class _$UsersTable extends Users implements TableInfo<Users, User> { class $UsersTable extends Users implements TableInfo<Users, User> {
final GeneratedDatabase _db; final GeneratedDatabase _db;
_$UsersTable(this._db); $UsersTable(this._db);
@override @override
GeneratedIntColumn get id => GeneratedIntColumn get id =>
GeneratedIntColumn('id', false, hasAutoIncrement: true); GeneratedIntColumn('id', false, hasAutoIncrement: true);
@ -254,9 +276,9 @@ class _$UsersTable extends Users implements TableInfo<Users, User> {
abstract class _$TodoDb extends GeneratedDatabase { abstract class _$TodoDb extends GeneratedDatabase {
_$TodoDb(QueryExecutor e) : super(const SqlTypeSystem.withDefaults(), e); _$TodoDb(QueryExecutor e) : super(const SqlTypeSystem.withDefaults(), e);
_$TodosTableTable get todosTable => _$TodosTableTable(this); $TodosTableTable get todosTable => $TodosTableTable(this);
_$CategoriesTable get categories => _$CategoriesTable(this); $CategoriesTable get categories => $CategoriesTable(this);
_$UsersTable get users => _$UsersTable(this); $UsersTable get users => $UsersTable(this);
@override @override
List<TableInfo> get allTables => [todosTable, categories, users]; List<TableInfo> get allTables => [todosTable, categories, users];
} }

View File

@ -24,7 +24,7 @@ void main() {
.write(TodoEntry(title: 'Updated title', category: 3)); .write(TodoEntry(title: 'Updated title', category: 3));
verify(executor.runUpdate( verify(executor.runUpdate(
'UPDATE todos SET title = ? category = ?;', ['Updated title', 3])); 'UPDATE todos SET title = ?, category = ?;', ['Updated title', 3]));
}); });
test('with a WHERE clause', () async { test('with a WHERE clause', () async {
@ -49,7 +49,9 @@ void main() {
test('are issued when data was changed', () async { test('are issued when data was changed', () async {
when(executor.runUpdate(any, any)).thenAnswer((_) => Future.value(3)); when(executor.runUpdate(any, any)).thenAnswer((_) => Future.value(3));
await db.update(db.todosTable).write(TodoEntry()); await db.update(db.todosTable).write(TodoEntry(
content: 'Updated content',
));
verify(streamQueries.handleTableUpdates('todos')); verify(streamQueries.handleTableUpdates('todos'));
}); });

View File

@ -109,7 +109,7 @@ class DataClassWriter {
buffer.write('}) => $dataClassName('); buffer.write('}) => $dataClassName(');
for (var column in table.columns) { for (var column in table.columns) {
// we also have a method parameter called getter, so we can use // we also have a method parameter called like the getter, so we can use
// field: field ?? this.field // field: field ?? this.field
final getter = column.dartGetterName; final getter = column.dartGetterName;
buffer.write('$getter: $getter ?? this.$getter,'); buffer.write('$getter: $getter ?? this.$getter,');