objectbox-dart
objectbox-dart copied to clipboard
Support DateTime query conditions (or at least document current approach)
-
ObjectBox version: [e.g. 0.14.0] 1.1.1
-
Flutter/Dart SDK: [e.g. 2.0.0, or the output of
dart --version
orflutter --version
]Flutter 2.2.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision f4abaa0735 (3 weeks ago) • 2021-07-01 12:46:11 -0700 Engine • revision 241c87ad80 Tools • Dart 2.13.4
-
Null-safety enabled: [yes | no] yes
-
Reproducibility: [e.g. occurred once only | occasionally without visible pattern | always] Create any Entity with DateTime as one of the variable Try to build query condition in the DateTime Variable. The property comes as an Integer property and not as a DateTime property. How to use query conditions like before or after, etc.
Currently for date fields, you need to use the timestamp, i.e. the same thing is stored internally in the database (it's a millisecond timestamp for date fields and nanosecond timestamp for @Property(type: PropertyType.dateNano)
).
Assuming an Order
entity with a date
field, you can query all orders from 2020 like this:
@Entity()
class Order {
final int id;
final DateTime date;
}
...
final query = box.query(
Order_.date.between(DateTime(2020).millisecondsSinceEpoch, DateTime(2021).millisecondsSinceEpoch - 1)
).build();
It would be nice for all the query conditions to support DateTime fields directly so leaving this issue open as a feature request.
@vaind
Thanks for the answer, can we put it in dart documentation (example page) and object box documentation, because currently it is not mentioned there and I think anyone checking the documentation will infer limited or no query operations for date time.
Hi, can I work on this?
any update?
@OHeroJ We share updates if there are some, no need to ask, thanks!
Edit: The current approach is documented at https://docs.objectbox.io/queries#common-conditions
Edit: if you are interested in something, it helps us more if you thumbs up the first comment!
I would like to work on this
New conditions were added and will be available with the next release.