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

sqlite group by equivalent #422

Closed
hamidmalek opened this issue Apr 9, 2018 · 5 comments
Closed

sqlite group by equivalent #422

hamidmalek opened this issue Apr 9, 2018 · 5 comments
Labels
more info required Further information is requested

Comments

@hamidmalek
Copy link

Hello there,
I'm new to Objectbox and just switched from old fashioned SQLite. I tried to convert my old queries and rewrite them in Objectbox queries, but there is query that I don't know how to convert.

SELECT FOOD_ID , COUNT(FOOD_ID) AS cnt FROM TABLE_FOOD_LOG GROUP BY FOOD_ID HAVING cnt > 2 ORDER BY cnt DESC LIMIT 20

To clarify, there are Food and FoodLog tables, user adds logs from the Food objects as she/he consumes them, and FoodLog object has a reference in the Food objects, So I want to extract the most used foods by user.

@greenrobot-team
Copy link
Member

This is not directly possible in ObjectBox. However, you can try to use property queries or maybe a query filter. In general, have a look at the Queries docs. -ut

@greenrobot-team greenrobot-team self-assigned this Apr 9, 2018
@hamidmalek
Copy link
Author

Can any expert tell me the best approach to implement this code?

@navidei
Copy link

navidei commented Apr 10, 2018

Counting objects with specific properties (like this query of @hamidmalek with additional group by command) is a useful feature which would be appreciated if it's implemented in this great library. We have decided to switch from sqlite to this ORM in our team and lack of this feature made us to do so in java.

@greenrobot
Copy link
Member

@hamidmalek You have to do two steps. First get all food_id values using a property query. Then do the grouping in Java.

We're open for API suggestions how to support this.

@greenrobot-team greenrobot-team removed their assignment Apr 17, 2018
@greenrobot-team greenrobot-team added the more info required Further information is requested label Apr 17, 2018
@greenrobot-team
Copy link
Member

Closing this issue due to inactivity. 💤 Feel free to re-open with more details or submit a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info required Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants