Skip to main content
Modifying the content of the datastore is done in a Datastore Transactions. The main operations available to modify the content are add, remove, removeWhere, updateWhere. In the following examples we will use a datastore with one store with the following schema:
And the following initial content:
Note that all these examples use the recommended way to edit the datastore by using the datastore.edit() method so that the transaction is automatically started and committed (or rolled back in case of an error).

Add rows

The simplest operation to insert data into the datastore is to use the add method. This method will insert a single record into the store.
Multiple rows can be inserted at once in a store by using the addAll method.
After these two operations, the content of the store will be:

Remove rows

Remove with a key

To remove a row with a key, one can use the remove method:
Applied to the initial content, this operations will remove the row with the key 1: To remove multiple rows with keys, one can use the removeAll method.

Remove with a condition

More often than key-based removal, one may want to remove rows based on a condition. This can be done with the removeWhere method. For instance let’s remove all the products from France:

Update-where procedures

The updateWhere method allows to update the values of a field based on a condition and an update procedure. For instance, let’s update the quantity of all the products from France by multiplying it by 2. Let’s first define a condition on which the procedure will be applied:
We must then define a selection of field used to apply the procedure. Here we want to multiply the quantity by 2 so we just need the quantity fields.
Finally, we define the procedure to apply to the selected fields. The procedure is defined by implementing the IUpdateWhereProcedure interface which has 2 methods:
  • init is called once before the update is applied with the format of the selected fields and the target records. It is generally used to retrieve the index of the fields to read and write, or do any heavy initialization.
  • execute is called for each record that matches the condition. This method provides the selected data in a read-only way and the target record where the data can be written.
And we can apply the update: