Parameters
Query your database like a Pro
Parameters
Published pipes support Jinja2 syntax for parameter templating.
Parameters help you write dynamic queries and provide more control over the results your queries return. In dashboards, you can prompt users for filter values and use those filters to query the data, returning only the relevant results.
Example of a parameterized endpoint:
Data Types
Airfold allows the following data types for the value of the parameters. Supported data types:
- String
- Int
- Float
- Boolean
- Date
- Datetime
To use the parameters in you SQL, just add the parameter name inside two curly braces like this {{ params }}
Example: SELECT * FROM t LIMIT {{ limit }}
The internal Jinja engine handles parameter substitution automatically. No need to escape parameters - WHERE name = {{ name }}
works correctly for string values.
Endpoint calls
All parameters are passed as query strings in the HTTP API.
For additional syntax options, refer to the Jinja2 documentation.
More Examples
For additional statement options, refer to the Jinja2 documentation.
UI
Create the Draft Pipe
Follow normal steps you would follow to create a draft pipe (refer Draft Pipes), make sure the query has the parameters enclosed in two curly braces like this: {{ params }}
Add parameters
Go to the three dots on top right corner and select “Add Parameter” and then select the Parameter Name, Data Type and and Default value.
Run the query
Once all the parameters are defined, you can just run the command and the query runs with the default values.
You can set the values for parameters just by assigning the value to the params.
CLI
Edit YAML file
Once the query is ready simply add {{ params }}
where required and set the publish
property
Add Params
To define the parameters in the SQL query, we need to add the params
property and define parameter name, type and default value.
Push
Once the config file is ready, you can use the push command to push the changes to your workspace.
Push this update by running:
Params can be used in endpoints and draft pipes.
Params cannot be used in materialized pipes.