-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for type converters #318
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #318 +/- ##
===========================================
+ Coverage 81.56% 82.71% +1.14%
===========================================
Files 60 68 +8
Lines 1535 1660 +125
===========================================
+ Hits 1252 1373 +121
- Misses 283 287 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
# Conflicts: # floor_generator/lib/processor/queryable_processor.dart # floor_generator/lib/value_object/entity.dart # floor_generator/lib/writer/query_method_writer.dart # floor_generator/test/value_object/entity_test.dart
This reverts commit b3447cf
@vitusortner |
@vitusortner Hi! Any updates on this? 🙂 |
I finally have some more time to look into this feature again. I'll keep you updated! |
# Conflicts: # floor_generator/lib/processor/entity_processor.dart # floor_generator/lib/value_object/entity.dart # floor_generator/test/processor/entity_processor_test.dart # floor_generator/test/value_object/entity_test.dart
This reverts commit 07259ef
# Conflicts: # floor_generator/lib/processor/database_processor.dart # floor_generator/pubspec.yaml
The long-awaited type converters are here! 🎉
Public API
First, some words about the public API of type converters. I wanted to make type converters as safe as possible at compile time. Thereby, I added an abstract
TypeConverter
class that required two type parameters. The first is the encoded type that is used outside of the database scope. The second type is the decoded database type. The abstract class, furthermore, comes with the two functionsencode()
anddecode()
which have to be overridden by the implementation classes. This way, we can be sure that there always is functionality provided for conversion in both directions. Room is missing this extra security as they use plain functions as type converters.A simple type converter that converts from
DateTime
toint
and vice versa is shown in the following.Such a class can then be applied to the database with different scope restrictions by using the
@TypeConverters
annotation. These scopes are:Implementation
Floor generates and uses type converter as described in the following.
Processors
Writers
@TypeConverters
)This still needs work:
Closes #165
Closes #313 as we won't fall back to
double
when the type of a field is unknown