This function enforces ThingsDB to create a change.
When using a stored closure which requires a change it might not be possible for ThingsDB
to detect the change requirement before evaluation the query. In this case it is required to use wse() to enforce a change.
Function wse() might both wrap a statement and be called without arguments.
Since version 1.10.1 it is possible to write f(..)! instead of wse(f(..)) making the function call obsolete.
This function generates a change.
wse([statement])
| Argument | Type | Description |
|---|---|---|
| statement | any (optional) | Statement or block to wrap. |
Return value of the given statement or nil.
This code shows an example usage for wse():
// Suppose we have a closure with side-effects
.take_license = || .licenses -= 1;
// And we have some initial licenses
.licenses = 99;
Here we need wse() to enforce a change:
// Without wse() no change would be created and thus this would raise an error
wse(.take_license());
// Return the number of licenses left
.licenses;
Return value in JSON format
98
Or, we could also use the shorter
(..)!syntax:
// The `!` after the function tells ThingsDB to use wse(..)
.take_license()!;
// Return the number of licenses left
.licenses;
Return value in JSON format
97