prorm API Reference
    Preparing search index...

    Interface TriggerDecoratorOptions<T>

    @Trigger class decorator — declare a database trigger on a model class.

    Stores trigger metadata using plain class properties (no reflect-metadata dependency) consistent with the rest of this decorator suite.

    Example:

      @Trigger({
    name: 'trg_users_audit',
    timing: 'AFTER',
    event: 'INSERT',
    body: `INSERT INTO audit_log(action, ts) VALUES ('INSERT', NOW())`,
    forEach: 'ROW',
    })
    class User extends Model { ... }

    // Retrieve trigger definitions:
    const triggers = getTriggers(User);

    // Generate DDL:
    const sql = buildCreateTriggerSQL('users', triggers[0], 'mysql');
    interface TriggerDecoratorOptions<T = Record<string, unknown>> {
        name: string;
        timing: "BEFORE" | "AFTER" | "INSTEAD OF" | TriggerTiming;
        event: "INSERT" | "UPDATE" | "DELETE" | "TRUNCATE" | TriggerEvent;
        body: TriggerBody;
        forEach?: "ROW" | "STATEMENT" | TriggerForEach;
        table?: TriggerTable;
        when?: string | WhereOptions;
        updateOf?: string[] | (keyof T & string)[];
    }

    Type Parameters

    • T = Record<string, unknown>
    Index
    name: string

    The trigger name in the database.

    timing: "BEFORE" | "AFTER" | "INSTEAD OF" | TriggerTiming

    When the trigger fires relative to the DML event. Prefer TriggerTiming: TriggerTiming.Before.

    event: "INSERT" | "UPDATE" | "DELETE" | "TRUNCATE" | TriggerEvent

    The DML event that activates the trigger. Prefer TriggerEvent: TriggerEvent.Update.

    What the trigger does — actions rather than SQL:

    body: { set: { updatedAt: fn('CURRENT_TIMESTAMP') } }
    body: [{ insertInto: AuditLog, values: { userId: NEW('id') } }]

    A raw SQL string is still accepted for anything the actions do not cover.

    forEach?: "ROW" | "STATEMENT" | TriggerForEach

    Row-level or statement-level (default: row). Prefer TriggerForEach: TriggerForEach.Statement.

    table?: TriggerTable

    The table the trigger fires on: a name or the model itself. Defaults to the table of the model the decorator is applied to.

    when?: string | WhereOptions

    Guard, in the usual where syntax, with NEW() / OLD() for the rows: when: { status: { ne: OLD('status') } }.

    updateOf?: string[] | (keyof T & string)[]

    Columns an UPDATE trigger watches. PostgreSQL and Oracle.