Re-run builders, add changelog entry

This commit is contained in:
Simon Binder 2023-11-22 13:09:09 +01:00
parent 3fb9e50f75
commit 28c3c444e7
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
7 changed files with 55 additions and 50 deletions

View File

@ -1,5 +1,10 @@
## 2.14.0-dev ## 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 ## 2.13.2
- Fix generated queries relying on custom types. - Fix generated queries relying on custom types.

View File

@ -14,19 +14,19 @@ String dataClassNameForClassName(String tableName) {
// from the table name. // from the table name.
if (tableName.endsWith('s')) { 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; return tableName;
} else if (tableName.endsWith('ies')) { } else if (tableName.endsWith('ies')) {
return tableName.substring(0, tableName.length - 3) + 'y'; return '${tableName.substring(0, tableName.length - 3)}y';
} else { } else {
return tableName.substring(0, tableName.length - 1); return tableName.substring(0, tableName.length - 1);
} }
} else { } 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( AnnotatedDartCode? parseCustomParentClass(

View File

@ -473,8 +473,8 @@ class TodoEntriesCompanion extends UpdateCompanion<TodoEntry> {
class TextEntries extends Table class TextEntries extends Table
with with
TableInfo<TextEntries, TextEntrie>, TableInfo<TextEntries, TextEntry>,
VirtualTableInfo<TextEntries, TextEntrie> { VirtualTableInfo<TextEntries, TextEntry> {
@override @override
final GeneratedDatabase attachedDatabase; final GeneratedDatabase attachedDatabase;
final String? _alias; final String? _alias;
@ -494,7 +494,7 @@ class TextEntries extends Table
String get actualTableName => $name; String get actualTableName => $name;
static const String $name = 'text_entries'; static const String $name = 'text_entries';
@override @override
VerificationContext validateIntegrity(Insertable<TextEntrie> instance, VerificationContext validateIntegrity(Insertable<TextEntry> instance,
{bool isInserting = false}) { {bool isInserting = false}) {
final context = VerificationContext(); final context = VerificationContext();
final data = instance.toColumns(true); final data = instance.toColumns(true);
@ -512,9 +512,9 @@ class TextEntries extends Table
@override @override
Set<GeneratedColumn> get $primaryKey => const {}; Set<GeneratedColumn> get $primaryKey => const {};
@override @override
TextEntrie map(Map<String, dynamic> data, {String? tablePrefix}) { TextEntry map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return TextEntrie( return TextEntry(
description: attachedDatabase.typeMapping description: attachedDatabase.typeMapping
.read(DriftSqlType.string, data['${effectivePrefix}description'])!, .read(DriftSqlType.string, data['${effectivePrefix}description'])!,
); );
@ -532,9 +532,9 @@ class TextEntries extends Table
'fts5(description, content=todo_entries, content_rowid=id)'; 'fts5(description, content=todo_entries, content_rowid=id)';
} }
class TextEntrie extends DataClass implements Insertable<TextEntrie> { class TextEntry extends DataClass implements Insertable<TextEntry> {
final String description; final String description;
const TextEntrie({required this.description}); const TextEntry({required this.description});
@override @override
Map<String, Expression> toColumns(bool nullToAbsent) { Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{}; final map = <String, Expression>{};
@ -548,10 +548,10 @@ class TextEntrie extends DataClass implements Insertable<TextEntrie> {
); );
} }
factory TextEntrie.fromJson(Map<String, dynamic> json, factory TextEntry.fromJson(Map<String, dynamic> json,
{ValueSerializer? serializer}) { {ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
return TextEntrie( return TextEntry(
description: serializer.fromJson<String>(json['description']), description: serializer.fromJson<String>(json['description']),
); );
} }
@ -563,12 +563,12 @@ class TextEntrie extends DataClass implements Insertable<TextEntrie> {
}; };
} }
TextEntrie copyWith({String? description}) => TextEntrie( TextEntry copyWith({String? description}) => TextEntry(
description: description ?? this.description, description: description ?? this.description,
); );
@override @override
String toString() { String toString() {
return (StringBuffer('TextEntrie(') return (StringBuffer('TextEntry(')
..write('description: $description') ..write('description: $description')
..write(')')) ..write(')'))
.toString(); .toString();
@ -579,10 +579,10 @@ class TextEntrie extends DataClass implements Insertable<TextEntrie> {
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
identical(this, other) || identical(this, other) ||
(other is TextEntrie && other.description == this.description); (other is TextEntry && other.description == this.description);
} }
class TextEntriesCompanion extends UpdateCompanion<TextEntrie> { class TextEntriesCompanion extends UpdateCompanion<TextEntry> {
final Value<String> description; final Value<String> description;
final Value<int> rowid; final Value<int> rowid;
const TextEntriesCompanion({ const TextEntriesCompanion({
@ -593,7 +593,7 @@ class TextEntriesCompanion extends UpdateCompanion<TextEntrie> {
required String description, required String description,
this.rowid = const Value.absent(), this.rowid = const Value.absent(),
}) : description = Value(description); }) : description = Value(description);
static Insertable<TextEntrie> custom({ static Insertable<TextEntry> custom({
Expression<String>? description, Expression<String>? description,
Expression<int>? rowid, Expression<int>? rowid,
}) { }) {

View File

@ -9,7 +9,7 @@ environment:
dependencies: dependencies:
drift: ^2.0.2+1 drift: ^2.0.2+1
sqlcipher_flutter_libs: ^0.5.1 sqlcipher_flutter_libs: ^0.6.0
flutter: flutter:
sdk: flutter sdk: flutter
path_provider: ^2.0.11 path_provider: ^2.0.11

View File

@ -14,7 +14,7 @@ void main() {
} }
class _DatabaseSampleState extends State<_DatabaseSample> { class _DatabaseSampleState extends State<_DatabaseSample> {
List<Entrie> allItems = []; List<Entry> allItems = [];
TextEditingController editController = TextEditingController(); TextEditingController editController = TextEditingController();
final database = MyDatabase(Platform.createDatabaseConnection('sample')); final database = MyDatabase(Platform.createDatabaseConnection('sample'));

View File

@ -3,7 +3,7 @@
part of 'database.dart'; part of 'database.dart';
// ignore_for_file: type=lint // ignore_for_file: type=lint
class Entries extends Table with TableInfo<Entries, Entrie> { class Entries extends Table with TableInfo<Entries, Entry> {
@override @override
final GeneratedDatabase attachedDatabase; final GeneratedDatabase attachedDatabase;
final String? _alias; final String? _alias;
@ -28,7 +28,7 @@ class Entries extends Table with TableInfo<Entries, Entrie> {
String get actualTableName => $name; String get actualTableName => $name;
static const String $name = 'entries'; static const String $name = 'entries';
@override @override
VerificationContext validateIntegrity(Insertable<Entrie> instance, VerificationContext validateIntegrity(Insertable<Entry> instance,
{bool isInserting = false}) { {bool isInserting = false}) {
final context = VerificationContext(); final context = VerificationContext();
final data = instance.toColumns(true); final data = instance.toColumns(true);
@ -47,9 +47,9 @@ class Entries extends Table with TableInfo<Entries, Entrie> {
@override @override
Set<GeneratedColumn> get $primaryKey => {id}; Set<GeneratedColumn> get $primaryKey => {id};
@override @override
Entrie map(Map<String, dynamic> data, {String? tablePrefix}) { Entry map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return Entrie( return Entry(
id: attachedDatabase.typeMapping id: attachedDatabase.typeMapping
.read(DriftSqlType.int, data['${effectivePrefix}id'])!, .read(DriftSqlType.int, data['${effectivePrefix}id'])!,
value: attachedDatabase.typeMapping value: attachedDatabase.typeMapping
@ -66,10 +66,10 @@ class Entries extends Table with TableInfo<Entries, Entrie> {
bool get dontWriteConstraints => true; bool get dontWriteConstraints => true;
} }
class Entrie extends DataClass implements Insertable<Entrie> { class Entry extends DataClass implements Insertable<Entry> {
final int id; final int id;
final String value; final String value;
const Entrie({required this.id, required this.value}); const Entry({required this.id, required this.value});
@override @override
Map<String, Expression> toColumns(bool nullToAbsent) { Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{}; final map = <String, Expression>{};
@ -85,10 +85,10 @@ class Entrie extends DataClass implements Insertable<Entrie> {
); );
} }
factory Entrie.fromJson(Map<String, dynamic> json, factory Entry.fromJson(Map<String, dynamic> json,
{ValueSerializer? serializer}) { {ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
return Entrie( return Entry(
id: serializer.fromJson<int>(json['id']), id: serializer.fromJson<int>(json['id']),
value: serializer.fromJson<String>(json['text']), value: serializer.fromJson<String>(json['text']),
); );
@ -102,13 +102,13 @@ class Entrie extends DataClass implements Insertable<Entrie> {
}; };
} }
Entrie copyWith({int? id, String? value}) => Entrie( Entry copyWith({int? id, String? value}) => Entry(
id: id ?? this.id, id: id ?? this.id,
value: value ?? this.value, value: value ?? this.value,
); );
@override @override
String toString() { String toString() {
return (StringBuffer('Entrie(') return (StringBuffer('Entry(')
..write('id: $id, ') ..write('id: $id, ')
..write('value: $value') ..write('value: $value')
..write(')')) ..write(')'))
@ -120,10 +120,10 @@ class Entrie extends DataClass implements Insertable<Entrie> {
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
identical(this, 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<Entrie> { class EntriesCompanion extends UpdateCompanion<Entry> {
final Value<int> id; final Value<int> id;
final Value<String> value; final Value<String> value;
const EntriesCompanion({ const EntriesCompanion({
@ -134,7 +134,7 @@ class EntriesCompanion extends UpdateCompanion<Entrie> {
this.id = const Value.absent(), this.id = const Value.absent(),
required String value, required String value,
}) : value = Value(value); }) : value = Value(value);
static Insertable<Entrie> custom({ static Insertable<Entry> custom({
Expression<int>? id, Expression<int>? id,
Expression<String>? value, Expression<String>? value,
}) { }) {
@ -176,7 +176,7 @@ class EntriesCompanion extends UpdateCompanion<Entrie> {
abstract class _$MyDatabase extends GeneratedDatabase { abstract class _$MyDatabase extends GeneratedDatabase {
_$MyDatabase(QueryExecutor e) : super(e); _$MyDatabase(QueryExecutor e) : super(e);
late final Entries entries = Entries(this); late final Entries entries = Entries(this);
Selectable<Entrie> allEntries() { Selectable<Entry> allEntries() {
return customSelect('SELECT * FROM entries', variables: [], readsFrom: { return customSelect('SELECT * FROM entries', variables: [], readsFrom: {
entries, entries,
}).asyncMap(entries.mapFromRow); }).asyncMap(entries.mapFromRow);

View File

@ -3,7 +3,7 @@
part of 'database.dart'; part of 'database.dart';
// ignore_for_file: type=lint // ignore_for_file: type=lint
class Entries extends Table with TableInfo<Entries, Entrie> { class Entries extends Table with TableInfo<Entries, Entry> {
@override @override
final GeneratedDatabase attachedDatabase; final GeneratedDatabase attachedDatabase;
final String? _alias; final String? _alias;
@ -28,7 +28,7 @@ class Entries extends Table with TableInfo<Entries, Entrie> {
String get actualTableName => $name; String get actualTableName => $name;
static const String $name = 'entries'; static const String $name = 'entries';
@override @override
VerificationContext validateIntegrity(Insertable<Entrie> instance, VerificationContext validateIntegrity(Insertable<Entry> instance,
{bool isInserting = false}) { {bool isInserting = false}) {
final context = VerificationContext(); final context = VerificationContext();
final data = instance.toColumns(true); final data = instance.toColumns(true);
@ -47,9 +47,9 @@ class Entries extends Table with TableInfo<Entries, Entrie> {
@override @override
Set<GeneratedColumn> get $primaryKey => {id}; Set<GeneratedColumn> get $primaryKey => {id};
@override @override
Entrie map(Map<String, dynamic> data, {String? tablePrefix}) { Entry map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return Entrie( return Entry(
id: attachedDatabase.typeMapping id: attachedDatabase.typeMapping
.read(DriftSqlType.int, data['${effectivePrefix}id'])!, .read(DriftSqlType.int, data['${effectivePrefix}id'])!,
value: attachedDatabase.typeMapping value: attachedDatabase.typeMapping
@ -66,10 +66,10 @@ class Entries extends Table with TableInfo<Entries, Entrie> {
bool get dontWriteConstraints => true; bool get dontWriteConstraints => true;
} }
class Entrie extends DataClass implements Insertable<Entrie> { class Entry extends DataClass implements Insertable<Entry> {
final int id; final int id;
final String value; final String value;
const Entrie({required this.id, required this.value}); const Entry({required this.id, required this.value});
@override @override
Map<String, Expression> toColumns(bool nullToAbsent) { Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{}; final map = <String, Expression>{};
@ -85,10 +85,10 @@ class Entrie extends DataClass implements Insertable<Entrie> {
); );
} }
factory Entrie.fromJson(Map<String, dynamic> json, factory Entry.fromJson(Map<String, dynamic> json,
{ValueSerializer? serializer}) { {ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
return Entrie( return Entry(
id: serializer.fromJson<int>(json['id']), id: serializer.fromJson<int>(json['id']),
value: serializer.fromJson<String>(json['text']), value: serializer.fromJson<String>(json['text']),
); );
@ -102,13 +102,13 @@ class Entrie extends DataClass implements Insertable<Entrie> {
}; };
} }
Entrie copyWith({int? id, String? value}) => Entrie( Entry copyWith({int? id, String? value}) => Entry(
id: id ?? this.id, id: id ?? this.id,
value: value ?? this.value, value: value ?? this.value,
); );
@override @override
String toString() { String toString() {
return (StringBuffer('Entrie(') return (StringBuffer('Entry(')
..write('id: $id, ') ..write('id: $id, ')
..write('value: $value') ..write('value: $value')
..write(')')) ..write(')'))
@ -120,10 +120,10 @@ class Entrie extends DataClass implements Insertable<Entrie> {
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
identical(this, 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<Entrie> { class EntriesCompanion extends UpdateCompanion<Entry> {
final Value<int> id; final Value<int> id;
final Value<String> value; final Value<String> value;
const EntriesCompanion({ const EntriesCompanion({
@ -134,7 +134,7 @@ class EntriesCompanion extends UpdateCompanion<Entrie> {
this.id = const Value.absent(), this.id = const Value.absent(),
required String value, required String value,
}) : value = Value(value); }) : value = Value(value);
static Insertable<Entrie> custom({ static Insertable<Entry> custom({
Expression<int>? id, Expression<int>? id,
Expression<String>? value, Expression<String>? value,
}) { }) {
@ -176,7 +176,7 @@ class EntriesCompanion extends UpdateCompanion<Entrie> {
abstract class _$MyDatabase extends GeneratedDatabase { abstract class _$MyDatabase extends GeneratedDatabase {
_$MyDatabase(QueryExecutor e) : super(e); _$MyDatabase(QueryExecutor e) : super(e);
late final Entries entries = Entries(this); late final Entries entries = Entries(this);
Selectable<Entrie> allEntries() { Selectable<Entry> allEntries() {
return customSelect('SELECT * FROM entries', variables: [], readsFrom: { return customSelect('SELECT * FROM entries', variables: [], readsFrom: {
entries, entries,
}).asyncMap(entries.mapFromRow); }).asyncMap(entries.mapFromRow);