From 28c3c444e77725a70a6d4248d596c136fae23dad Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 22 Nov 2023 13:09:09 +0100 Subject: [PATCH] Re-run builders, add changelog entry --- drift_dev/CHANGELOG.md | 5 ++++ .../analysis/resolver/shared/data_class.dart | 12 ++++---- examples/app/lib/database/database.g.dart | 28 +++++++++---------- examples/encryption/pubspec.yaml | 2 +- .../flutter_web_worker_example/lib/main.dart | 2 +- .../lib/src/database/database.g.dart | 28 +++++++++---------- .../web_worker_example/lib/database.g.dart | 28 +++++++++---------- 7 files changed, 55 insertions(+), 50 deletions(-) diff --git a/drift_dev/CHANGELOG.md b/drift_dev/CHANGELOG.md index cb1b0f63..ba02b0f9 100644 --- a/drift_dev/CHANGELOG.md +++ b/drift_dev/CHANGELOG.md @@ -1,5 +1,10 @@ ## 2.14.0-dev +- __Breaking change__: The name of the generated row class derived from the name + of the Dart table name now supports more forms of plurals. + For instance, a table without a `@DataClassName` annotation named `Categories` + would now generate a `Category` class instead of `Categorie`. + ## 2.13.2 - Fix generated queries relying on custom types. diff --git a/drift_dev/lib/src/analysis/resolver/shared/data_class.dart b/drift_dev/lib/src/analysis/resolver/shared/data_class.dart index 496d3afd..cb711716 100644 --- a/drift_dev/lib/src/analysis/resolver/shared/data_class.dart +++ b/drift_dev/lib/src/analysis/resolver/shared/data_class.dart @@ -14,19 +14,19 @@ String dataClassNameForClassName(String tableName) { // from the table name. if (tableName.endsWith('s')) { - if (tableName.endsWith('ss') || tableName.endsWith('us') || tableName.endsWith('sses')) { + if (tableName.endsWith('ss') || + tableName.endsWith('us') || + tableName.endsWith('sses')) { return tableName; } else if (tableName.endsWith('ies')) { - return tableName.substring(0, tableName.length - 3) + 'y'; + return '${tableName.substring(0, tableName.length - 3)}y'; } else { return tableName.substring(0, tableName.length - 1); } } else { - return tableName; + // Default behavior if the table name is not a valid plural. + return '${tableName}Data'; } - - // Default behavior if the table name is not a valid plural. - return '${tableName}Data'; } AnnotatedDartCode? parseCustomParentClass( diff --git a/examples/app/lib/database/database.g.dart b/examples/app/lib/database/database.g.dart index 52aebbf6..bf280bcd 100644 --- a/examples/app/lib/database/database.g.dart +++ b/examples/app/lib/database/database.g.dart @@ -473,8 +473,8 @@ class TodoEntriesCompanion extends UpdateCompanion { class TextEntries extends Table with - TableInfo, - VirtualTableInfo { + TableInfo, + VirtualTableInfo { @override final GeneratedDatabase attachedDatabase; final String? _alias; @@ -494,7 +494,7 @@ class TextEntries extends Table String get actualTableName => $name; static const String $name = 'text_entries'; @override - VerificationContext validateIntegrity(Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); @@ -512,9 +512,9 @@ class TextEntries extends Table @override Set get $primaryKey => const {}; @override - TextEntrie map(Map data, {String? tablePrefix}) { + TextEntry map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return TextEntrie( + return TextEntry( description: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}description'])!, ); @@ -532,9 +532,9 @@ class TextEntries extends Table 'fts5(description, content=todo_entries, content_rowid=id)'; } -class TextEntrie extends DataClass implements Insertable { +class TextEntry extends DataClass implements Insertable { final String description; - const TextEntrie({required this.description}); + const TextEntry({required this.description}); @override Map toColumns(bool nullToAbsent) { final map = {}; @@ -548,10 +548,10 @@ class TextEntrie extends DataClass implements Insertable { ); } - factory TextEntrie.fromJson(Map json, + factory TextEntry.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return TextEntrie( + return TextEntry( description: serializer.fromJson(json['description']), ); } @@ -563,12 +563,12 @@ class TextEntrie extends DataClass implements Insertable { }; } - TextEntrie copyWith({String? description}) => TextEntrie( + TextEntry copyWith({String? description}) => TextEntry( description: description ?? this.description, ); @override String toString() { - return (StringBuffer('TextEntrie(') + return (StringBuffer('TextEntry(') ..write('description: $description') ..write(')')) .toString(); @@ -579,10 +579,10 @@ class TextEntrie extends DataClass implements Insertable { @override bool operator ==(Object other) => identical(this, other) || - (other is TextEntrie && other.description == this.description); + (other is TextEntry && other.description == this.description); } -class TextEntriesCompanion extends UpdateCompanion { +class TextEntriesCompanion extends UpdateCompanion { final Value description; final Value rowid; const TextEntriesCompanion({ @@ -593,7 +593,7 @@ class TextEntriesCompanion extends UpdateCompanion { required String description, this.rowid = const Value.absent(), }) : description = Value(description); - static Insertable custom({ + static Insertable custom({ Expression? description, Expression? rowid, }) { diff --git a/examples/encryption/pubspec.yaml b/examples/encryption/pubspec.yaml index e0b4e254..74c3d2a0 100644 --- a/examples/encryption/pubspec.yaml +++ b/examples/encryption/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: drift: ^2.0.2+1 - sqlcipher_flutter_libs: ^0.5.1 + sqlcipher_flutter_libs: ^0.6.0 flutter: sdk: flutter path_provider: ^2.0.11 diff --git a/examples/flutter_web_worker_example/lib/main.dart b/examples/flutter_web_worker_example/lib/main.dart index fb611392..e2a534a4 100644 --- a/examples/flutter_web_worker_example/lib/main.dart +++ b/examples/flutter_web_worker_example/lib/main.dart @@ -14,7 +14,7 @@ void main() { } class _DatabaseSampleState extends State<_DatabaseSample> { - List allItems = []; + List allItems = []; TextEditingController editController = TextEditingController(); final database = MyDatabase(Platform.createDatabaseConnection('sample')); 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 ca90faf1..06e4c94e 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 @@ -3,7 +3,7 @@ part of 'database.dart'; // ignore_for_file: type=lint -class Entries extends Table with TableInfo { +class Entries extends Table with TableInfo { @override final GeneratedDatabase attachedDatabase; final String? _alias; @@ -28,7 +28,7 @@ class Entries extends Table with TableInfo { String get actualTableName => $name; static const String $name = 'entries'; @override - VerificationContext validateIntegrity(Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); @@ -47,9 +47,9 @@ class Entries extends Table with TableInfo { @override Set get $primaryKey => {id}; @override - Entrie map(Map data, {String? tablePrefix}) { + Entry map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return Entrie( + return Entry( id: attachedDatabase.typeMapping .read(DriftSqlType.int, data['${effectivePrefix}id'])!, value: attachedDatabase.typeMapping @@ -66,10 +66,10 @@ class Entries extends Table with TableInfo { bool get dontWriteConstraints => true; } -class Entrie extends DataClass implements Insertable { +class Entry extends DataClass implements Insertable { final int id; final String value; - const Entrie({required this.id, required this.value}); + const Entry({required this.id, required this.value}); @override Map toColumns(bool nullToAbsent) { final map = {}; @@ -85,10 +85,10 @@ class Entrie extends DataClass implements Insertable { ); } - factory Entrie.fromJson(Map json, + factory Entry.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return Entrie( + return Entry( id: serializer.fromJson(json['id']), value: serializer.fromJson(json['text']), ); @@ -102,13 +102,13 @@ class Entrie extends DataClass implements Insertable { }; } - Entrie copyWith({int? id, String? value}) => Entrie( + Entry copyWith({int? id, String? value}) => Entry( id: id ?? this.id, value: value ?? this.value, ); @override String toString() { - return (StringBuffer('Entrie(') + return (StringBuffer('Entry(') ..write('id: $id, ') ..write('value: $value') ..write(')')) @@ -120,10 +120,10 @@ class Entrie extends DataClass implements Insertable { @override bool operator ==(Object other) => identical(this, other) || - (other is Entrie && other.id == this.id && other.value == this.value); + (other is Entry && other.id == this.id && other.value == this.value); } -class EntriesCompanion extends UpdateCompanion { +class EntriesCompanion extends UpdateCompanion { final Value id; final Value value; const EntriesCompanion({ @@ -134,7 +134,7 @@ class EntriesCompanion extends UpdateCompanion { this.id = const Value.absent(), required String value, }) : value = Value(value); - static Insertable custom({ + static Insertable custom({ Expression? id, Expression? value, }) { @@ -176,7 +176,7 @@ class EntriesCompanion extends UpdateCompanion { abstract class _$MyDatabase extends GeneratedDatabase { _$MyDatabase(QueryExecutor e) : super(e); late final Entries entries = Entries(this); - Selectable allEntries() { + Selectable allEntries() { return customSelect('SELECT * FROM entries', variables: [], readsFrom: { entries, }).asyncMap(entries.mapFromRow); diff --git a/examples/web_worker_example/lib/database.g.dart b/examples/web_worker_example/lib/database.g.dart index ca90faf1..06e4c94e 100644 --- a/examples/web_worker_example/lib/database.g.dart +++ b/examples/web_worker_example/lib/database.g.dart @@ -3,7 +3,7 @@ part of 'database.dart'; // ignore_for_file: type=lint -class Entries extends Table with TableInfo { +class Entries extends Table with TableInfo { @override final GeneratedDatabase attachedDatabase; final String? _alias; @@ -28,7 +28,7 @@ class Entries extends Table with TableInfo { String get actualTableName => $name; static const String $name = 'entries'; @override - VerificationContext validateIntegrity(Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); @@ -47,9 +47,9 @@ class Entries extends Table with TableInfo { @override Set get $primaryKey => {id}; @override - Entrie map(Map data, {String? tablePrefix}) { + Entry map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return Entrie( + return Entry( id: attachedDatabase.typeMapping .read(DriftSqlType.int, data['${effectivePrefix}id'])!, value: attachedDatabase.typeMapping @@ -66,10 +66,10 @@ class Entries extends Table with TableInfo { bool get dontWriteConstraints => true; } -class Entrie extends DataClass implements Insertable { +class Entry extends DataClass implements Insertable { final int id; final String value; - const Entrie({required this.id, required this.value}); + const Entry({required this.id, required this.value}); @override Map toColumns(bool nullToAbsent) { final map = {}; @@ -85,10 +85,10 @@ class Entrie extends DataClass implements Insertable { ); } - factory Entrie.fromJson(Map json, + factory Entry.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return Entrie( + return Entry( id: serializer.fromJson(json['id']), value: serializer.fromJson(json['text']), ); @@ -102,13 +102,13 @@ class Entrie extends DataClass implements Insertable { }; } - Entrie copyWith({int? id, String? value}) => Entrie( + Entry copyWith({int? id, String? value}) => Entry( id: id ?? this.id, value: value ?? this.value, ); @override String toString() { - return (StringBuffer('Entrie(') + return (StringBuffer('Entry(') ..write('id: $id, ') ..write('value: $value') ..write(')')) @@ -120,10 +120,10 @@ class Entrie extends DataClass implements Insertable { @override bool operator ==(Object other) => identical(this, other) || - (other is Entrie && other.id == this.id && other.value == this.value); + (other is Entry && other.id == this.id && other.value == this.value); } -class EntriesCompanion extends UpdateCompanion { +class EntriesCompanion extends UpdateCompanion { final Value id; final Value value; const EntriesCompanion({ @@ -134,7 +134,7 @@ class EntriesCompanion extends UpdateCompanion { this.id = const Value.absent(), required String value, }) : value = Value(value); - static Insertable custom({ + static Insertable custom({ Expression? id, Expression? value, }) { @@ -176,7 +176,7 @@ class EntriesCompanion extends UpdateCompanion { abstract class _$MyDatabase extends GeneratedDatabase { _$MyDatabase(QueryExecutor e) : super(e); late final Entries entries = Entries(this); - Selectable allEntries() { + Selectable allEntries() { return customSelect('SELECT * FROM entries', variables: [], readsFrom: { entries, }).asyncMap(entries.mapFromRow);