本文介绍如何通过 Node.js SDK 在表格存储的数据表中写入单行数据。
前提条件
方法说明
putRow: function putRow(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.putRow(params, function (err, data) {
if (err) {
console.log('Put 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);
});添加属性列。
params.attributeColumns = [{ 'col1': 'val1' }];指定数据版本号,您可以为每个属性列指定单独的版本号。
params.attributeColumns = [{ 'col1': 'val1', 'timestamp': Date.now() }];
相关文档
该文章对您有帮助吗?