-
Notifications
You must be signed in to change notification settings - Fork 188
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 #165
Comments
Hi. That sounds great! If you have questions about the structure of the library, just open a PR of the current state of your development or add them here. You can find a small wiki on the feature in the following. Type ConvertersType converters allow translating data right before inserting and after reading it in order to make the values storable in the database. For instance, an entity might hold a date in form of a
The library has to check whether such a type converter is applied to a specific entity, DAO, DAO function or the whole database. In order a converter is found, the library has to call the previously implemented converter functions whenever a matching type should get inserted, updated or selected. It's also required to change the field type of the entity when creating the table. In case of the APIThe full API of the feature is visible in the following code snippet. It includes the definition of the converter itself and multiple ways for applying it to either an entity, database, DAO or DAO function.
Room also allows applying converters to just a specific DAO function field. Let's discuss if that's required. More documentation on the feature can be found here and here. ImplementationThis feature requires changes in a couple places. But first, some explanation about the general architecture of the library. The annotation processor of it searches in the user's source code for a class annotated with When implementing the type converter functionality, it's required to check the source code for the |
Type Converters will be really useful for other data types as well. I am looking forward to their implementation. |
@vitusortner I found an alternative approach in |
Finally got some time to look into this. First of all, thank you for the tips. They have been really helpful as I've been studying the code. Secondly, I have some questons. How would you approach priority? I was thinking dao function > dao > entity > database. What do you think? And how would you implement that? I would really appreciate some pointers here as well. As for applying converters to specific DAO function fields, I feel like it could be skipped for now and gotten back to later if there is demand. I can't really think of a critical use case right now. |
@dkaera
Once converters have been realized for DAO function, DAO, entity and database scopes, it should be simple to also apply them to the scope of a field. @xiprox
|
Presumably the DateTime converter would ship as part of the library b/c that's such a commonly-used datatype. Maybe a few others too. Having the ability to map arbitrary datatypes used as fields would be definite win. Thanks && hope to see this one soon :-) |
A quick update: I've started the development of this highly requested feature and will release it as soon as possible. |
+1 for this, can't use this library without support for DateTime |
@vitusortner |
@vitusortner |
If you need it now, switch from floor to moor, like I just did. It's a non-trivial switch, but (a) they handle datetime, and enums, and various other things and (b) they already support type converters if you don't like the way they handle e.g., datetime (they store as a Unix time_t, but my existing app database used yyyy-mm-dd, so I just wrote a trivial converter and it's up and running). See https://moor.simonbinder.eu/ or google "flutter moor". |
@IanDarwin |
On Sun, Jul 12, 2020 at 07:42:31AM -0700, Yaroslav Pronin wrote:
***@***.***
The current solution is not entirely beautiful, but working: use a
shadow variable in entity to store data in DB format, and convert it in
the getter or initialize a field with the desired type in the
constructor.
That would have worked, I guess. Too far along to revert from moor to floor;
busy working on the rest of the building.
|
This is what we do in our current app. |
I looked at Moor, and it's too big and too opinionated. The less entanglements the better, and Moor is full of them. |
Yeah it could come as an out of the box feature. I would like to suggest to also provide option to transform DateTime to iso8601 or millisecondsSinceEpoch too, where we could config in a build.yaml file 🤔. Waiting for this feature to come out! |
Hi, is there an ETA for this? thanks for your great work! |
Any ETA on the release? I started implementing this library in my one project only to find out later that it doesnt cater for this? Sorry but I am going to have to find another library in the mean time |
Thanks for your interest in this feature. I'll create a new release ASAP that contains an experimental implementation of type converters. You can follow the progress here #318. |
I read a mention of this in #119. I think it's a great idea.
I will be digging the code and seeing if I can help out, but thought I'd open this issue anyway.
Also, thanks a lot for the great library!
The text was updated successfully, but these errors were encountered: