From c1ee1f7274d00b39cb01d38dd035b227c1a87916 Mon Sep 17 00:00:00 2001 From: Alexander Wilde Date: Thu, 1 Dec 2022 02:04:16 +0000 Subject: [PATCH 1/3] Add JsonTypeConverter support to enums --- drift/lib/src/runtime/types/converters.dart | 6 ++++-- drift_dev/lib/src/analysis/resolver/dart/column.dart | 5 ++++- drift_dev/lib/src/analysis/resolver/drift/table.dart | 2 ++ drift_dev/lib/src/analysis/resolver/shared/dart_types.dart | 6 +++++- drift_dev/lib/src/writer/tables/data_class_writer.dart | 5 ++++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drift/lib/src/runtime/types/converters.dart b/drift/lib/src/runtime/types/converters.dart index febc0499..5ce18b35 100644 --- a/drift/lib/src/runtime/types/converters.dart +++ b/drift/lib/src/runtime/types/converters.dart @@ -83,7 +83,8 @@ mixin JsonTypeConverter implements JsonTypeConverter2 { /// Implementation for an enum to int converter that uses the index of the enum /// as the value stored in the database. -class EnumIndexConverter extends TypeConverter { +class EnumIndexConverter extends TypeConverter + with JsonTypeConverter { /// All values of the enum. final List values; @@ -103,7 +104,8 @@ class EnumIndexConverter extends TypeConverter { /// Implementation for an enum to string converter that uses the name of the /// enum as the value stored in the database. -class EnumNameConverter extends TypeConverter { +class EnumNameConverter extends TypeConverter + with JsonTypeConverter { /// All values of the enum. final List values; diff --git a/drift_dev/lib/src/analysis/resolver/dart/column.dart b/drift_dev/lib/src/analysis/resolver/dart/column.dart index 75f38124..9ddc9c99 100644 --- a/drift_dev/lib/src/analysis/resolver/dart/column.dart +++ b/drift_dev/lib/src/analysis/resolver/dart/column.dart @@ -337,6 +337,7 @@ class ColumnParser { final sqlName = foundExplicitName ?? ReCase(getter.name.lexeme).snakeCase; final sqlType = _startMethodToColumnType(foundStartMethod); + final helper = await _resolver.resolver.driver.loadKnownTypes(); AppliedTypeConverter? converter; if (mappedAs != null) { @@ -347,7 +348,7 @@ class ColumnParser { nullable, (message) => _resolver.reportError( DriftAnalysisError.inDartAst(element, mappedAs!, message)), - await _resolver.resolver.driver.loadKnownTypes(), + helper, ); } @@ -366,6 +367,7 @@ class ColumnParser { remainingExpr.typeArguments ?? remainingExpr.methodName, msg)), enumType, EnumType.intEnum, + helper, ); } else if (foundStartMethod == _startTextEnum) { if (converter != null) { @@ -382,6 +384,7 @@ class ColumnParser { remainingExpr.typeArguments ?? remainingExpr.methodName, msg)), enumType, EnumType.textEnum, + helper, ); } diff --git a/drift_dev/lib/src/analysis/resolver/drift/table.dart b/drift_dev/lib/src/analysis/resolver/drift/table.dart index e78cc001..61a42003 100644 --- a/drift_dev/lib/src/analysis/resolver/drift/table.dart +++ b/drift_dev/lib/src/analysis/resolver/drift/table.dart @@ -28,6 +28,7 @@ class DriftTableResolver extends LocalElementResolver { Table table; final references = {}; final stmt = discovered.sqlNode; + final helper = await resolver.driver.loadKnownTypes(); try { final reader = SchemaFromCreateTable( @@ -74,6 +75,7 @@ class DriftTableResolver extends LocalElementResolver { DriftAnalysisError.inDriftFile(column.definition ?? stmt, msg)), dartClass.classElement.thisType, type == DriftSqlType.int ? EnumType.intEnum : EnumType.textEnum, + helper, ); } } diff --git a/drift_dev/lib/src/analysis/resolver/shared/dart_types.dart b/drift_dev/lib/src/analysis/resolver/shared/dart_types.dart index 0f251bf8..8703eee4 100644 --- a/drift_dev/lib/src/analysis/resolver/shared/dart_types.dart +++ b/drift_dev/lib/src/analysis/resolver/shared/dart_types.dart @@ -230,7 +230,9 @@ AppliedTypeConverter readEnumConverter( void Function(String) reportError, DartType dartEnumType, EnumType columnEnumType, + KnownDriftTypes helper, ) { + final typeProvider = helper.helperLibrary.typeProvider; if (dartEnumType is! InterfaceType) { reportError('Not a class: `$dartEnumType`'); } @@ -261,7 +263,9 @@ AppliedTypeConverter readEnumConverter( return AppliedTypeConverter( expression: expression, dartType: dartEnumType, - jsonType: null, + jsonType: columnEnumType == EnumType.intEnum + ? typeProvider.intType + : typeProvider.stringType, sqlType: columnEnumType == EnumType.intEnum ? DriftSqlType.int : DriftSqlType.string, diff --git a/drift_dev/lib/src/writer/tables/data_class_writer.dart b/drift_dev/lib/src/writer/tables/data_class_writer.dart index e63ecd4a..e9707e83 100644 --- a/drift_dev/lib/src/writer/tables/data_class_writer.dart +++ b/drift_dev/lib/src/writer/tables/data_class_writer.dart @@ -133,8 +133,11 @@ class DataClassWriter { final typeConverter = column.typeConverter; if (typeConverter != null && typeConverter.alsoAppliesToJsonConversion) { - final type = + var type = _emitter.dartCode(AnnotatedDartCode.type(typeConverter.jsonType!)); + if (column.nullable) { + type = '$type?'; + } final fromConverter = "serializer.fromJson<$type>(json['$jsonKey'])"; final converterField = _converter(column); From 5a6f402d86226bec8dc867f003d183e49251ee77 Mon Sep 17 00:00:00 2001 From: Alexander Wilde Date: Thu, 1 Dec 2022 02:51:41 +0000 Subject: [PATCH 2/3] Run build --- drift/test/generated/custom_tables.g.dart | 21 ++++++++++-------- drift/test/generated/todos.g.dart | 22 +++++++++++-------- examples/app/lib/database/database.g.dart | 22 ++++++++++--------- examples/encryption/lib/database.g.dart | 7 +++--- .../lib/src/database/database.g.dart | 6 ++--- .../migrations_example/lib/database.g.dart | 2 +- .../web_worker_example/lib/database.g.dart | 6 ++--- .../benchmarks/lib/src/moor/database.g.dart | 6 ++--- .../lib/database/database.g.dart | 21 ++++++++++-------- ...ves_after_migration_regression_test.g.dart | 6 ++--- 10 files changed, 66 insertions(+), 53 deletions(-) diff --git a/drift/test/generated/custom_tables.g.dart b/drift/test/generated/custom_tables.g.dart index a79b84f4..0a302840 100644 --- a/drift/test/generated/custom_tables.g.dart +++ b/drift/test/generated/custom_tables.g.dart @@ -548,8 +548,8 @@ class Config extends DataClass implements Insertable { configKey: serializer.fromJson(json['config_key']), configValue: serializer.fromJson(json['config_value']), syncState: serializer.fromJson(json['sync_state']), - syncStateImplicit: - serializer.fromJson(json['sync_state_implicit']), + syncStateImplicit: ConfigTable.$convertersyncStateImplicitn + .fromJson(serializer.fromJson(json['sync_state_implicit'])), ); } factory Config.fromJsonString(String encodedJson, @@ -563,7 +563,8 @@ class Config extends DataClass implements Insertable { 'config_key': serializer.toJson(configKey), 'config_value': serializer.toJson(configValue), 'sync_state': serializer.toJson(syncState), - 'sync_state_implicit': serializer.toJson(syncStateImplicit), + 'sync_state_implicit': serializer.toJson( + ConfigTable.$convertersyncStateImplicitn.toJson(syncStateImplicit)), }; } @@ -774,10 +775,11 @@ class ConfigTable extends Table with TableInfo { const SyncTypeConverter(); static TypeConverter $convertersyncStaten = NullAwareTypeConverter.wrap($convertersyncState); - static TypeConverter $convertersyncStateImplicit = + static JsonTypeConverter2 $convertersyncStateImplicit = const EnumIndexConverter(SyncType.values); - static TypeConverter $convertersyncStateImplicitn = - NullAwareTypeConverter.wrap($convertersyncStateImplicit); + static JsonTypeConverter2 + $convertersyncStateImplicitn = + JsonTypeConverter2.asNullable($convertersyncStateImplicit); @override bool get isStrict => true; @override @@ -1472,8 +1474,8 @@ class MyViewData extends DataClass { configKey: serializer.fromJson(json['config_key']), configValue: serializer.fromJson(json['config_value']), syncState: serializer.fromJson(json['sync_state']), - syncStateImplicit: - serializer.fromJson(json['sync_state_implicit']), + syncStateImplicit: ConfigTable.$convertersyncStateImplicitn + .fromJson(serializer.fromJson(json['sync_state_implicit'])), ); } factory MyViewData.fromJsonString(String encodedJson, @@ -1488,7 +1490,8 @@ class MyViewData extends DataClass { 'config_key': serializer.toJson(configKey), 'config_value': serializer.toJson(configValue), 'sync_state': serializer.toJson(syncState), - 'sync_state_implicit': serializer.toJson(syncStateImplicit), + 'sync_state_implicit': serializer.toJson( + ConfigTable.$convertersyncStateImplicitn.toJson(syncStateImplicit)), }; } diff --git a/drift/test/generated/todos.g.dart b/drift/test/generated/todos.g.dart index 81f376c4..13745e9d 100644 --- a/drift/test/generated/todos.g.dart +++ b/drift/test/generated/todos.g.dart @@ -39,7 +39,8 @@ class Category extends DataClass implements Insertable { return Category( id: serializer.fromJson(json['id']), description: serializer.fromJson(json['description']), - priority: serializer.fromJson(json['priority']), + priority: $CategoriesTable.$converterpriority + .fromJson(serializer.fromJson(json['priority'])), descriptionInUpperCase: serializer.fromJson(json['descriptionInUpperCase']), ); @@ -55,7 +56,8 @@ class Category extends DataClass implements Insertable { return { 'id': serializer.toJson(id), 'description': serializer.toJson(description), - 'priority': serializer.toJson(priority), + 'priority': serializer + .toJson($CategoriesTable.$converterpriority.toJson(priority)), 'descriptionInUpperCase': serializer.toJson(descriptionInUpperCase), }; @@ -256,7 +258,7 @@ class $CategoriesTable extends Categories return $CategoriesTable(attachedDatabase, alias); } - static TypeConverter $converterpriority = + static JsonTypeConverter2 $converterpriority = const EnumIndexConverter(CategoryPriority.values); } @@ -321,7 +323,8 @@ class TodoEntry extends DataClass implements Insertable { content: serializer.fromJson(json['content']), targetDate: serializer.fromJson(json['target_date']), category: serializer.fromJson(json['category']), - status: serializer.fromJson(json['status']), + status: $TodosTableTable.$converterstatusn + .fromJson(serializer.fromJson(json['status'])), ); } factory TodoEntry.fromJsonString(String encodedJson, @@ -338,7 +341,8 @@ class TodoEntry extends DataClass implements Insertable { 'content': serializer.toJson(content), 'target_date': serializer.toJson(targetDate), 'category': serializer.toJson(category), - 'status': serializer.toJson(status), + 'status': serializer + .toJson($TodosTableTable.$converterstatusn.toJson(status)), }; } @@ -605,10 +609,10 @@ class $TodosTableTable extends TodosTable return $TodosTableTable(attachedDatabase, alias); } - static TypeConverter $converterstatus = + static JsonTypeConverter2 $converterstatus = const EnumNameConverter(TodoStatus.values); - static TypeConverter $converterstatusn = - NullAwareTypeConverter.wrap($converterstatus); + static JsonTypeConverter2 $converterstatusn = + JsonTypeConverter2.asNullable($converterstatus); } class User extends DataClass implements Insertable { @@ -1308,7 +1312,7 @@ class PureDefault extends DataClass implements Insertable { serializer ??= driftRuntimeOptions.defaultSerializer; return PureDefault( txt: $PureDefaultsTable.$convertertxtn - .fromJson(serializer.fromJson>(json['txt'])), + .fromJson(serializer.fromJson?>(json['txt'])), ); } factory PureDefault.fromJsonString(String encodedJson, diff --git a/examples/app/lib/database/database.g.dart b/examples/app/lib/database/database.g.dart index f4bbec4c..879f5353 100644 --- a/examples/app/lib/database/database.g.dart +++ b/examples/app/lib/database/database.g.dart @@ -142,7 +142,7 @@ class $CategoriesTable extends Categories final GeneratedDatabase attachedDatabase; final String? _alias; $CategoriesTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override late final GeneratedColumn id = GeneratedColumn( 'id', aliasedName, false, @@ -151,12 +151,12 @@ class $CategoriesTable extends Categories requiredDuringInsert: false, defaultConstraints: GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT')); - final VerificationMeta _nameMeta = const VerificationMeta('name'); + static const VerificationMeta _nameMeta = const VerificationMeta('name'); @override late final GeneratedColumn name = GeneratedColumn( 'name', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - final VerificationMeta _colorMeta = const VerificationMeta('color'); + static const VerificationMeta _colorMeta = const VerificationMeta('color'); @override late final GeneratedColumnWithTypeConverter color = GeneratedColumn('color', aliasedName, false, @@ -382,7 +382,7 @@ class $TodoEntriesTable extends TodoEntries final GeneratedDatabase attachedDatabase; final String? _alias; $TodoEntriesTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override late final GeneratedColumn id = GeneratedColumn( 'id', aliasedName, false, @@ -391,13 +391,14 @@ class $TodoEntriesTable extends TodoEntries requiredDuringInsert: false, defaultConstraints: GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT')); - final VerificationMeta _descriptionMeta = + static const VerificationMeta _descriptionMeta = const VerificationMeta('description'); @override late final GeneratedColumn description = GeneratedColumn( 'description', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - final VerificationMeta _categoryMeta = const VerificationMeta('category'); + static const VerificationMeta _categoryMeta = + const VerificationMeta('category'); @override late final GeneratedColumn category = GeneratedColumn( 'category', aliasedName, true, @@ -405,7 +406,8 @@ class $TodoEntriesTable extends TodoEntries requiredDuringInsert: false, defaultConstraints: GeneratedColumn.constraintIsAlways('REFERENCES categories (id)')); - final VerificationMeta _dueDateMeta = const VerificationMeta('dueDate'); + static const VerificationMeta _dueDateMeta = + const VerificationMeta('dueDate'); @override late final GeneratedColumn dueDate = GeneratedColumn( 'due_date', aliasedName, true, @@ -564,7 +566,7 @@ class TextEntries extends Table final GeneratedDatabase attachedDatabase; final String? _alias; TextEntries(this.attachedDatabase, [this._alias]); - final VerificationMeta _descriptionMeta = + static const VerificationMeta _descriptionMeta = const VerificationMeta('description'); late final GeneratedColumn description = GeneratedColumn( 'description', aliasedName, false, @@ -594,7 +596,7 @@ class TextEntries extends Table } @override - Set get $primaryKey => const {}; + Set get $primaryKey => const {}; @override TextEntrie map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; @@ -670,7 +672,7 @@ abstract class _$AppDatabase extends GeneratedDatabase { } @override - Iterable> get allTables => + Iterable> get allTables => allSchemaEntities.whereType>(); @override List get allSchemaEntities => [ diff --git a/examples/encryption/lib/database.g.dart b/examples/encryption/lib/database.g.dart index 1d19fbbc..fd91fe6d 100644 --- a/examples/encryption/lib/database.g.dart +++ b/examples/encryption/lib/database.g.dart @@ -115,7 +115,7 @@ class $NotesTable extends Notes with TableInfo<$NotesTable, Note> { final GeneratedDatabase attachedDatabase; final String? _alias; $NotesTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override late final GeneratedColumn id = GeneratedColumn( 'id', aliasedName, false, @@ -124,7 +124,8 @@ class $NotesTable extends Notes with TableInfo<$NotesTable, Note> { requiredDuringInsert: false, defaultConstraints: GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT')); - final VerificationMeta _contentMeta = const VerificationMeta('content'); + static const VerificationMeta _contentMeta = + const VerificationMeta('content'); @override late final GeneratedColumn content = GeneratedColumn( 'content', aliasedName, false, @@ -175,7 +176,7 @@ abstract class _$MyEncryptedDatabase extends GeneratedDatabase { _$MyEncryptedDatabase(QueryExecutor e) : super(e); late final $NotesTable notes = $NotesTable(this); @override - Iterable> get allTables => + Iterable> get allTables => allSchemaEntities.whereType>(); @override List get allSchemaEntities => [notes]; diff --git a/examples/flutter_web_worker_example/lib/src/database/database.g.dart b/examples/flutter_web_worker_example/lib/src/database/database.g.dart index 053608e2..e2936d0d 100644 --- a/examples/flutter_web_worker_example/lib/src/database/database.g.dart +++ b/examples/flutter_web_worker_example/lib/src/database/database.g.dart @@ -115,13 +115,13 @@ class Entries extends Table with TableInfo { final GeneratedDatabase attachedDatabase; final String? _alias; Entries(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); + static const VerificationMeta _idMeta = const VerificationMeta('id'); late final GeneratedColumn id = GeneratedColumn( 'id', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: false, $customConstraints: 'PRIMARY KEY'); - final VerificationMeta _valueMeta = const VerificationMeta('value'); + static const VerificationMeta _valueMeta = const VerificationMeta('value'); late final GeneratedColumn value = GeneratedColumn( 'text', aliasedName, false, type: DriftSqlType.string, @@ -201,7 +201,7 @@ abstract class _$MyDatabase extends GeneratedDatabase { } @override - Iterable> get allTables => + Iterable> get allTables => allSchemaEntities.whereType>(); @override List get allSchemaEntities => [entries]; diff --git a/examples/migrations_example/lib/database.g.dart b/examples/migrations_example/lib/database.g.dart index d00c8322..24074da7 100644 --- a/examples/migrations_example/lib/database.g.dart +++ b/examples/migrations_example/lib/database.g.dart @@ -823,7 +823,7 @@ class GroupCount extends ViewInfo String get entityName => 'group_count'; @override String get createViewStmt => - 'CREATE VIEW group_count AS SELECT\n users.*,\n (SELECT COUNT(*) FROM "groups" WHERE owner = users.id) AS group_count\n FROM users;'; + 'CREATE VIEW group_count AS SELECT users.*, (SELECT COUNT(*) FROM "groups" WHERE owner = users.id) AS group_count FROM users'; @override GroupCount get asDslTable => this; @override diff --git a/examples/web_worker_example/lib/database.g.dart b/examples/web_worker_example/lib/database.g.dart index 6b4879b1..07dd1e10 100644 --- a/examples/web_worker_example/lib/database.g.dart +++ b/examples/web_worker_example/lib/database.g.dart @@ -115,13 +115,13 @@ class Entries extends Table with TableInfo { final GeneratedDatabase attachedDatabase; final String? _alias; Entries(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); + static const VerificationMeta _idMeta = const VerificationMeta('id'); late final GeneratedColumn id = GeneratedColumn( 'id', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: false, $customConstraints: 'PRIMARY KEY'); - final VerificationMeta _valueMeta = const VerificationMeta('value'); + static const VerificationMeta _valueMeta = const VerificationMeta('value'); late final GeneratedColumn value = GeneratedColumn( 'text', aliasedName, false, type: DriftSqlType.string, @@ -202,7 +202,7 @@ abstract class _$MyDatabase extends GeneratedDatabase { } @override - Iterable> get allTables => + Iterable> get allTables => allSchemaEntities.whereType>(); @override List get allSchemaEntities => [entries]; diff --git a/extras/benchmarks/lib/src/moor/database.g.dart b/extras/benchmarks/lib/src/moor/database.g.dart index e9496d97..eb184d46 100644 --- a/extras/benchmarks/lib/src/moor/database.g.dart +++ b/extras/benchmarks/lib/src/moor/database.g.dart @@ -117,12 +117,12 @@ class $KeyValuesTable extends KeyValues final GeneratedDatabase attachedDatabase; final String? _alias; $KeyValuesTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _keyMeta = const VerificationMeta('key'); + static const VerificationMeta _keyMeta = const VerificationMeta('key'); @override late final GeneratedColumn key = GeneratedColumn( 'key', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - final VerificationMeta _valueMeta = const VerificationMeta('value'); + static const VerificationMeta _valueMeta = const VerificationMeta('value'); @override late final GeneratedColumn value = GeneratedColumn( 'value', aliasedName, false, @@ -176,7 +176,7 @@ abstract class _$Database extends GeneratedDatabase { _$Database(QueryExecutor e) : super(e); late final $KeyValuesTable keyValues = $KeyValuesTable(this); @override - Iterable> get allTables => + Iterable> get allTables => allSchemaEntities.whereType>(); @override List get allSchemaEntities => [keyValues]; diff --git a/extras/integration_tests/drift_testcases/lib/database/database.g.dart b/extras/integration_tests/drift_testcases/lib/database/database.g.dart index 4c9cf05a..86bbee6d 100644 --- a/extras/integration_tests/drift_testcases/lib/database/database.g.dart +++ b/extras/integration_tests/drift_testcases/lib/database/database.g.dart @@ -210,7 +210,7 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> { final GeneratedDatabase attachedDatabase; final String? _alias; $UsersTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override late final GeneratedColumn id = GeneratedColumn( 'id', aliasedName, false, @@ -219,23 +219,24 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> { requiredDuringInsert: false, defaultConstraints: GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT')); - final VerificationMeta _nameMeta = const VerificationMeta('name'); + static const VerificationMeta _nameMeta = const VerificationMeta('name'); @override late final GeneratedColumn name = GeneratedColumn( 'name', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - final VerificationMeta _birthDateMeta = const VerificationMeta('birthDate'); + static const VerificationMeta _birthDateMeta = + const VerificationMeta('birthDate'); @override late final GeneratedColumn birthDate = GeneratedColumn( 'birth_date', aliasedName, false, type: DriftSqlType.dateTime, requiredDuringInsert: true); - final VerificationMeta _profilePictureMeta = + static const VerificationMeta _profilePictureMeta = const VerificationMeta('profilePicture'); @override late final GeneratedColumn profilePicture = GeneratedColumn('profile_picture', aliasedName, true, type: DriftSqlType.blob, requiredDuringInsert: false); - final VerificationMeta _preferencesMeta = + static const VerificationMeta _preferencesMeta = const VerificationMeta('preferences'); @override late final GeneratedColumnWithTypeConverter @@ -455,17 +456,19 @@ class $FriendshipsTable extends Friendships final GeneratedDatabase attachedDatabase; final String? _alias; $FriendshipsTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _firstUserMeta = const VerificationMeta('firstUser'); + static const VerificationMeta _firstUserMeta = + const VerificationMeta('firstUser'); @override late final GeneratedColumn firstUser = GeneratedColumn( 'first_user', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: true); - final VerificationMeta _secondUserMeta = const VerificationMeta('secondUser'); + static const VerificationMeta _secondUserMeta = + const VerificationMeta('secondUser'); @override late final GeneratedColumn secondUser = GeneratedColumn( 'second_user', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: true); - final VerificationMeta _reallyGoodFriendsMeta = + static const VerificationMeta _reallyGoodFriendsMeta = const VerificationMeta('reallyGoodFriends'); @override late final GeneratedColumn reallyGoodFriends = @@ -625,7 +628,7 @@ abstract class _$Database extends GeneratedDatabase { } @override - Iterable> get allTables => + Iterable> get allTables => allSchemaEntities.whereType>(); @override List get allSchemaEntities => [users, friendships]; diff --git a/extras/integration_tests/web/test/saves_after_migration_regression_test.g.dart b/extras/integration_tests/web/test/saves_after_migration_regression_test.g.dart index 9aebb6b3..a9244a0f 100644 --- a/extras/integration_tests/web/test/saves_after_migration_regression_test.g.dart +++ b/extras/integration_tests/web/test/saves_after_migration_regression_test.g.dart @@ -97,7 +97,7 @@ class $FoosTable extends Foos with TableInfo<$FoosTable, Foo> { final GeneratedDatabase attachedDatabase; final String? _alias; $FoosTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override late final GeneratedColumn id = GeneratedColumn( 'id', aliasedName, false, @@ -234,7 +234,7 @@ class $BarsTable extends Bars with TableInfo<$BarsTable, Bar> { final GeneratedDatabase attachedDatabase; final String? _alias; $BarsTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override late final GeneratedColumn id = GeneratedColumn( 'id', aliasedName, false, @@ -282,7 +282,7 @@ abstract class _$_FakeDb extends GeneratedDatabase { late final $FoosTable foos = $FoosTable(this); late final $BarsTable bars = $BarsTable(this); @override - Iterable> get allTables => + Iterable> get allTables => allSchemaEntities.whereType>(); @override List get allSchemaEntities => [foos, bars]; From c80e6b6cbed09fa8ecfd7cfde6fc25edc49c9690 Mon Sep 17 00:00:00 2001 From: Alexander Wilde Date: Thu, 1 Dec 2022 03:23:48 +0000 Subject: [PATCH 3/3] Fix tests --- drift/test/serialization_test.dart | 6 +++--- drift_dev/test/writer/data_class_writer_test.dart | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drift/test/serialization_test.dart b/drift/test/serialization_test.dart index 1feb4efe..e277c48a 100644 --- a/drift/test/serialization_test.dart +++ b/drift/test/serialization_test.dart @@ -20,7 +20,7 @@ final Map _regularSerialized = { 'content': 'content', 'target_date': _someDate.millisecondsSinceEpoch, 'category': 3, - 'status': TodoStatus.open, + 'status': TodoStatus.open.name, }; final Map _asTextSerialized = { @@ -29,7 +29,7 @@ final Map _asTextSerialized = { 'content': 'content', 'target_date': _someDate.toIso8601String(), 'category': 3, - 'status': TodoStatus.open, + 'status': TodoStatus.open.name, }; final Map _customSerialized = { @@ -38,7 +38,7 @@ final Map _customSerialized = { 'content': 'content', 'target_date': _someDate.toIso8601String(), 'category': 3, - 'status': TodoStatus.open, + 'status': TodoStatus.open.name, }; class CustomSerializer extends ValueSerializer { diff --git a/drift_dev/test/writer/data_class_writer_test.dart b/drift_dev/test/writer/data_class_writer_test.dart index 27fb17aa..3b848cc9 100644 --- a/drift_dev/test/writer/data_class_writer_test.dart +++ b/drift_dev/test/writer/data_class_writer_test.dart @@ -117,7 +117,7 @@ class Database extends _$Database {} checkOutputs({ 'a|lib/main.drift.dart': decodedMatches(contains(r''' - static TypeConverter $converterpriority = + static JsonTypeConverter2 $converterpriority = const EnumNameConverter(Priority.values);''')), }, writer.dartOutputs, writer); },