Closed Just2Archi closed 6 years ago
创建表
var client = require('./client'); var params = { tableMeta: { tableName: 'sampleTable', primaryKey: [ { name: 'gid', type: 'INTEGER' }, { name: 'uid', type: 'INTEGER', option: 'AUTO_INCREMENT' // 自增列 } ] }, reservedThroughput: { capacityUnit: { read: 0, write: 0 } }, tableOptions: { timeToLive: -1,// 数据的过期时间, 单位秒, -1代表永不过期. 假如设置过期时间为一年, 即为 365 * 24 * 3600. maxVersions: 1// 保存的最大版本数, 设置为1即代表每列上最多保存一个版本(保存最新的版本). } }; client.createTable(params, function (err, data) { if (err) { console.log('error:', err); return; } console.log('success:', data); });
插入数据
var TableStore = require('../index.js'); var Long = TableStore.Long; var client = require('./client'); var currentTimeStamp = Date.now(); var params = { tableName: "sampleTable", condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null), primaryKey: [{ 'gid': Long.fromNumber(20013) }, { 'uid': Long.fromNumber(20013) }], attributeColumns: [ { 'col1': '表格存储' }, { 'col2': '2', 'timestamp': currentTimeStamp }, { 'col3': 3.1 }, { 'col4': -0.32 }, { 'col5': Long.fromNumber(123456789) } ], returnContent: { returnType: TableStore.ReturnType.Primarykey } }; client.putRow(params, function (err, data) { if (err) { console.log('error:', err); return; } console.log('success:', data); });
参考下:https://github.com/aliyun/aliyun-tablestore-nodejs-sdk/blob/master/samples/primarykey.js 这个里面的putRow
创建表
插入数据