Custom SQL queries could be used to both insert and modify data in your database, or to make more advanced data filtering and only expose a very limited part of your data.
To add a custom database query to your database connection follow these steps:
Now you may enter the SQL query you wish to execute in your database. Please be careful as this query will be executed directly into your SQL database and may result in data loss if your query is poorly written.
Enter your query and when you are ready click on RUN QUERY to preview the result.
Using parameters / arguments
You can easily add parameters to your queries by first adding an argument to your query and then add the argument to your query. In the following example we will use an argument called name to query our table Persons for persons who have a specific name.
First, add the argument to your query by following these steps:
(The default value of an argument will be used when previewing a query and will also be used if no argument is supplied to the query).
As the final step we only need to write our SQL for this query. In this example we will select all data from the table Persons where the column named First matches the name argument:
select * from Persons where name = '%name%'
As you can see the name of the argument is written between percent signs. When the query is executed %name% will be replaced by the value provided as the argument name.
Mapping the data
By mapping the data from a query to a data model in your app you don't need to care about the names of columns returned by your query and you can continue to work with your regular data models.
To configure the mapping of the result from a query first run the query by clicking on the RUN QUERY button and then click on the DATA MAPPING tab.
To map the query data to a data model select a data model and then map the columns from your query to your model by dragging the columns from the query in the list on the left to the fields in your data model to the right.