Database Triggers

Execute functions automatically when rows are inserted, updated, or deleted on your Spala tables.

Database Triggers

Database triggers run backend logic when project data changes. Use them when the action should happen no matter which endpoint, task, or agent changed the data.

Trigger Events

Each trigger is configured for a table and one or more events:

| Event | When It Fires | Common Use |
|---|---|---|
| Insert | A new row is created | Send welcome emails, create related records |
| Update | An existing row changes | Audit changes, sync external systems |
| Delete | A row is removed | Cleanup related data, notify systems |

Triggers can run synchronously or asynchronously depending on the setting in the editor.

Create A Database Trigger

Open Triggers from the sidebar

Click Create Trigger

Select the target table

Choose insert, update, delete, or multiple events

Choose whether the trigger runs sync or async

Build the trigger function with Gherkin, Visual, Split, or Code view

Save and enable the trigger

Trigger Variables

Inside the trigger function, Spala provides variables for the changed row:

Examples

Audit log

// Update on users
// Step 1: Insert audit row with trigger.oldRecord and trigger.newRecord
// Step 2: Return success

Welcome email

// Insert on users
// Step 1: Send email to trigger.newRecord.email
// Step 2: Log delivery result

Cleanup

// Delete on projects
// Step 1: Remove related temporary records
// Step 2: Notify operations channel

Use endpoints for request validation

If you need to reject invalid client input before a write, put that validation in the endpoint function that performs the write. Use database triggers for automatic follow-up work around data changes.

The operation type: INSERT, UPDATE, or DELETE
The new row data, available on insert and update
The previous row data, available on update and delete
The table/model ID that fired the trigger
Triggers Overview
/triggers
Create trigger automations from the current builder
Database Steps
/reference/steps/database
Reference for database query steps used in trigger functions
Project Agents
/features/project-agents
Build richer automations with multiple trigger types