Custom Functions (DB)

You may want to create your own functions, in addition to what is auto-generated when you connect a data source. One use of custom functions is to allow you to bulk update multiple records, based on filter criteria you define. Currently you can create custom functions for PostgreSQL, MySQL, and Cassandra data sources. 


To create a custom function for a database, first navigate to Company Settings (left navigation) → Data Sources (tab). Click on the desired data source. 


In the “Functions” section, click on “Add New”. Note you can also go to the Function Library and click “+Function” with a data source selected. 


Enter in a name for your function at the top. 


Data Source: Select the data source you want this function to act on (this is pre-selected if you create a function from a data source page). 


Action Type: There are three types of actions that your custom function can perform:

  • Insert: This will create a new data record and allow you to set values for data fields
  • Update: This will update particular record(s) using filter criteria and allowing you to set values for data fields
  • Delete: This will delete particular record(s) using filter criteria


Resource: Select the resource you want this function to act on. 


Filter by: (only appears for Update and Delete actions)

You’ll use filters to identify the particular records you want the function to act on. 

  • Attribute: Select the fields you want to filter on
  • Operator: Choose how you want to compare (options here may vary depending on the attribute’s data type) - Ex: “Greater than”, “Is equal to”, “contains” (string-only), etc. 
  • Value: Enter in a value that you want to compare to. If the value you want to compare against is not a fixed value, you can use Javascript template literals. Any Javascript expressions will become a dynamic parameter, which you'll see listed at the bottom. Later on, when you configure a component to use this function, you'll define where the values for your parameters come from. Note: there are some edge cases in how we convert to template literal, please see the dynamic parameters documentation for details.

You can click on the “X” to the right of a filter to remove a filter. 

Click “+Add filter” to add another filter. Each filter is an “AND” statement - records must pass all filter criteria in order to be acted upon. 


Set: (only appears for Insert and Update actions)

This allows you to set new values for the fields you specify.

  • Attribute: Select the field that you want to set a new value for
  • Value: Enter in a value that you want to set this field to. Usually this will not be a fixed value, so you should use Javascript template literals to create a dynamic parameter (your Javascript expressions become dynamic parameters, listed at the bottom). Note: there are some edge cases in how we convert to template literal, please see the dynamic parameters documentation for details.


Allow multiple records to be updated: This checkbox provides an additional safety net in case you do not intend for this function to perform bulk update actions. If this is unchecked, the function will fail if it attempts to act on more than one record. 


Hit “Apply” to finish creating your function. It’s now ready for you to use in a Space component. 


Note: You’ll configure how values for your dynamic parameters are populated when you use this function in a component.