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 collection
db.record.updatedFires after an existing record is updated
db.record.deletedFires after a record is deleted

Creating 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:

send-welcome-email/index.tsTypeScript
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.

Success ratePercentage of executions that returned without error in the last 24h
Run countTotal number of trigger executions in the last 24h
Failure countNumber of failed executions in the last 24h

Trigger execution is asynchronous

DB triggers fire in a background goroutine — they do not block the database operation that caused them. If the trigger fails, it is retried automatically. See Retries & DLQ.