Creating and removing rows
To create a row in a table, call the get() action on the table you want to add the row to. The action declaration is as follows:
action get(string key) returns Row
The Table.get() action returns a Row event that represents the row in the table that has the specified key. If there is no row with the specified key, this action returns a Row event that represents a row that contains default values. A call to the Row.inTable() action returns false.
For example:
boolean done := false;
integer n := -1;
while not done {
Row row := tbl.get("example-row");
n := row.getInteger("times_run");
row.setInteger("times_run", n+1);
done := row.tryCommit();
}
send Result(
"This example has been run " +n.toString() +" time(s) before")
to "output";
To remove a row from a table, call the Table.remove() action on the table that contains the row. The action declaration is as follows:
action remove(string key)
The Table.remove() action removes the row with the specified key from the table. If the row does not exist, this action does nothing.
It is also possible to remove a row transactionally, by calling Table.get() and then Row.remove() and Row.commit(). This strategy lets you check the row's state before removal. The Row.commit() action fails if the shared, in-memory row has been updated since the Table.get(). action
In some circumstances, using Row.remove() is essential to guarantee correctness. For example, when decrementing a usage counter in the row and removing the row when the count reaches zero. Otherwise, another correlator context might re-increment the count between it reaching zero and the row being removed.