Read a single row from a Tablestore table by calling `getRow` in the Node.js SDK. Specify primary key values, version ranges, and column filters to control the returned data.
Notes
You must provide the complete primary key value to read data. This value includes the value of the auto-increment primary key column.
Prerequisites
Method
getRow: function getRow(params, callback)
Examples
The following sample code shows how to read a single row of data where the primary key value is 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));
});
-
Set a time range for the data versions to read. Only data within the specified time range is returned.
params.timeRange = { startTime: (Date.now() - 86400 * 1000).toString(), endTime: Date.now().toString() } -
Specify the attribute columns to read.
params.columnsToGet = ['col2']