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.
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.
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.
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 …
- 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.
- Add a Form with fields for each of the bindings, except for the id which will come from the URL ID binding.
- 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.
- Finally map your form field bindings to your custom query bindings like so:
Click Save to finish.
Updated 3 months ago