objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

Support DateTime query conditions (or at least document current approach) #287

Closed raphire08 closed 3 months ago

raphire08 commented 2 years ago
vaind commented 2 years ago

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.

raphire08 commented 2 years ago

@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.

pedr0luiz commented 2 years ago

Hi, can I work on this?

OHeroJ commented 1 year ago

any update?

greenrobot-team commented 1 year ago

@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!

kumarpriyanshu2k2 commented 1 year ago

I would like to work on this

greenrobot-team commented 3 months ago

New conditions were added and will be available with the next release.