You create a sequence by constructing an array of
Operation
objects. For each object, you specify the
necessary operation information using the object's
push()
method.
Each element in the array represents exactly one operation in
the store.
For example, suppose you are using a table defined like this:
CREATE TABLE myTable ( itemType STRING, itemCategory STRING, itemClass STRING, itemColor STRING, itemSize STRING, price FLOAT, inventoryCount INTEGER, PRIMARY KEY (SHARD(itemType, itemCategory, itemClass), itemColor, itemSize) )
With tables containing data like this:
Row 1:
itemType: Hats |
itemCategory: baseball |
itemClass: longbill |
itemColor: red |
itemSize: small |
price: 12.07 |
inventoryCount: 127 |
Row 2:
itemType: Hats |
itemCategory: baseball |
itemClass: longbill |
itemColor: red |
itemSize: medium |
price: 13.07 |
inventoryCount: 201 |
Row 3:
itemType: Hats |
itemCategory: baseball |
itemClass: longbill |
itemColor: red |
itemSize: large |
price: 14.07 |
inventoryCount: 39 |
And further suppose that this table has rows that require an update (such as a price and inventory refresh), and you want the update to occur in such a fashion as to ensure it is performed consistently for all the rows.
Then you can create a sequence in the following way:
var operations = []; var row = { itemType: "Hats", itemCategory: "baseball", itemClass: "longbill", itemColor: "red", itemSize: "small", price: 12.07, inventoryCount: 127 }; operations.push (new nosqldb.Types.Operation('newTable', nosqldb.Types.OperationType.PUT, row, nosqldb.Types.ReturnChoice.ALL, true, null)); row = { itemType: "Hats", itemCategory: "baseball", itemClass: "longbill", itemColor: "red", itemSize: "medium", price: 13.07, inventoryCount: 201 }; operations.push (new nosqldb.Types.Operation('newTable', nosqldb.Types.OperationType.PUT, row, nosqldb.Types.ReturnChoice.ALL, true, null)); row = { itemType: "Hats", itemCategory: "baseball", itemClass: "longbill", itemColor: "red", itemSize: "large", price: 14.07, inventoryCount: 309 }; operations.push (new nosqldb.Types.Operation('newTable', nosqldb.Types.OperationType.PUT, row, nosqldb.Types.ReturnChoice.ALL, true, null));
Note in the above example that we update only those rows that
share the same shard key. In this case, the shard key includes
the itemType
, itemCategory
,
and itemClass
fields. If the value for any
of those fields is different from the others, we could not
successfully execute the sequence.