Using QueryLines to filter your BaaS data

Posted by on in Cloud

Today I thought I would do a quick tutorial on how you can filter your BaaS data using TBackendQuery's QueryLines feature. This allows you to filter your cloud data using regular expressions. For more information on regular expressions, click here.

If you have never used a Backend-as-a-Service provider like Kinvey, Parse or App42 and are looking to build BaaS enabled apps with 10 Seattle, I would recommend having a look at my tutorial series: http://blogs.embarcadero.com/sarinadupont/category/baas-tutorials/

I created some sample data in a Kinvey data collection that consists of Recipe Categories and Recipe Titles. For more info on this demo, please see: http://blogs.embarcadero.com/sarinadupont/2014/10/21/displaying-cloud-based-data-with-a-to-z-listview-headers/

Data1

Using regular expressions, I am able to filter my results. Select TBackendQuery's QueryLines field in the Object Inspector and click on "...". Then type in your regular expression and click OK. Right-click on the BackendQuery component on your form and select "Execute". You are now able to see the filtered results at design time.

QueryLines1

Below are some sample queries.

Sample Query 1:

query={"$or":[{"Category":"Mexican"}, {"RecipeTitle":{"$regex": "^Tamales"}}]}  //search for recipes that are either in the Mexican food category or begin with "Tamales" in the title
limit=2    // limit number of results to just 2
skip=1    //skip the first result / exclude it from the list
sort={"RecipeTitle":-1}   //display recipe titles in descending (Z-A) order

query={"$or":[{"Category":"Mexican"}, {"RecipeTitle":{"$regex": "^Tamales"}}]}
limit=2
skip=1
sort={"RecipeTitle":-1}

 

Filtered1

 

Sample Query 2:

query={"RecipeTitle":{"$regex": "^[SM]"}}  // recipe title starts with either "S" or  "M"
sort={"RecipeTitle":-1}    // display recipe titles in descending (Z-A) order

query={"RecipeTitle":{"$regex": "^[SM]"}}
sort={"RecipeTitle":-1}

Filtered2

 

Sample Query 3:

query={"RecipeTitle":{"$regex": "^.*Salmon"}}  // recipe title includes the word "Salmon"
sort={"RecipeTitle":-1}   // display recipe titles in descending (Z-A) order

query={"RecipeTitle":{"$regex": "^[SM]"}}
sort={"RecipeTitle":-1}

 

Filtered3



About
Gold User, Rank: 5, Points: 558
Senior Product Manager, RAD Studio

Comments

  • Page :
  • 1

Check out more tips and tricks in this development video: