Skip to content
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

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

Closed
raphire08 opened this issue Jul 26, 2021 · 7 comments
Closed
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@raphire08
Copy link

raphire08 commented Jul 26, 2021

  • 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 raphire08 added the bug Something isn't working label Jul 26, 2021
@vaind
Copy link
Contributor

vaind commented Jul 26, 2021

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 vaind added enhancement New feature or request good first issue Good for newcomers help wanted Looking for contributors (ideas, comments, code, etc) and removed bug Something isn't working labels Jul 26, 2021
@raphire08
Copy link
Author

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

@vaind vaind added the documentation Improvements or additions to documentation label Jul 26, 2021
@pedr0luiz
Copy link

Hi, can I work on this?

@vaind vaind mentioned this issue Dec 31, 2021
2 tasks
@greenrobot-team greenrobot-team changed the title How to query for DateTime variables declared in dart class Support DateTime query conditions (or at least document current approach) Jun 1, 2022
@OHeroJ
Copy link

OHeroJ commented Aug 24, 2022

any update?

@greenrobot-team
Copy link
Member

greenrobot-team commented Aug 24, 2022

@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
Copy link

I would like to work on this

@greenrobot-team greenrobot-team removed the documentation Improvements or additions to documentation label Feb 5, 2024
@greenrobot-team greenrobot-team self-assigned this Feb 5, 2024
@greenrobot-team greenrobot-team removed the help wanted Looking for contributors (ideas, comments, code, etc) label Feb 5, 2024
@greenrobot-team greenrobot-team added this to the 2.4.1 milestone Feb 12, 2024
@greenrobot-team
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
6 participants