本文介紹如何使用 Node.js SDK 刪除Table Store資料表的單行資料。
前提條件
方法說明
deleteRow: function deleteRow(params, callback)範例程式碼
以下範例程式碼用於刪除 test_table 表中主索引值為 row1 的行資料。
var params = {
tableName: 'test_table',
// 主鍵資訊
primaryKey: [{ 'id': 'row1' }],
// 刪除資料時必須配置刪除條件 (TableStore.RowExistenceExpectation.IGNORE,表示不做行存在性判斷)
condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null)
};
client.deleteRow(params, function (err, data) {
if (err) {
console.log('Delete row failed with error: ', err);
return;
}
console.log('RequestId: ', data.RequestId);
console.log('Read CU Cost: ', data.consumed.capacityUnit.read);
console.log('Write CU Cost: ', data.consumed.capacityUnit.write);
});