How do I write custom SQL Queries? | Aquro Help Center

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:

  1. Make sure that you are inside Aquro App Studio
  2. Expand the Backend Service folder in the treeview to the left
  3. Expand the Database Connections folder
  4. Click on the database connection that you want to configure
  5. Click on the QUERIES tab
  6. Click on ADD QUERY
  7. Give your query a name
  8. Click on SAVE

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:

  1. Go to the ARGUMENTS tab
  2. Click on ADD
  3. Type name as the argument
  4. Type John as the default value

(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.