1.batchWriteRow方法
var put = new Array();
results.map(function (o) {
if (o.method_name) {
var splitKey = o.method_name + "," + o.user_id + "," + o.created_date.toString() + "," + o.status;
console.log(splitKey);
put.push({
condition: { row_existence: "IGNORE" },
primary_key: [{
name: "_id",
value: {
type: "STRING",
v_string: splitKey
}
}],
attribute_columns: [
{
name: 'user_id',
value: {
type: 'STRING',
v_string: o.user_id
}
},
{
name: 'product_name',
value: {
type: 'STRING',
v_string: o.product_name
}
}
]
});
return put;
}
})
var rule = {
instance_name: OtsConfig.tables.detail.instance,
tables: [
{
table_name: OtsConfig.tables.detail.tableName,
put_rows: put
}
]
}
AliyunOTS.batchWriteRow(rule, function (err, data) {
if (err) {
console.log('失败' + err);
} else {
console.log('成功' + data);
}
});
2.getRange方法
var getRangeRule = {
instance_name: OtsConfig.tables.detail.instance,
table_name: OtsConfig.tables.detail.tableName,
direction: 'FORWARD',
columns_to_get: ['_id', 'appkey', 'product_name', 'cost', '__v'],
limit: 10,
inclusive_start_primary_key: [{
name: "_id",
value: {
type: "STRING",
v_string: '000000000000000000000000,1449065436828,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
}
}],
exclusive_end_primary_key: [{
name: "_id",
value: {
type: "STRING",
v_string: 'zzzzzzzzzzzzzzzzzzzzzzzz,1449065443990,zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'
}
}]
}
//范围读
AliyunOTS.getRange(getRangeRule, function (err, data) {
if (err) {
console.log('失败' + err);
} else {
console.log('成功' + data);
if (data.rows.length > 0) {
var getRangeResult = []
data.rows.map(function (o) {
getRangeResult.push({
appkey: o.attribute_columns[0].value.v_string,
product_name: o.attribute_columns[1].value.v_string,
_id: o.primary_key_columns[0].value.v_string
})
})
console.log(getRangeResult);
}
}
})
3.listTable方法
var listTableRule = {
instance_name: OtsConfig.tables.detail.instance,
}
AliyunOTS.listTable(listTableRule, function (err, data) {
if (err) {
console.log('失败' + err);
} else {
console.log('成功' + data);
}
});
4.createTable方法
var createTableRule = {
instance_name: OtsConfig.tables.detail.instance,
table_meta: {
table_name: 'test',
primary_key: [
{
name: "_id",
type: "STRING",
},
{
name: "name",
type: "STRING",
},
{
name: "age",
type: "INTEGER",
}
]
},
reserved_throughput: {
capacity_unit: {
read: 0,
write: 0
}
}
}
AliyunOTS.createTable(createTableRule, function (err, data) {
if (err) {
console.log('失败' + err);
} else {
console.log('成功' + data);
}
})
5.deleteTable方法
var deleteTableRule = {
instance_name: OtsConfig.tables.detail.instance,
table_name: 'test'
}
AliyunOTS.deleteTable(deleteTableRule, function (err, data) {
if (err) {
console.log('失败' + err);
} else {
console.log('成功' + data);
}
})
6.updateTable方法
var updateTableRule = {
instance_name: OtsConfig.tables.detail.instance,
table_name: 'test',
reserved_throughput: {
capacity_unit: {
read: 2,
write: 1
}
}
}
AliyunOTS.updateTable(updateTableRule, function (err, data) {
if (err) {
console.log('失败' + err);
} else {
console.log('成功' + data);
}
})
7.describeTable方法
var describeTableRule = {
instance_name: OtsConfig.tables.detail.instance,
table_name: 'test'
}
AliyunOTS.describeTable(describeTableRule, function (err, data) {
if (err) {
console.log('失败' + err);
} else {
console.log('成功' + data);
}
})