Light
Dark
System
v2latest
v3dev
v2latest
v1

TriggersAdded in v3.0

This section describes the SDL declarations pertaining to triggers (added in 3.0).

Declare a trigger that inserts a Log object for each new User object:

Copy
type User {
  required name: str;

  trigger log_insert after insert for each do (
    insert Log {
      action := 'insert',
      target_name := __new__.name
    }
  );
}

Define a new trigger corresponding to the more explicit DDL commands (added in 3.0).

type type-name "{"
  trigger name
  after
    {insert | update | delete} [, ...]
    for {each | all}
    do expr
"}"

This declaration defines a new trigger with the following options:

type-name

The name (optionally module-qualified) of the type to be triggered on.

name

The name of the trigger.

insert | update | delete [, ...]

The query type (or types) to trigger on. Separate multiple values with commas to invoke the same trigger for multiple types of queries.

each

The expression will be evaluated once per modified object. __new__ and __old__ in this context within the expression will refer to a single object.

all

The expression will be evaluted once for the entire query, even if multiple objects were modified. __new__ and __old__ in this context within the expression refer to sets of the modified objects.

expr

The expression to be evaluated when the trigger is invoked.

The trigger name must be distinct from that of any existing trigger on the same type.

See also

Schema > Triggers (added in 3.0)

DDL > Triggers (added in 3.0)

Introspection > Triggers (added in 3.0)

Light
Dark
System