DB Triggers
Bind a function to a database collection event. The function fires automatically whenever a matching record is created, updated, or deleted — no polling, no glue code.
Event types
db.record.createdFires after a new record is successfully inserted into the collectiondb.record.updatedFires after an existing record is updateddb.record.deletedFires after a record is deletedCreating a trigger
Navigate to your project → Functions → select a function → Triggers tab → Add Trigger. Set the event type and collection name.
Example: fire send-welcome-email when a record is created in users:
Function
send-welcome-email
Event
db.record.created
Collection
users
Accessing trigger data in the function
When a trigger fires, ctx.request contains the event details and the record payload:
export async function handler(ctx) {
// ctx.request.event — 'db.record.created'
// ctx.request.collection — 'users'
// ctx.request.payload — the full record that was mutated
const { event, collection, payload } = ctx.request;
if (event === 'db.record.created') {
const newUser = payload;
const email = newUser.data?.email;
const name = newUser.data?.name;
// Send welcome email...
const apiKey = Deno.env.get('SENDGRID_KEY');
await fetch('https://api.sendgrid.com/v3/mail/send', {
method: 'POST',
headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
to: [{ email }],
from: { email: 'hello@myapp.com' },
subject: 'Welcome!',
text: `Hi ${name}, welcome to MyApp!`,
}),
});
}
return { ok: true };
}Trigger observability
Each trigger row in the dashboard shows a 24-hour success rate with a colour-coded progress bar — green (≥80%), amber (50–80%), red (<50%). Triggers with a failure rate above 50% show a "Failing frequently" warning badge.