提交 c0af92a1 编写于 作者: A Annie_wang
上级 8f20ac7f
...@@ -13,7 +13,7 @@ For details about the APIs, see [Distributed KV Store](../reference/apis/js-apis ...@@ -13,7 +13,7 @@ For details about the APIs, see [Distributed KV Store](../reference/apis/js-apis
| API | Description | | API | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ | | ------------------------------------------------------------ | ------------------------------------------------------------ |
| createKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): void<br>createKVManager(config: KVManagerConfig): Promise&lt;KVManager> | Creates a **KvManager** object for database management. | | createKVManager(config: KVManagerConfig): KVManager | Creates a **KvManager** object for database management. |
| getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void<br>getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options): Promise&lt;T&gt; | Creates and obtains a KV store.| | getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void<br>getKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options): Promise&lt;T&gt; | Creates and obtains a KV store.|
| put(key: string, value: Uint8Array\|string\|number\|boolean, callback: AsyncCallback&lt;void&gt;): void<br>put(key: string, value: Uint8Array\|string\|number\|boolean): Promise&lt;void> | Inserts and updates data. | | put(key: string, value: Uint8Array\|string\|number\|boolean, callback: AsyncCallback&lt;void&gt;): void<br>put(key: string, value: Uint8Array\|string\|number\|boolean): Promise&lt;void> | Inserts and updates data. |
| delete(key: string, callback: AsyncCallback&lt;void&gt;): void<br>delete(key: string): Promise&lt;void> | Deletes data. | | delete(key: string, callback: AsyncCallback&lt;void&gt;): void<br>delete(key: string): Promise&lt;void> | Deletes data. |
...@@ -117,16 +117,10 @@ The following uses a single KV store as an example to describe the development p ...@@ -117,16 +117,10 @@ The following uses a single KV store as an example to describe the development p
bundleName: 'com.example.datamanagertest', bundleName: 'com.example.datamanagertest',
context:context, context:context,
} }
distributedKVStore.createKVManager(kvManagerConfig, function (err, manager) { kvManager = distributedKVStore.createKVManager(kvManagerConfig);
if (err) { console.log("Created KVManager successfully");
console.error(`Failed to create KVManager. code is ${err.code},message is ${err.message}`);
return;
}
console.log('Created KVManager successfully');
kvManager = manager;
});
} catch (e) { } catch (e) {
console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); console.error(`Failed to create KVManager. Code is ${e.code}, message is ${e.message}`);
} }
``` ```
...@@ -150,14 +144,14 @@ The following uses a single KV store as an example to describe the development p ...@@ -150,14 +144,14 @@ The following uses a single KV store as an example to describe the development p
}; };
kvManager.getKVStore('storeId', options, function (err, store) { kvManager.getKVStore('storeId', options, function (err, store) {
if (err) { if (err) {
console.error(`Failed to get KVStore: code is ${err.code},message is ${err.message}`); console.error(`Failed to get KVStore: code is ${err.code}, message is ${err.message}`);
return; return;
} }
console.log('Obtained KVStore successfully'); console.log('Obtained KVStore successfully');
kvStore = store; kvStore = store;
}); });
} catch (e) { } catch (e) {
console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); console.error(`An unexpected error occurred. Code is ${e.code}, message is ${e.message}`);
} }
``` ```
...@@ -175,7 +169,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -175,7 +169,7 @@ The following uses a single KV store as an example to describe the development p
console.log(`dataChange callback call data: ${data}`); console.log(`dataChange callback call data: ${data}`);
}); });
}catch(e){ }catch(e){
console.error(`An unexpected error occured.code is ${e.code},message is ${e.message}`); console.error(`An unexpected error occured. Code is ${e.code}, message is ${e.message}`);
} }
``` ```
...@@ -192,13 +186,13 @@ The following uses a single KV store as an example to describe the development p ...@@ -192,13 +186,13 @@ The following uses a single KV store as an example to describe the development p
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) { if (err != undefined) {
console.error(`Failed to put.code is ${err.code},message is ${err.message}`); console.error(`Failed to put data. Code is ${err.code}, message is ${err.message}`);
return; return;
} }
console.log('Put data successfully'); console.log("Put data successfully");
}); });
}catch (e) { }catch (e) {
console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); console.error(`An unexpected error occurred. Code is ${e.code}, message is ${e.message}`);
} }
``` ```
...@@ -215,20 +209,20 @@ The following uses a single KV store as an example to describe the development p ...@@ -215,20 +209,20 @@ The following uses a single KV store as an example to describe the development p
try { try {
kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) { if (err != undefined) {
console.error(`Failed to put.code is ${err.code},message is ${err.message}`); console.error(`Failed to put data. Code is ${err.code}, message is ${err.message}`);
return; return;
} }
console.log('Put data successfully'); console.log("Put data successfully");
kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) { kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) {
if (err != undefined) { if (err != undefined) {
console.error(`Failed to get data.code is ${err.code},message is ${err.message}`); console.error(`Failed to obtain data. Code is ${err.code}, message is ${err.message}`);
return; return;
} }
console.log(`Obtained data successfully:${data}`); console.log(`Obtained data successfully:${data}`);
}); });
}); });
}catch (e) { }catch (e) {
console.error(`Failed to get.code is ${e.code},message is ${e.message}`); console.error(`Failed to obtain data. Code is ${e.code}, message is ${e.message}`);
} }
``` ```
...@@ -262,7 +256,7 @@ The following uses a single KV store as an example to describe the development p ...@@ -262,7 +256,7 @@ The following uses a single KV store as an example to describe the development p
// 1000 indicates that the maximum delay is 1000 ms. // 1000 indicates that the maximum delay is 1000 ms.
kvStore.sync(deviceIds, distributedKVStore.SyncMode.PUSH_ONLY, 1000); kvStore.sync(deviceIds, distributedKVStore.SyncMode.PUSH_ONLY, 1000);
} catch (e) { } catch (e) {
console.error(`An unexpected error occurred. code is ${e.code},message is ${e.message}`); console.error(`An unexpected error occurred. Code is ${e.code}, message is ${e.message}`);
} }
} }
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册