Comments (6)
I've thought about introducing type converters similar how Room handles these conversions. This would open up the possibility of persisting data of custom date implementations, for instance. What are your thoughts?
from floor.
I found a workaround for now using the dart built-in features :
- var milliseconds = DateTime.now().millisecondsSinceEpoch
- DateTime.fromMillisecondsSinceEpoch(milliseconds)
Not sure why DateTime is not supported. I think SQLite support it as format.
@vitusortner Do you have some technical limitation here? Why do you need to convert?
from floor.
@vitusortner: Further to the above:
For example, whenever an enum value should get stored.
For the special case of enums, wouldn't it make sense to have floor simply store in an int column, and just convert using myEnum.index and myEnum.values[n]?
One step up would be to copy the idea from JPA and use an annotation to allow mapping by user's choice of int value or by string name (FWIW, JPA uses @Enumerated(EnumType.STRING) or EnumType.ORDINAL; ORDINAL is the default there). It's well known there that ordinal is more efficient but does mean you can't add new values to the enum except at the end.
This would be simpler than fully implementing type converters and could maybe get in sooner? But meanwhile I've had to convert my entity to use ints for dates (as you suggest) and for enums.
from floor.
DateTime
is not supported by sqflite (the database access layer).
Type converters might seem like an overkill for such an easy mapping between milliseconds and Dart's DateTime
. They surely simplify the interaction with the database. Nevertheless, type converters come in even more handy when thinking about other conversions. For example, whenever an enum value should get stored. It's nicer to just define a type converter in one place and let it do its magic automatically without calling its functions manually.
from floor.
Yes, make sense. :)
from floor.
It's not planned to support DateTime
out of the box for now. Same for enums. Instead, type converters will be introduced soon which will solve these problems. Follow the progress and discussion in #165.
from floor.
Related Issues (20)
- Improve FTS documentation and add some examples
- Not supported on Flutter Web HOT 1
- dependecy conflict with riverpod_lint 2.3.3 HOT 2
- Dumplicate field name when entity implement form abstract class HOT 1
- duplicate field name when entity implement form abstract class
- Unhandled Exception: type 'Null' is not a subtype of type 'double' in type cast HOT 1
- This exception cannot be executed on the entire floor library
- trying to get a SUM of a field with floor. HOT 1
- Custom Database File Path HOT 1
- sqlite wal HOT 1
- How to update a List of an object as field of entity into table in Floor
- How add rawQuery added ?? HOT 2
- Are there any plans to adapt HarmonyOS HOT 4
- Imports collision HOT 1
- #802 still an issue. any help?
- Casting to double might not work; HOT 1
- dependencies issue HOT 5
- Invalid query (failing to parse) does not throw an error
- onCreate callback is not being called, "tbl not found" exception
- How to select with like ??? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from floor.