Discuss

Creating Custom SQL Queries

On this page

You can use the Custom Query component in Server Connect in order to manually add a custom SQL query. You can define your own parameters, edit the schema and metadata and preview the results.


Creating Custom SQL Queries

You already know how to create a database connection in Wappler, so we won't show this again. In your server action with the database connection, right click the database connection step:

Screenshot_4|690x400

Open Database Actions and select Database Custom Query:

Screenshot_5|690x400

Click the Build Query button:

Screenshot_6|690x400

In the Custom Query dialog, you will see your database tables listed on the left. In the SQL Editor area you can write your own SQL Statements. Code autocomplete options are available, so it makes it easier to write your queries there:

Screenshot_7|690x400

You can also directly paste your statements, generated by any other software there and then click the Run button to preview the results:

Screenshot_8|690x400

The query results tab will automatically show the results:

Screenshot_9|690x400

Open the Schema tab, to edit the schema that will later be available in the Dynamic Data Picker on your pages. The schema is automatically populated with the results from your custom SQL query. You can edit the data type or remove any fields you don't want to use:

Screenshot_10|690x400

You can add Parameters to use with your custom SQL Statements. Just open the Parameters tab:

Screenshot_11|690x400

Then click the Add New Parameter button:

Screenshot_12|690x400

Add a name for your parameter and assign a dynamic value for it:

Screenshot_13|690x400

Select your value using the dynamic data picker dialog:

Screenshot_14|690x400

You can also add some test value, to test your query with:

Screenshot_15|690x400

Click the OK button, when you are done:

Screenshot_16|690x400

Save your server action and you are done:

Screenshot_17|690x400

Now you can use your custom query results on the page, just as you do with any other normal query.