Data

Custom queries

A custom query is a saved read or write over one of your custom tables. You build it visually, and your functions run it whenever they need data.

How queries work

Each query belongs to one target table and has one of three types: SELECT reads rows, INSERT adds a row, and UPDATE changes rows.

A query never runs by itself. A function runs it with the Execute Query node, and a scheduled trigger can run a function once for every row a SELECT query returns.

There is no DELETE query. See the last section for how to remove rows safely.

Create a query

1

Open Custom Queries

In the admin panel, go to Database, then Custom Queries.

2

Click Build New Query

Fill in Query Name, choose the Query Type (SELECT, CREATE (INSERT) or UPDATE) and pick the Target Table.

3

Add parameters

Click Edit Query and open the Parameters tab. Add every value the query will receive when it runs.

4

Build it

Open the Query Builder tab, define the query, then click Save Compiled Query.

5

Secure it

Open the Security tab and choose who may run it.

The target table can be changed later in the General configuration tab.

SELECT queries

JOIN Relations

Bring in columns from another table with a Left, Inner or Right Join, an optional alias, and the columns that match.

SELECT Columns

The columns to return. Leave it empty to return every column of the target table.

Aggregates and GROUP BY

count, sum, avg, min or max over a column, with an alias, grouped by the columns you choose.

WHERE Conditions

Filters built from a column, an operator (=, !=, >, <, >=, <=, like, in) and a fixed value or a parameter. Combine them in AND / OR groups.

ORDER BY & LIMIT

Sort rules, applied in order, and the maximum number of rows to return.

If you choose specific columns, include uuid. Links, detail pages and later queries identify a row by its uuid.

In a function, a SELECT query returns one output named results: a list of rows.

INSERT queries

In INSERT Value Bindings, bind each column of the target table to a fixed value or to a parameter. The uuid is generated for you.

In a function, an INSERT query returns the new row's id and uuid.

UPDATE queries

Values to write

Each column is written from a parameter or a fixed value. A parameter that does not arrive leaves its column as it is.

Which rows to change

Required. Every parameter used here must be marked Required, so a missing value can never widen the change to the whole table.

Most rows one run may change

If the conditions match more rows than this, the run fails and nothing changes. Use 1 when you mean one row.

id, uuid and the created and updated dates can never be written. In a function, an UPDATE query returns count (rows changed) and uuids (their uuids).

Removing rows: use a status column

Queries cannot delete rows. Mark rows as removed instead, which also keeps a history you can restore.

1

Add a status column

A String column with a default value such as 'active'.

2

Write an UPDATE query

It sets status to deleted for the row whose uuid it receives.

3

Filter your reads

Add a WHERE condition status = active to every SELECT query that lists rows.