Database Steps

Steps for querying, inserting, updating, deleting, and aggregating database records.

Database Steps

Database steps interact with your project's PostgreSQL database. They provide both raw SQL access and structured operations that generate SQL for you.

Database Query

Executes a raw SQL query. Use this for complex queries that the structured steps cannot express.

Query: SELECT * FROM products WHERE price > $1 AND category = $2
Parameters: [29.99, 'electronics']
Assign To: products

Always use parameterized queries instead of string concatenation to prevent SQL injection.

Database Insert

Inserts one or more rows into a table.

Table: users
Data: { name: input.name, email: input.email }
Returning: *
Assign To: newUser

Database Update

Updates rows in a table matching the given conditions.

Table: users
Data: { name: input.name }
Where: { id: vars.userId }
Returning: *
Assign To: updatedUser

Database Delete

Deletes rows from a table matching the given conditions.

Table: sessions
Where: { expires_at: { $lt: 'NOW()' } }

Database Select

Retrieves rows from a table with structured filtering, sorting, and pagination.

Table: products
Columns: id, name, price
Where: { category: 'electronics' }
Order By: price ASC
Limit: 20
Offset: 0
Assign To: products

Find One

Retrieves a single row matching the conditions. Returns null if no match is found.

Table: users
Where: { email: input.email }
Assign To: user

Find Many

Retrieves all rows matching the conditions.

Table: orders
Where: { user_id: vars.userId, status: 'pending' }
Assign To: pendingOrders

Count

Returns the number of rows matching the conditions.

Table: orders
Where: { status: 'completed' }
Assign To: completedCount

Aggregate

Performs aggregation operations on a table (SUM, AVG, MIN, MAX, COUNT).

Function: SUM
Column: amount
Table: orders
Where: { status: 'completed' }
Group By: category
Assign To: salesByCategory
The SQL query to execute. Use `$1`, `$2`, etc. for parameterized values.
Array of values for parameterized placeholders.
Variable name to store the query result.
The target table name.
An object (single row) or array of objects (multiple rows) to insert.
Columns to return from the inserted rows (e.g., `*` or `id`).
Variable name to store the returned data.
The target table name.
Key-value pairs of columns to update.
Conditions to match rows for updating.
Columns to return from the updated rows.
Variable name to store the returned data.
The target table name.
Conditions to match rows for deletion.
Columns to return from the deleted rows.
Variable name to store the returned data.
The table to query.
Columns to select. Defaults to `*`.
Filter conditions.
Column and direction for sorting (e.g., `created_at DESC`).
Maximum number of rows to return.
Number of rows to skip.
Variable name to store the result.
The table to query.
Filter conditions.
Variable name to store the result.
The table to query.
Filter conditions.
Variable name to store the result array.
The table to query.
Filter conditions.
Variable name to store the count.
The table to query.
The aggregation function: `SUM`, `AVG`, `MIN`, `MAX`, or `COUNT`.
The column to aggregate.
Filter conditions.
Column to group results by.
Variable name to store the result.
Steps Reference
/reference/steps
Browse all step categories
Database Overview
/database
Design tables and relationships
Variable Steps
/reference/steps/variables
Store query results in variables