行操作
更新时间:2020-04-10
单条写入
描述
写入一行数据。
请求参数
参数名称 | 是否必须 | 参数类型 | 说明 |
---|---|---|---|
rowkey | 是 | String | 行主键 |
cells | 是 | Array | 每个column,value对的列表 |
+column | 是 | String | 列名,命名规则满足正则[a-zA-Z_][a-za-z0-9\_]{0,254} |
+value | 是 | String | 列值 |
返回参数
无
示例
Plain Text
1let Client = require('@baiducloud/sdk').BtsClient;
2let myClient = new Client.BtsClient(config);
3
4let putRowRequest = new Client.PutRowRequest();
5putRowRequest.rowkey = "rowkey1";
6putRowRequest.addCells("column1", "value1");
7putRowRequest.addCells("column2", "value2");
8
9myClient.putRow('{instanceName}', '{tableName}', putRowRequest)
10 .then(response => console.log(response)) // 成功
11 .catch(error => console.error(error)); // 失败
批量写入
描述
批量写入多行数据。
请求参数
参数名称 | 是否必须 | 参数类型 | 说明 |
---|---|---|---|
rows | 是 | Array | |
+rowkey | 是 | String | 行主键 |
+cells | 是 | Array | 每个column,value对的列表 |
++column | 是 | String | 列名,命名规则满足正则[a-zA-Z_][a-za-z0-9\_]{0,254} |
++value | 是 | String | 列值 |
返回参数
无
示例
Plain Text
1let Client = require('@baiducloud/sdk').BtsClient;
2let myClient = new Client.BtsClient(config);
3
4let batchPutRowRequest = new Client.BatchPutRowRequest();
5batchPutRowRequest.addRows('rowkey1', 'column1', 'value1');
6batchPutRowRequest.addRows('rowkey1', 'column2', 'value2');
7batchPutRowRequest.addRows('rowkey2', 'column1', 'value3');
8batchPutRowRequest.addRows('rowkey2', 'column3', 'value4');
9
10myClient.batchPutRow('{instanceName}', '{tableName}', batchPutRowRequest)
11 .then(response => console.log(response)) // 成功
12 .catch(error => console.error(error)); // 失败
单条删除
描述
删除一整行数据或该行数据的部分列。
请求参数
参数名称 | 是否必须 | 参数类型 | 说明 |
---|---|---|---|
rowkey | 是 | String | 行主键 |
cells | 否 | Array | 待删除column列表,不指定默认删除全部列 |
+column | 否 | String | 待删除的列名称 |
返回参数
无
示例
Plain Text
1let Client = require('@baiducloud/sdk').BtsClient;
2let myClient = new Client.BtsClient(config);
3
4let deleteRowRequest = new Client.DeleteRowRequest();
5deleteRowRequest.rowkey = 'rowkey1';
6deleteRowRequest.addCells('column1');
7deleteRowRequest.addCells('column2');
8
9myClient.deleteRow('{instanceName}', '{tableName}', deleteRowRequest)
10 .then(response => console.log(response)) // 成功
11 .catch(error => console.error(error)); // 失败
批量删除
描述
批量删除若干行数据。
请求参数
参数名称 | 是否必须 | 参数类型 | 说明 |
---|---|---|---|
rows | 是 | Array | 指定要删除的列 |
+rowkey | 是 | String | 行主键 |
+cells | 是 | Array | 待删除column列表 |
++column | 是 | String | 待删除的列名称 |
返回参数
无
示例
Plain Text
1let Client = require('@baiducloud/sdk').BtsClient;
2let myClient = new Client.BtsClient(config);
3
4let batchDeleteRowRequest = new Client.BatchDeleteRowRequest();
5batchDeleteRowRequest.addRows('rowkey1', 'column1');
6batchDeleteRowRequest.addRows('rowkey2', 'column2');
7batchDeleteRowRequest.addRows('rowkey3', 'column1');
8batchDeleteRowRequest.addRows('rowkey4', 'column3');
9
10myClient.batchDeleteRow('{instanceName}', '{tableName}', batchDeleteRowRequest)
11 .then(response => console.log(response)) // 成功
12 .catch(error => console.error(error)); // 失败
单条随机读
描述
查询一行,或一行中的某些列。
请求参数
参数名称 | 是否必须 | 参数类型 | 说明 |
---|---|---|---|
rowkey | 是 | String | 行主键 |
cells | 否 | Array | 待查询的column列表 |
+column | 否 | String | 待查询的列名称,不指定默认返回全部列 |
maxVersions | 否 | Number | 最多保留版本数,取值范围[1, 50000]。设置该值后,用户可读取之前的版本到最新版本之间共maxVersions个版本的数据 |
返回参数
参数名称 | 参数类型 | 说明 |
---|---|---|
result | Array | 查询到的行结果,单条随机读最多只会有一个result |
+rowkey | String | 主键,用户需rawurldecode |
+cells | Array | 查询到的column列表 |
++column | String | 列名 |
++value | String | 列值,用户需rawurldecode |
++timestamp | Number | 指定列的版本号,毫秒级的时间戳 |
示例
Plain Text
1let Client = require('@baiducloud/sdk').BtsClient;
2let myClient = new Client.BtsClient(config);
3
4let getRowRequest = new Client.GetRowRequest();
5getRowRequest.rowkey = 'rowkey1';
6getRowRequest.addCells('column1');
7getRowRequest.addCells('column2');
8getRowRequest.addCells('column3');
9
10myClient.getRow('{instanceName}', '{tableName}', getRowRequest)
11 .then(response => console.log(response)) // 成功
12 .catch(error => console.error(error)); // 失败
批量读
描述
批量查询多行,或其中的某些列。
请求参数
参数名称 | 是否必须 | 参数类型 | 说明 |
---|---|---|---|
rows | 是 | Array | |
+rowkey | 是 | String | 行主键 |
+cells | 否 | Array | 待查询的column列表 |
++column | 否 | String | 待查询的列名称 |
maxVersions | 否 | Number | 最多保留版本数,取值范围[1, 50000]。设置该值后,用户可读取之前的版本到最新版本之间共maxVersions个版本的数据 |
返回参数
参数名称 | 参数类型 | 说明 |
---|---|---|
result | Array | 查询到的行结果 |
+rowkey | String | 主键,用户需rawurldecode |
+cells | Array | 查询到的column列表 |
++column | String | 属性列名称 |
++value | String | 列值,用户需rawurldecode |
++timestamp | Number | 指定列的版本号,毫秒级的时间戳 |
示例
Plain Text
1let Client = require('@baiducloud/sdk').BtsClient;
2let myClient = new Client.BtsClient(config);
3
4let batchGetRowRequest = new Client.BatchGetRowRequest();
5batchGetRowRequest.addRows('rowkey1', 'column1');
6batchGetRowRequest.addRows('rowkey2');
7
8myClient.batchGetRow('{instanceName}', '{tableName}', batchGetRowRequest)
9 .then(response => console.log(response)) // 成功
10 .catch(error => console.error(error)); // 失败
区间读
描述
扫描若干行数据。
请求参数
参数名称 | 是否必须 | 参数类型 | 说明 |
---|---|---|---|
startRowkey | 否 | String | scan的起始rowkey,不填时默认为表的第一个rowkey |
includeStart | 否 | Boolean | 是否包含起始rowkey,默认包含 |
stopRowkey | 否 | String | scan的终止rowkey,不填时默认为表的最后一个rowkey |
includeStop | 否 | Boolean | 是否包含终止rowkey,默认不包含 |
selector | 否 | Array | 待查询的column列表,不写默认返回全部列 |
+column | 否 | String | 待查询的列名称 |
limit | 否 | Number | 限定查询行数,其值必须为整数,设为其他类型无效,默认返回全部列 |
maxVersions | 否 | Number | 最多保留版本数,取值范围[1, 50000]。设置该值后,用户可读取之前的版本到最新版本之间共maxVersions个版本的数据 |
注意:startRowkey和stopRowkey指定的区间只需要包含用户所读数据即可,不需要一定是真实存在于表中的rowkey。
返回参数
参数名称 | 参数类型 | 说明 |
---|---|---|
result | Array | 记录列表 |
+rowkey | String | 主键,用户需rawurldecode |
+cells | Array | cell列表 |
++column | String | 列名 |
++value | String | 列值,用户需rawurldecode |
++timestamp | Number | 指定列的版本号,毫秒级的时间戳 |
nextStartKey | String | 若本次扫描未结束(返回206),后端会返回nextStartKey作为下一次扫描的起始key,用户应使用此值填充至startRowkey发起下一次scan操作 |
示例
Plain Text
1let Client = require('@baiducloud/sdk').BtsClient;
2let myClient = new Client.BtsClient(config);
3
4let scanRowRequest = new Client.ScanRequest();
5scanRowRequest.startRowkey = 'rowkey1';
6scanRowRequest.stopRowkey = 'rowkey2';
7scanRowRequest.includeStart = true;
8scanRowRequest.includeStop = false;
9scanRowRequest.addCells('column1');
10
11myClient.scan('{instanceName}', '{tableName}', scanRowRequest)
12 .then(response => console.log(response)) // 成功
13 .catch(error => console.error(error)); // 失败