objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

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

Open raphire08 opened this issue 3 years ago • 6 comments

  • ObjectBox version: [e.g. 0.14.0] 1.1.1

  • Flutter/Dart SDK: [e.g. 2.0.0, or the output of dart --version or flutter --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.

raphire08 avatar Jul 26 '21 09:07 raphire08

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 avatar Jul 26 '21 10:07 vaind

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

raphire08 avatar Jul 26 '21 11:07 raphire08

Hi, can I work on this?

pedr0luiz avatar Oct 26 '21 17:10 pedr0luiz

any update?

OHeroJ avatar Aug 24 '22 01:08 OHeroJ

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

greenrobot-team avatar Aug 24 '22 05:08 greenrobot-team

I would like to work on this

kumarpriyanshu2k2 avatar Oct 04 '22 14:10 kumarpriyanshu2k2

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

greenrobot-team avatar Feb 12 '24 08:02 greenrobot-team