Custom queries

Budibase supports the ability to write custom queries. These queries can be really useful if you want to perform advanced joins or server-side filtering.

To write custom queries, head over to your Datasource, and scroll down until you find the queries section. Click the Add Query button, which will guide you to a form to configure your query.


Budibase DB

The internal Budibase DB is a unique datasource that does not support custom queries.
It does however support Views

An example would be to query all pet names from a specific owner. For this demonstration we've used a custom binding to insert the ownerID into the query.

Using query bindings

You can also override the default binding values.

When you use the query as a data source for your provider, you can click on the cog icon.

This will show a query bindings drawer where you can add a dynamic value to override the default.

Editing custom queries

A list of your custom queries can be found underneath the associated data sources. Click on the query to be able to edit the config.

It is also possible to delete queries that are no longer needed, or duplicate queries, which can useful in cases where an additional query only requires minor changes.

To access these options, hover over the query and click the …

Tutorial: Posting form data to a custom query

  1. Add your query to a datasource, in this example we'll use PostgreSQL. Add your bindings with some optional defaults, and then reference them within your query.

  1. Add a Form with fields for each of the bindings, except for the id which will come from the URL ID binding.

  1. Define actions for the 'Submit' button. Choose the Execute Query action and pick PostgreSQL as the datasource. You should now be able to see and select your custom query.

  1. Finally map your form field bindings to your custom query bindings like so:

Click Save to finish.