Discuss

Creating Database Queries

On this page
After you created your Database Connection, now it's time to setup a Database Query. The first thing we need to do is to create a new API Action (also known as Server Action). The API Actions are located under the API section of the Server Actions panel:

Creating an API Action

Screenshot_1|690x431

Right click API and select Add API Action:

Screenshot_2|690x431

Give it a name, we call our API Action - records:

Screenshot_3|690x431

You can see the API Action, loaded in a separate tab. There you will find its steps and that's where we define all the server side logic that we need.

Creating a Database Query

Right click steps:

Screenshot_4|690x431

Open Database Actions and select Database Query:

Screenshot_5|690x431

Basic Options

Your existing database connection will be automatically selected in the dropdown. If you have more than one database connections defined, make sure select the one you need:

Screenshot_6|690x431

Click the Query Builder button:

Screenshot_7|690x431

Selecting Tables and Columns

Open the database tables drop-down and select a table:

Screenshot_8|690x431

Screenshot_9|690x431

If you want to add all the table columns to the query, you don't have to do anything else - the table is already added. If you want to add specific columns to the query, just select them (using Ctrl + click / Cmd + click) and click the add button:

Screenshot_10|690x431

Query Conditions

You can add conditions/filters to your database query. Click the Conditions tab:

Screenshot_11|690x431

Here you can setup your query conditions, just select a column:

Screenshot_12|690x431

Then select a condition:

Screenshot_13|690x431

And add a value for the condition. This can be a dynamic value, or a static one. In our example we add a static value:

Screenshot_14|690x431

You can add multiple conditions or groups of conditions to your queries. Click the Add New Condition buton:

Screenshot_15|690x431

Just select how to combine these conditions - using the AND or OR operators. Clicking the operator toggles it from AND to OR. Selecting AND will only return records which match both conditions, while using OR will return any records matching any of the conditions. We set the operator to AND:

Screenshot_16|690x431

And then we setup our second condition:

Screenshot_17|690x431

Sorting Query Results

You can add sorting options to your query, select the Sorting tab:

Screenshot_18|690x431

Select the column you want to sort the query by and add it to the sort list:

Screenshot_19|690x431

Then just select the sort order:

Screenshot_20|690x431

You can see the generated code for the database query, which you just set up:

Screenshot_21|690x431

Click OK in order to apply the query options:

Screenshot_22|690x431

Previewing the Results

Make sure the Output option is enabled. When disabled, the query results won't be displayed on the freont-end:

Screenshot_24|690x431

Do not forget to save your server action by using the Ctrl + S / Cmd + S shortcut:

Screenshot_23|690x431

You can preview your query results by selecting the server action and then clicking the Open in Browser button:

Screenshot_25|690x431

The results will be loaded in your browser:

Screenshot_26|690x431