Update a single row in a Tablestore table by calling `updateRow` in the Node.js SDK. Modify attribute column values, add attribute columns, delete a specific version, or delete an entire attribute column.
Prerequisites
Method
updateRow: function updateRow(params, callback)
Examples
The following sample code changes the value of the col1 attribute column to changed_val1 for the row whose primary key is row1 in the test_table table.
var params = {
tableName: 'test_table',
primaryKey: [{ 'id': 'row1' }],
// An update condition is required to update a row. TableStore.RowExistenceExpectation.IGNORE means that the row existence is not checked.
condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null)
};
params.updateOfAttributeColumns = [
{ 'PUT': [{ 'col1': 'changed_val1' }] }
]
client.updateRow(params, function (err, data) {
if (err) {
console.log('Update 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);
});
Also perform the following row operations.
-
Add an attribute column.
params.updateOfAttributeColumns = [ { 'PUT': [{ 'col2': 'val2' }] } ] -
Set the version number for an attribute column.
params.updateOfAttributeColumns = [ { 'PUT': [{ 'col2': 'val2', 'timestamp': Date.now() }] } ] -
Delete data of a specific version from an attribute column.
params.updateOfAttributeColumns = [ { 'DELETE': [{ 'col2': TableStore.Long.fromNumber(1496826473186) }] }, ] -
Delete all data from an attribute column.
params.updateOfAttributeColumns = [ { 'DELETE_ALL': ['col2'] } ]