順序の作成
順序を作成するには、Operation
オブジェクトの配列を作成します。オブジェクトごとに、そのオブジェクトのpush()
メソッドを使用して必要な操作情報を指定します。配列の各要素は、ストアでの1つの操作を表します。
たとえば、次のように定義された表を使用しているとします。
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)
)
次のようなデータを含む表:
-
行1:
-
itemType: Hats
-
itemCategory: baseball
-
itemClass: longbill
-
itemColor: red
-
itemSize: small
-
price: 12.07
-
inventoryCount: 127
-
-
行2:
-
itemType: Hats
-
itemCategory: baseball
-
itemClass: longbill
-
itemColor: red
-
itemSize: medium
-
price: 13.07
-
inventoryCount: 201
-
-
行3:
-
itemType: Hats
-
itemCategory: baseball
-
itemClass: longbill
-
itemColor: red
-
itemSize: large
-
price: 14.07
-
inventoryCount: 39
-
さらに、この表には更新が必要な行(価格、在庫更新など)があり、すべての行について一貫して更新が行われるようにするとします。
次のように順序を作成します。
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));
前述の例では、同じシャード・キーを共有する行のみを更新することに注意してください。この場合、シャード・キーにはitemType
、itemCategory
およびitemClass
フィールドが含まれます。これらのフィールドの値が他のフィールドと異なる場合、順序は正常に実行されません。