Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created September 19, 2014 07:22
Show Gist options
  • Select an option

  • Save fengmk2/f59cfc7ac957e80c7fa1 to your computer and use it in GitHub Desktop.

Select an option

Save fengmk2/f59cfc7ac957e80c7fa1 to your computer and use it in GitHub Desktop.
var ots = require('ots');
var client = ots.createClient({
accessID: 'your accessID',
accessKey: 'your accessKey'
});
// create a table
client.createTable({
TableName: 'testdemo',
PrimaryKey: [
{'Name': 'uid', 'Type': 'STRING'},
],
PagingKeyLen: 0,
View: [
{
'Name': 'view1',
'PrimaryKey' : [
{'Name':'uid', 'Type':'STRING'},
{'Name':'flag', 'Type':'STRING'},
{'Name':'docid', 'Type':'STRING'},
],
'Column' : [
{'Name':'updatetime', 'Type':'STRING'},
{'Name':'createtime', 'Type':'STRING'},
],
'PagingKeyLen': 2
}
]
}, function(err, result) {
console.log(err, result);
});
// insert a row
client.putRow('user',
{ Name: 'uid', Value: 'mk2' },
[
{ Name: 'firstname', Value: 'yuan' },
{ Name: 'lastname', Value: 'feng\' aerdeng' },
{ Name: 'nickname', Value: '苏千' },
{ Name: 'age', Value: 28 },
{ Name: 'price', Value: 110.5 },
{ Name: 'enable', Value: true },
{ Name: 'man', Value: true },
{ Name: 'female', Value: false },
{ Name: 'createtime', Value: new Date().toJSON() },
], function(err, result) {
console.log(err, result);
});
// get a row
client.getRow('user', { Name: 'uid', Value: 'mk2' }, function (err, row) {
console.log(err, row);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment