Skip to content

Creating Database Queries

Original guide · All levels · Server Connect

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 loca

Right click API and select Add API Action:

Section titled “Right click API and select Add API Action:”

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

Section titled “Give it a name, we call our API Action - records:”

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.

Right click steps:

Open Database Actions and select Database Query:

Section titled “Open Database Actions and select Database Query:”

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:

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

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:

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

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

Section titled “Here you can setup your query conditions, just select a column:”

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:

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

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

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:

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

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

Section titled “Select the column you want to sort the query by and add it to the sort list:”

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

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

Click OK in order to apply the query options:

Section titled “Click OK in order to apply the query options:”

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

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

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

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

The results will be loaded in your browser:

Section titled “The results will be loaded in your browser:”