Start a new topic

How to concatenate queries?

Hello 

The answer to my question might be pretty simple, I just don't get it. 

I was going through the Data Store manual of HTML5/Javascript API. It looks all very promising! There is one aspect I have to cover and couldn't find a clear solution: Dynamic queries. 

Of course I can set values dynamically inside a query but can I also "join" a query to another query dynamically?

Here's an example: Let's assume I have vine brands in a Kinvey collection. The user/app can filter by the name of the vine (f.e. "Primitivo"). This would be a single and simple query. Now let's assume there is a column "country" in that collection and the user can also filter for that one. He sets the filter to name: "Primitivo" and country to "Italy". Now I have to generate the query dinamically like: name = "Primitivo" AND country "Italy". This can't be done in a single query so I need to join/attach the second query to the first query DYNAMICALLY. Is that possible? If so, what way would you recommend to do that?

Regards

1 Comment

Hi Tayger,


To add more than one filter you simply add more operators, so the query would look like this:


var query = new Kinvey.Query();
query.equalTo("name", Primitivo").equalTo("country", "Italy");


or if you need to add the second filter at a later stage:


var query = new Kinvey.Query();
query.equalTo("name", Primitivo");

query.equalTo("country", "Italy");


Let me know if this has helped.

Martin

Login or Signup to post a comment