未验证 提交 729ada92 编写于 作者: O openharmony_ci 提交者: Gitee

!5687 3.1-Release分布式数据示例代码更改

Merge pull request !5687 from Wangkai/OpenHarmony-3.1-Release
......@@ -270,7 +270,7 @@ const options = {
kvManager.getKVStore('storeId', options, async function (err, store) {
console.log('getKVStore success');
kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) {
kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) {
console.log('closeKVStore success');
});
});
......@@ -320,7 +320,7 @@ const options = {
kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('getKVStore success');
kvStore = store;
await kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => {
kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => {
console.log('closeKVStore success');
}).catch((err) => {
console.log('closeKVStore err ' + JSON.stringify(err));
......@@ -368,7 +368,7 @@ try {
kvManager.getKVStore('store', options, async function (err, store) {
console.log('getKVStore success');
kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId', function (err, data) {
kvManager.deleteKVStore('appId', 'storeId', function (err, data) {
console.log('deleteKVStore success');
});
});
......@@ -417,7 +417,7 @@ try {
kvManager.getKVStore('storeId', options).then(async (store) => {
console.log('getKVStore success');
kvStore = store;
await kvManager.deleteKVStore('appId', 'storeId').then(() => {
kvManager.deleteKVStore('appId', 'storeId').then(() => {
console.log('deleteKVStore success');
}).catch((err) => {
console.log('deleteKVStore err ' + JSON.stringify(err));
......@@ -704,7 +704,7 @@ try {
node.appendChild(child1);
node.appendChild(child2);
node.appendChild(child3);
console.log("appendNode " + node.toJson());
console.log("appendNode " + JSON.stringify(node));
child1 = null;
child2 = null;
child3 = null;
......@@ -2341,7 +2341,7 @@ try {
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key', function (err,entrys) {
kvStore.getEntries('batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
......@@ -2393,7 +2393,7 @@ try {
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key').then((entrys) => {
kvStore.getEntries('batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('PutBatch ' + JSON.stringify(entries));
}).catch((err) => {
......@@ -2445,7 +2445,7 @@ try {
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.deleteBatch(keys, async function (err,data) {
kvStore.deleteBatch(keys, async function (err,data) {
console.log('deleteBatch success');
});
});
......@@ -2497,7 +2497,7 @@ try {
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.deleteBatch(keys).then((err) => {
kvStore.deleteBatch(keys).then((err) => {
console.log('deleteBatch success');
}).catch((err) => {
console.log('deleteBatch fail ' + JSON.stringify(err));
......@@ -2553,7 +2553,7 @@ try {
console.log('startTransaction success');
let entries = putBatchString(10, 'batch_test_string_key');
console.log('entries: ' + JSON.stringify(entries));
await kvStore.putBatch(entries, async function (err,data) {
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
});
});
......@@ -3049,7 +3049,7 @@ try {
}
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('batch_test_number_key', function (err,entrys) {
kvStore.getEntries('batch_test_number_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
......@@ -3101,7 +3101,7 @@ try {
console.log('entries: ' + entries);
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('batch_test_string_key').then((entrys) => {
kvStore.getEntries('batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
......@@ -3157,7 +3157,7 @@ try {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query, function (err,entrys) {
kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
......@@ -3193,6 +3193,7 @@ getEntries(query: Query): Promise<Entry[]>
**示例:**
```js
let kvStore;
try {
var arr = new Uint8Array([21,31]);
let entries = [];
......@@ -3212,7 +3213,7 @@ try {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query).then((entrys) => {
kvStore.getEntries(query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
......@@ -3262,7 +3263,7 @@ try {
}
kvStore.putBatch(entries, async function (err, data) {
console.log('GetResultSet putBatch success');
await kvStore.getResultSet('batch_test_string_key', async function (err, result) {
kvStore.getResultSet('batch_test_string_key', async function (err, result) {
console.log('GetResultSet getResultSet succeed.');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
......@@ -3373,7 +3374,7 @@ try {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet(query, async function (err, result) {
kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet succeed.');
resultSet = result;
});
......@@ -3547,7 +3548,7 @@ try {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize(query, async function (err, resultSize) {
kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet succeed.');
});
});
......@@ -3637,12 +3638,12 @@ try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('put success');
const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) {
kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) {
console.log('removeDeviceData success');
} else {
console.log('removeDeviceData fail');
await kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err,data) {
kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData get success');
});
}
......@@ -4046,7 +4047,7 @@ try {
console.log('entries: ' + entries);
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
await kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err,entrys) {
kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
......@@ -4099,7 +4100,7 @@ try {
console.log('entries: ' + entries);
kvStore.putBatch(entries).then(async (err) => {
console.log('putBatch success');
await kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entrys) => {
kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entrys) => {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
......@@ -4153,11 +4154,10 @@ try {
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getEntries(query, function (err,entrys) {
kvStore.getEntries(query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
......@@ -4213,7 +4213,7 @@ try {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getEntries(query).then((entrys) => {
kvStore.getEntries(query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
......@@ -4265,11 +4265,10 @@ try {
console.log('entries: ' + JSON.stringify(entries));
kvStore.putBatch(entries, async function (err,data) {
console.log('putBatch success');
expect(err == undefined).assertTrue();
var query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query, function (err,entrys) {
kvStore.getEntries('localDeviceId', query, function (err,entrys) {
console.log('getEntries success');
console.log('entrys.length: ' + entrys.length);
console.log('entrys[0]: ' + JSON.stringify(entrys[0]));
......@@ -4327,7 +4326,7 @@ try {
var query = new distributedData.Query();
query.deviceId('localDeviceId');
query.prefixKey("batch_test");
await kvStore.getEntries('localDeviceId', query).then((entrys) => {
kvStore.getEntries('localDeviceId', query).then((entrys) => {
console.log('getEntries success');
}).catch((err) => {
console.log('getEntries fail ' + JSON.stringify(err));
......@@ -4367,7 +4366,7 @@ try {
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
console.log('getResultSet succeed.');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
......@@ -4459,10 +4458,10 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSet(query, async function (err, result) {
kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet succeed.');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
......@@ -4575,10 +4574,10 @@ try {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet('localDeviceId', query, async function (err, result) {
kvStore.getResultSet('localDeviceId', query, async function (err, result) {
console.log('getResultSet succeed.');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
})
});
......@@ -4765,7 +4764,7 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSize(query, async function (err, resultSize) {
kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet succeed.');
});
});
......@@ -4868,7 +4867,7 @@ try {
console.log('putBatch success');
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
console.log('getResultSet succeed.');
});
});
......@@ -4959,12 +4958,12 @@ try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData put success');
const deviceid = 'no_exist_device_id';
await kvStore.removeDeviceData(deviceid, async function (err,data) {
kvStore.removeDeviceData(deviceid, async function (err,data) {
if (err == undefined) {
console.log('removeDeviceData success');
} else {
console.log('removeDeviceData fail');
await kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, async function (err,data) {
kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, async function (err,data) {
console.log('RemoveDeviceData get success');
});
}
......@@ -5082,6 +5081,7 @@ on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]&gt
**示例:**
```js
let kvStore;
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const VALUE_TEST_FLOAT_ELEMENT = 321.12;
try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册