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 theadd method.
This method will insert a single record into the store.
addAll method.
Remove rows
Remove with a key
To remove a row with a key, one can use theremove method:
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 theremoveWhere method.
For instance let’s remove all the products from France:
Update-where procedures
TheupdateWhere 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:
IUpdateWhereProcedure interface which has 2 methods:
initis 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.executeis 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.