Update statement
You can use operators @
, @?
, @*
, @+
to specify cardinality, like for the at-operator. A run-time error occurs if
the number of updated records doesn't match the cardinality.
update user @ { .name == 'Bob' } ( company = 'Microsoft' ); // exactly one
update user @? { .name == 'Bob' } ( deleted = true ); // zero or one
update user @* { .company.name == 'Bad Company' } ( salary -= 1000 ); // any number
Can change only mutable
attributes.
You can match entity attributes implicitly by name or type:
val company = 'Microsoft';
update user @ { .name == 'Bob' } ( company );
Using multiple entities with aliases. The first entity is the one that's updated. You can use other entities in the where-part:
update (u: user, c: company) @ { u.xyz == c.xyz, u.name == 'Bob', c.name == 'Google' } ( city = 'Seattle' );
Can specify an arbitrary expression returning a entity, a nullable entity, or a collection of entities:
val u = user @? { .name == 'Bob' };
update u ( salary += 5000 );
You can modify a single attribute by a regular assignment syntax:
val u = user @ { .name == 'Bob' };
u.salary += 5000;