From 041abcfce98ae9868065a0d6d0ce2c80f424f47d Mon Sep 17 00:00:00 2001 From: Vitus Date: Sat, 1 May 2021 19:27:51 +0200 Subject: [PATCH 1/4] Update website URL (#560) --- README.md | 3 +-- example/pubspec.yaml | 2 +- floor/README.md | 2 +- floor/pubspec.yaml | 2 +- floor_annotation/pubspec.yaml | 2 +- floor_generator/pubspec.yaml | 2 +- mkdocs.yml | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c9ad2258..56bbe8ed 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ ![Floor](https://raw.githubusercontent.com/vitusortner/floor/develop/img/floor.png) -**See the [project's website](https://vitusortner.github.io/floor/) for the full documentation.** -**[Vote for our domain name 🗳](https://github.com/vitusortner/floor/discussions/546)** +**See the [project's website](https://floor.codes) for the full documentation.** Floor provides a neat SQLite abstraction for your Flutter applications inspired by the [Room persistence library](https://developer.android.com/topic/libraries/architecture/room). It comes with automatic mapping between in-memory objects and database rows while still offering full control of the database with the use of SQL. diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 7edcbca6..8c131f13 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: > The typesafe, reactive and lightweight SQLite abstraction for your Flutter applications. This is an example on how to use the library. version: 1.0.0 -homepage: https://github.com/vitusortner/floor +homepage: https://floor.codes author: vitusortner publish_to: none diff --git a/floor/README.md b/floor/README.md index a0ccab5a..207b9b05 100644 --- a/floor/README.md +++ b/floor/README.md @@ -1,6 +1,6 @@ ![Floor](https://raw.githubusercontent.com/vitusortner/floor/develop/img/floor.png) -**See the [project's website](https://vitusortner.github.io/floor/) for the full documentation.** +**See the [project's website](https://floor.codes) for the full documentation.** Floor provides a neat SQLite abstraction for your Flutter applications inspired by the [Room persistence library](https://developer.android.com/topic/libraries/architecture/room). It comes with automatic mapping between in-memory objects and database rows while still offering full control of the database with the use of SQL. diff --git a/floor/pubspec.yaml b/floor/pubspec.yaml index a3609d10..f7c7adaf 100644 --- a/floor/pubspec.yaml +++ b/floor/pubspec.yaml @@ -3,7 +3,7 @@ description: > The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications. This library is the runtime dependency. version: 1.1.0 -homepage: https://github.com/vitusortner/floor +homepage: https://floor.codes author: Vitus Ortner publish_to: none diff --git a/floor_annotation/pubspec.yaml b/floor_annotation/pubspec.yaml index 1ee027b2..218f6f5f 100644 --- a/floor_annotation/pubspec.yaml +++ b/floor_annotation/pubspec.yaml @@ -3,7 +3,7 @@ description: > The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications. Don't use this package directly. Import the floor package instead. version: 1.0.0 -homepage: https://github.com/vitusortner/floor +homepage: https://floor.codes author: Vitus Ortner environment: diff --git a/floor_generator/pubspec.yaml b/floor_generator/pubspec.yaml index bd3dff0a..f085e190 100644 --- a/floor_generator/pubspec.yaml +++ b/floor_generator/pubspec.yaml @@ -3,7 +3,7 @@ description: > The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications. This library is the dev dependency. version: 1.1.0 -homepage: https://github.com/vitusortner/floor +homepage: https://floor.codes author: Vitus Ortner publish_to: none diff --git a/mkdocs.yml b/mkdocs.yml index 5bfb6940..16d1c2c1 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,6 +1,6 @@ site_name: Floor SQLite site_description: "Floor - The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications" -site_url: https://vitusortner.github.io/floor/ +site_url: https://floor.codes repo_name: floor repo_url: https://github.com/vitusortner/floor edit_uri: edit/develop/docs/ From d26c8d318aee2256bd0564a8b65d42e55fdabcdd Mon Sep 17 00:00:00 2001 From: Vitus Date: Sat, 1 May 2021 19:43:10 +0200 Subject: [PATCH 2/4] Keep CNAME file throughout website deployments (#561) --- docs/CNAME | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/CNAME diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 00000000..de25b2a3 --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +floor.codes From 1c14faff5d378b91ed5f210bdab62a57f8ea086a Mon Sep 17 00:00:00 2001 From: Vitus Date: Sun, 2 May 2021 13:17:00 +0200 Subject: [PATCH 3/4] Remove author section from pubspecs (#562) --- example/pubspec.yaml | 1 - floor/pubspec.yaml | 1 - floor_annotation/pubspec.yaml | 1 - floor_generator/pubspec.yaml | 1 - 4 files changed, 4 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 8c131f13..89015152 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,6 @@ description: > This is an example on how to use the library. version: 1.0.0 homepage: https://floor.codes -author: vitusortner publish_to: none environment: diff --git a/floor/pubspec.yaml b/floor/pubspec.yaml index f7c7adaf..99531289 100644 --- a/floor/pubspec.yaml +++ b/floor/pubspec.yaml @@ -4,7 +4,6 @@ description: > This library is the runtime dependency. version: 1.1.0 homepage: https://floor.codes -author: Vitus Ortner publish_to: none environment: diff --git a/floor_annotation/pubspec.yaml b/floor_annotation/pubspec.yaml index 218f6f5f..08f658e6 100644 --- a/floor_annotation/pubspec.yaml +++ b/floor_annotation/pubspec.yaml @@ -4,7 +4,6 @@ description: > Don't use this package directly. Import the floor package instead. version: 1.0.0 homepage: https://floor.codes -author: Vitus Ortner environment: sdk: '>=2.12.0 <3.0.0' diff --git a/floor_generator/pubspec.yaml b/floor_generator/pubspec.yaml index f085e190..d6cb64d4 100644 --- a/floor_generator/pubspec.yaml +++ b/floor_generator/pubspec.yaml @@ -4,7 +4,6 @@ description: > This library is the dev dependency. version: 1.1.0 homepage: https://floor.codes -author: Vitus Ortner publish_to: none environment: From 57b4899a2d8d20038a172788d57a8f041af4fbe6 Mon Sep 17 00:00:00 2001 From: mqus <8398165+mqus@users.noreply.github.com> Date: Sun, 2 May 2021 13:26:59 +0200 Subject: [PATCH 4/4] Bugfix/nullable transaction return (#559) --- .../lib/processor/queryable_processor.dart | 25 ++---- .../lib/writer/transaction_method_writer.dart | 4 +- .../transaction_method_writer_test.dart | 82 +++++++++++++++++++ 3 files changed, 93 insertions(+), 18 deletions(-) diff --git a/floor_generator/lib/processor/queryable_processor.dart b/floor_generator/lib/processor/queryable_processor.dart index 6cb887fd..95b0a13a 100644 --- a/floor_generator/lib/processor/queryable_processor.dart +++ b/floor_generator/lib/processor/queryable_processor.dart @@ -2,6 +2,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:collection/collection.dart'; import 'package:floor_annotation/floor_annotation.dart' as annotations; +import 'package:floor_generator/misc/extension/dart_type_extension.dart'; import 'package:floor_generator/misc/extension/set_extension.dart'; import 'package:floor_generator/misc/extension/string_extension.dart'; import 'package:floor_generator/misc/extension/type_converter_element_extension.dart'; @@ -79,7 +80,6 @@ abstract class QueryableProcessor extends Processor { if (parameterElement.type.isDefaultSqlType) { parameterValue = databaseValue.cast( parameterElement.type, - field.isNullable, parameterElement, ); } else { @@ -88,7 +88,6 @@ abstract class QueryableProcessor extends Processor { .getClosest(parameterElement.type); final castedDatabaseValue = databaseValue.cast( typeConverter.databaseType, - field.isNullable, parameterElement, ); @@ -107,27 +106,21 @@ abstract class QueryableProcessor extends Processor { } extension on String { - String cast( - DartType dartType, - bool isNullable, - ParameterElement parameterElement, - ) { + String cast(DartType dartType, ParameterElement parameterElement) { if (dartType.isDartCoreBool) { - if (isNullable) { + if (dartType.isNullable) { // if the value is null, return null // if the value is not null, interpret 1 as true and 0 as false return '$this == null ? null : ($this as int) != 0'; } else { return '($this as int) != 0'; } - } else if (dartType.isDartCoreString) { - return '$this as String${isNullable ? '?' : ''}'; - } else if (dartType.isDartCoreInt) { - return '$this as int${isNullable ? '?' : ''}'; - } else if (dartType.isUint8List) { - return '$this as Uint8List${isNullable ? '?' : ''}'; - } else if (dartType.isDartCoreDouble) { - return '$this as double${isNullable ? '?' : ''}'; + } else if (dartType.isDartCoreString || + dartType.isDartCoreInt || + dartType.isUint8List || + dartType.isDartCoreDouble) { + final typeString = dartType.getDisplayString(withNullability: true); + return '$this as $typeString'; } else { throw InvalidGenerationSourceError( 'Trying to convert unsupported type $dartType.', diff --git a/floor_generator/lib/writer/transaction_method_writer.dart b/floor_generator/lib/writer/transaction_method_writer.dart index e4425a38..8ac253b8 100644 --- a/floor_generator/lib/writer/transaction_method_writer.dart +++ b/floor_generator/lib/writer/transaction_method_writer.dart @@ -14,7 +14,7 @@ class TransactionMethodWriter implements Writer { return Method((builder) => builder ..annotations.add(overrideAnnotationExpression) ..returns = refer(method.returnType.getDisplayString( - withNullability: false, + withNullability: true, )) ..name = method.name ..requiredParameters.addAll(_generateParameters()) @@ -47,7 +47,7 @@ class TransactionMethodWriter implements Writer { return Parameter((builder) => builder ..name = parameter.name ..type = refer(parameter.type.getDisplayString( - withNullability: false, + withNullability: true, ))); }).toList(); } diff --git a/floor_generator/test/writer/transaction_method_writer_test.dart b/floor_generator/test/writer/transaction_method_writer_test.dart index 83960745..55d8c4f2 100644 --- a/floor_generator/test/writer/transaction_method_writer_test.dart +++ b/floor_generator/test/writer/transaction_method_writer_test.dart @@ -87,6 +87,88 @@ void main() { } ''')); }); + + test('Generate transaction method with nullable future return', () async { + final transactionMethod = await _createTransactionMethod(''' + @transaction + Future? replacePersons(List persons) async { + return null; + } + '''); + + final actual = TransactionMethodWriter(transactionMethod).write(); + + expect(actual, equalsDart(r''' + @override + Future? replacePersons(List persons) async { + if (database is sqflite.Transaction) { + return super.replacePersons(persons); + } else { + return (database as sqflite.Database) + .transaction((transaction) async { + final transactionDatabase = _$TestDatabase(changeListener) + ..database = transaction; + return transactionDatabase.personDao.replacePersons(persons); + }); + } + } + ''')); + }); + + test('Generate transaction method with nullable return type parameter', + () async { + final transactionMethod = await _createTransactionMethod(''' + @transaction + Future replacePersons(List persons) async { + return null; + } + '''); + + final actual = TransactionMethodWriter(transactionMethod).write(); + + expect(actual, equalsDart(r''' + @override + Future replacePersons(List persons) async { + if (database is sqflite.Transaction) { + return super.replacePersons(persons); + } else { + return (database as sqflite.Database) + .transaction((transaction) async { + final transactionDatabase = _$TestDatabase(changeListener) + ..database = transaction; + return transactionDatabase.personDao.replacePersons(persons); + }); + } + } + ''')); + }); + + test('Generate transaction method with nullable parameter', () async { + final transactionMethod = await _createTransactionMethod(''' + @transaction + Future? replacePersons(Person? person) async { + return null; + } + '''); + + final actual = TransactionMethodWriter(transactionMethod).write(); + + expect(actual, equalsDart(r''' + @override + Future? replacePersons(Person? person) async { + if (database is sqflite.Transaction) { + return super.replacePersons(person); + } else { + return (database as sqflite.Database) + .transaction((transaction) async { + final transactionDatabase = _$TestDatabase(changeListener) + ..database = transaction; + return transactionDatabase.personDao.replacePersons(person); + }); + } + } + ''')); + }); } Future _createTransactionMethod(