In other articles, we have reviewed multiple techniques for loading data objects from persistent server-side storage. There is a list of all articles categorized by topic. In this post, we are going to review the API for loading data objects using an SQL query.
We already wrote once about SQL queries in Backendless and that post described how to test queries using Backendless Console. We recommend reading that post before reviewing the samples below.
Consider the following data tables:
There are two Person objects:
And there are three Address objects. Notice there is a one-to-many relation between Person and Address objects:
Suppose you need to load all persons who are older than 21 and live in New York City. The following query expresses exactly that condition:
Notice the query references object properties/columns to define the search expression. The addresses column in the Person table references a collection of the Address objects. Since Address has the city column, it is identified using the dot notation in the query.
The code below demonstrates the query in action:
The API is designed in a way that lets you combine query-based search with sorting, loading of relations, paging and many other data search-related features of Backendless.