本文介紹如何通過 Node.js SDK 讀取Table Store資料表的單行資料。
注意事項
讀取資料時需要提供包含自增主鍵列值在內的完整主索引值。
前提條件
方法說明
getRow: function getRow(params, callback)範例程式碼
以下範例程式碼讀取了主索引值為 row1 的單行資料。
var params = {
tableName: 'test_table',
primaryKey: [{ 'id': 'row1' }]
};
client.getRow(params, function (err, data) {
if (err) {
console.log('Get row failed with error: ', err);
return;
}
console.log('Read CU Cost: ', data.consumed.capacityUnit.read);
console.log('Write CU Cost: ', data.consumed.capacityUnit.write);
console.log('Row Data: ', JSON.stringify(data.row));
});設定讀取的資料版本範圍,結果只返回版本範圍內的資料。
params.timeRange = { startTime: (Date.now() - 86400 * 1000).toString(), endTime: Date.now().toString() }指定讀取的屬性列。
params.columnsToGet = ['col2']