아리운-sdk

5290 단어

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);
    }
})

좋은 웹페이지 즐겨찾기