Skip to content

Triggers

You can add triggers to a table in its definition with the trigger function:

ts
const users = table({
  columns: {
    id: integer(),
    updatedAt: timestamp().default(sql`now()`),
    updatedAtTwo: timestamp().default(sql`now()`),
  },
  triggers: [ 
    trigger({ 
      fireWhen: "before", 
      events: ["update"], 
      forEach: "row", 
      function: { 
        name: "moddatetime", 
        args: [sql.ref("updatedAt")], 
      }, 
    }) 
  ], 
});

You can read more about the different options to configure a trigger in TriggerOptions.

For the official PostgreSQL documentation on triggers visit CREATE TRIGGER