NESTEDSESSION operator
The NESTEDSESSION operator creates an action that executes the other action in a nested session.
Syntax
NESTEDSESSION [SINGLE] action
Description
The NESTEDSESSION operator creates an action that executes the other action in a nested session. Applying changes inside the nested session copies them back into the surrounding session rather than committing to the database. If the operator is executed during an apply transaction of the current session, no nested session is created — the executed action is deferred and executed in the current session inside the same transaction.
Parameters
-
SINGLEOptional keyword. If the
NESTEDSESSIONis itself called inside an apply transaction, this flag is propagated to the inner action: changes to stored properties used by it are flushed incrementally during the transaction instead of being batched at the end of the apply. -
actionA context-dependent action operator that defines an action to be executed in the nested session.
Examples
testNestedSession () {
NESTEDSESSION {
name(Sku s) <- 'aaa';
// in fact, the changes will not be applied to the database, but to the "upper" session
APPLY;
}
MESSAGE (GROUP SUM 1 IF name(Sku s) == 'aaa'); // returns all rows
CANCEL;
// returns NULL if there was no Sku named aaa in the database before
MESSAGE (GROUP SUM 1 IF name(Sku s) == 'aaa');
}
FORM sku
OBJECTS s = Sku PANEL
PROPERTIES(s) id, name
;
newNestedSession() {
NESTEDSESSION {
NEW s = Sku {
// shows the form, but any changes in it will not be applied to the database,
// but will be saved in the "upper session" session
SHOW sku OBJECTS s = s;
}
}
}
// SINGLE — only meaningful when NESTEDSESSION is itself executed inside an apply transaction
recalcNested () {
APPLY {
NESTEDSESSION SINGLE {
// changes here are flushed incrementally during the outer apply
name(Sku s) <- 'recalculated';
}
}
}