1e41f4b71Sopenharmony_ci# @ohos.data.distributedData (Distributed Data Management)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe distributed data management module implements collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to distributed databases and perform operations such as adding, deleting, modifying, querying, and synchronizing data in distributed databases.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThis module provides the following functions:
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci- [KVManager](#kvmanager): provides a **KVManager** instance to manage key-value (KV) stores.
8e41f4b71Sopenharmony_ci- [KvStoreResultSet<sup>8+</sup>](#kvstoreresultset8): provides APIs to obtain the KV store result set and query or move the data read position.
9e41f4b71Sopenharmony_ci- [Query<sup>8+</sup>](#query8): provides APIs to query data from the database through a **Query** instance by using predicates.
10e41f4b71Sopenharmony_ci- [KVStore](#kvstore): provides APIs to add data, delete data, and observe data changes and data sync through a **KVStore** instance.
11e41f4b71Sopenharmony_ci- [SingleKVStore](#singlekvstore): provides APIs to query and synchronize data in a single KV store. This class inherits from [KVStore](#kvstore), and data is not distinguished by device.
12e41f4b71Sopenharmony_ci- [DeviceKVStore<sup>8+</sup>](#devicekvstore8): provides APIs to query and synchronize data in a device KV store. This class inherits from [KVStore](#kvstore), and data is distinguished by device.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci>**NOTE**
15e41f4b71Sopenharmony_ci>
16e41f4b71Sopenharmony_ci>- The APIs provided by this module are no longer maintained since API version 9. You are advised to use [@ohos.data.distributedKVStore](js-apis-distributedKVStore.md).
17e41f4b71Sopenharmony_ci>
18e41f4b71Sopenharmony_ci>- The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
19e41f4b71Sopenharmony_ci>
20e41f4b71Sopenharmony_ci>- All the APIs that need to obtain **deviceId** in this module are available only to system applications.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## Modules to Import
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci```js
26e41f4b71Sopenharmony_ciimport distributedData from '@ohos.data.distributedData';
27e41f4b71Sopenharmony_ci```
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci## distributedData.createKVManager
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_cicreateKVManager(config: KVManagerConfig, callback: AsyncCallback&lt;KVManager&gt;): void
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ciCreates a **KVManager** instance to manage KV stores. This API uses an asynchronous callback to return the result.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Parameters**
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
41e41f4b71Sopenharmony_ci| ----- | ------ | ------ | ------ |
42e41f4b71Sopenharmony_ci| config | [KVManagerConfig](#kvmanagerconfig) | Yes | Configuration of the **KVManager** instance, including the bundle name and user information of the caller.|
43e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;[KVManager](#kvmanager)&gt; | Yes | Callback used to return the **KVManager** instance created.|
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Example**
46e41f4b71Sopenharmony_ci```js
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_cilet kvManager;
49e41f4b71Sopenharmony_citry {
50e41f4b71Sopenharmony_ci    const kvManagerConfig = {
51e41f4b71Sopenharmony_ci        bundleName : 'com.example.datamanagertest',
52e41f4b71Sopenharmony_ci        userInfo : {
53e41f4b71Sopenharmony_ci            userId : '0',
54e41f4b71Sopenharmony_ci            userType : distributedData.UserType.SAME_USER_ID
55e41f4b71Sopenharmony_ci        }
56e41f4b71Sopenharmony_ci    }
57e41f4b71Sopenharmony_ci    distributedData.createKVManager(kvManagerConfig, function (err, manager) {
58e41f4b71Sopenharmony_ci        if (err) {
59e41f4b71Sopenharmony_ci            console.log("Failed to create KVManager: "  + JSON.stringify(err));
60e41f4b71Sopenharmony_ci            return;
61e41f4b71Sopenharmony_ci        }
62e41f4b71Sopenharmony_ci        console.log("Created KVManager successfully");
63e41f4b71Sopenharmony_ci        kvManager = manager;
64e41f4b71Sopenharmony_ci    });
65e41f4b71Sopenharmony_ci} catch (e) {
66e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
67e41f4b71Sopenharmony_ci}
68e41f4b71Sopenharmony_ci```
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci## distributedData.createKVManager
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_cicreateKVManager(config: KVManagerConfig): Promise&lt;KVManager&gt;
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciCreates a **KVManager** instance to manage KV stores. This API uses a promise to return the result.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**Parameters**
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
81e41f4b71Sopenharmony_ci| ----- | ------ | ------ | ------ |
82e41f4b71Sopenharmony_ci| config |[KVManagerConfig](#kvmanager) | Yes | Configuration of the **KVManager** instance, including the bundle name and user information of the caller.|
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Return value**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| Type| Description|
87e41f4b71Sopenharmony_ci| -------- | -------- |
88e41f4b71Sopenharmony_ci| Promise&lt;[KVManager](#kvmanager)&gt; | Promise used to return the **KVManager** instance created.|
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Example**
91e41f4b71Sopenharmony_ci```js
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_citry {
94e41f4b71Sopenharmony_ci  const kvManagerConfig = {
95e41f4b71Sopenharmony_ci    bundleName: 'com.example.datamanagertest',
96e41f4b71Sopenharmony_ci    userInfo: {
97e41f4b71Sopenharmony_ci      userId: '0',
98e41f4b71Sopenharmony_ci      userType: distributedData.UserType.SAME_USER_ID
99e41f4b71Sopenharmony_ci    }
100e41f4b71Sopenharmony_ci  }
101e41f4b71Sopenharmony_ci  distributedData.createKVManager(kvManagerConfig).then((manager) => {
102e41f4b71Sopenharmony_ci    console.log("Created KVManager successfully");
103e41f4b71Sopenharmony_ci    kvManager = manager;
104e41f4b71Sopenharmony_ci  }).catch((err) => {
105e41f4b71Sopenharmony_ci    console.error("Failed to create KVManager: " + JSON.stringify(err));
106e41f4b71Sopenharmony_ci  });
107e41f4b71Sopenharmony_ci} catch (e) {
108e41f4b71Sopenharmony_ci  console.log("An unexpected error occurred. Error:" + e);
109e41f4b71Sopenharmony_ci}
110e41f4b71Sopenharmony_ci```
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci## KVManagerConfig
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ciDefines the configuration of the **KVManager** object, including the bundle name and user information of the caller.
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
119e41f4b71Sopenharmony_ci| ----- | ------ | ------ | ------ |
120e41f4b71Sopenharmony_ci| userInfo | [UserInfo](#userinfo) | Yes | User information.|
121e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name of the caller.|
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci## UserInfo
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ciDefines user information.
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
130e41f4b71Sopenharmony_ci| ----- | ------ |------ | ------ |
131e41f4b71Sopenharmony_ci| userId | string | No | User ID. The default value is **0**.|
132e41f4b71Sopenharmony_ci| userType | [UserType](#usertype) | No | User type. The default value is **0**.|
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci## UserType
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ciEnumerates the user types.
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci| Name| Value| Description|
142e41f4b71Sopenharmony_ci| ----- | ------ | ------ |
143e41f4b71Sopenharmony_ci| SAME_USER_ID | 0 | User who logs in to different devices using the same account.|
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci## KVManager
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ciCreates a **KVManager** object to obtain KV store information. Before calling any method in **KVManager**, you must use [createKVManager](#distributeddatacreatekvmanager) to create a **KVManager** object.
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci### getKVStore
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_cigetKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options, callback: AsyncCallback&lt;T&gt;): void
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ciCreates and obtains a KV store. This API uses an asynchronous callback to return the result.
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci**Parameters**
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
161e41f4b71Sopenharmony_ci| ----- | ------ | ------ | ------ |
162e41f4b71Sopenharmony_ci| storeId | string | Yes | Unique identifier of the KV store. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).|
163e41f4b71Sopenharmony_ci| options | [Options](#options) | Yes | Configuration of the KV store.|
164e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;T&gt; | Yes | Callback used to return the KV store instance created.|
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci**Example**
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci```js
169e41f4b71Sopenharmony_cilet kvStore;
170e41f4b71Sopenharmony_cilet kvManager;
171e41f4b71Sopenharmony_citry {
172e41f4b71Sopenharmony_ci    const options = {
173e41f4b71Sopenharmony_ci        createIfMissing : true,
174e41f4b71Sopenharmony_ci        encrypt : false,
175e41f4b71Sopenharmony_ci        backup : false,
176e41f4b71Sopenharmony_ci        autoSync : true,
177e41f4b71Sopenharmony_ci        kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
178e41f4b71Sopenharmony_ci        securityLevel : distributedData.SecurityLevel.S3,
179e41f4b71Sopenharmony_ci    };
180e41f4b71Sopenharmony_ci    kvManager.getKVStore('storeId', options, function (err, store) {
181e41f4b71Sopenharmony_ci        if (err) {
182e41f4b71Sopenharmony_ci            console.log("getKVStore err: "  + JSON.stringify(err));
183e41f4b71Sopenharmony_ci            return;
184e41f4b71Sopenharmony_ci        }
185e41f4b71Sopenharmony_ci        console.log("getKVStore success");
186e41f4b71Sopenharmony_ci        kvStore = store;
187e41f4b71Sopenharmony_ci    });
188e41f4b71Sopenharmony_ci} catch (e) {
189e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
190e41f4b71Sopenharmony_ci}
191e41f4b71Sopenharmony_ci```
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci### getKVStore
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_cigetKVStore&lt;T extends KVStore&gt;(storeId: string, options: Options): Promise&lt;T&gt;
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ciCreates and obtains a KV store. This API uses a promise to return the result.
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci**Parameters**
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci| Name  | Type               | Mandatory | Description   |
205e41f4b71Sopenharmony_ci| ------- | ---------------------- | ---- | -------------------- |
206e41f4b71Sopenharmony_ci| storeId  | string      | Yes  | Unique identifier of the KV store. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).|
207e41f4b71Sopenharmony_ci| options  | [Options](#options)   | Yes  | Configuration of the KV store.|
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci**Return value**
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci| Type                                   | Description       |
213e41f4b71Sopenharmony_ci| -------------------------------------- | ------------------------ |
214e41f4b71Sopenharmony_ci| Promise&lt;T&gt;, &lt;T extends [KVStore](#kvstore)&gt; | Promise used to return the KV store instance created.|
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci**Example**
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci```js
219e41f4b71Sopenharmony_cilet kvStore;
220e41f4b71Sopenharmony_cilet kvManager;
221e41f4b71Sopenharmony_citry {
222e41f4b71Sopenharmony_ci    const options = {
223e41f4b71Sopenharmony_ci        createIfMissing : true,
224e41f4b71Sopenharmony_ci        encrypt : false,
225e41f4b71Sopenharmony_ci        backup : false,
226e41f4b71Sopenharmony_ci        autoSync : true,
227e41f4b71Sopenharmony_ci        kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
228e41f4b71Sopenharmony_ci        securityLevel : distributedData.SecurityLevel.S3,
229e41f4b71Sopenharmony_ci    };
230e41f4b71Sopenharmony_ci    kvManager.getKVStore('storeId', options).then((store) => {
231e41f4b71Sopenharmony_ci        console.log("getKVStore success");
232e41f4b71Sopenharmony_ci        kvStore = store;
233e41f4b71Sopenharmony_ci    }).catch((err) => {
234e41f4b71Sopenharmony_ci        console.log("getKVStore err: "  + JSON.stringify(err));
235e41f4b71Sopenharmony_ci    });
236e41f4b71Sopenharmony_ci} catch (e) {
237e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
238e41f4b71Sopenharmony_ci}
239e41f4b71Sopenharmony_ci```
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ci### closeKVStore<sup>8+</sup>
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_cicloseKVStore(appId: string, storeId: string, kvStore: KVStore, callback: AsyncCallback&lt;void&gt;): void
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ciCloses a KV store. This API uses an asynchronous callback to return the result.
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci**Parameters**
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci| Name  | Type             | Mandatory| Description        |
253e41f4b71Sopenharmony_ci| ------- | -----------------   | ---- | --------------------------- |
254e41f4b71Sopenharmony_ci| appId    | string              | Yes  | Bundle name of the app that invokes the KV store.        |
255e41f4b71Sopenharmony_ci| storeId  | string  | Yes  | Unique identifier of the KV store to close. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).|
256e41f4b71Sopenharmony_ci| kvStore  | [KVStore](#kvstore) | Yes  | KV store to close.    |
257e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci**Example**
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci```js
262e41f4b71Sopenharmony_cilet kvStore;
263e41f4b71Sopenharmony_cilet kvManager;
264e41f4b71Sopenharmony_ciconst options = {
265e41f4b71Sopenharmony_ci    createIfMissing: true,
266e41f4b71Sopenharmony_ci    encrypt: false,
267e41f4b71Sopenharmony_ci    backup: false,
268e41f4b71Sopenharmony_ci    autoSync: false,
269e41f4b71Sopenharmony_ci    kvStoreType: distributedData.KVStoreType.SINGLE_VERSION,
270e41f4b71Sopenharmony_ci    schema: undefined,
271e41f4b71Sopenharmony_ci    securityLevel: distributedData.SecurityLevel.S3,
272e41f4b71Sopenharmony_ci}
273e41f4b71Sopenharmony_citry {
274e41f4b71Sopenharmony_ci    kvManager.getKVStore('storeId', options, async function (err, store) {
275e41f4b71Sopenharmony_ci        console.log('getKVStore success');
276e41f4b71Sopenharmony_ci        kvStore = store;
277e41f4b71Sopenharmony_ci        kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) {
278e41f4b71Sopenharmony_ci            console.log('closeKVStore success');
279e41f4b71Sopenharmony_ci        });
280e41f4b71Sopenharmony_ci    });
281e41f4b71Sopenharmony_ci} catch (e) {
282e41f4b71Sopenharmony_ci    console.log('closeKVStore e ' + e);
283e41f4b71Sopenharmony_ci}
284e41f4b71Sopenharmony_ci```
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci
287e41f4b71Sopenharmony_ci### closeKVStore<sup>8+</sup>
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_cicloseKVStore(appId: string, storeId: string, kvStore: KVStore): Promise&lt;void&gt;
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ciCloses a KV store. This API uses a promise to return the result.
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci**Parameters**
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description       |
298e41f4b71Sopenharmony_ci| -----  | ------  | ---- | ----------------------------- |
299e41f4b71Sopenharmony_ci| appId  | string  | Yes  | Bundle name of the app that invokes the KV store.           |
300e41f4b71Sopenharmony_ci| storeId | string | Yes  | Unique identifier of the KV store to close. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).|
301e41f4b71Sopenharmony_ci| kvStore | [KVStore](#kvstore)  | Yes  | KV store to close.       |
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci**Return value**
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci| Type         | Description           |
306e41f4b71Sopenharmony_ci| ------------- | -------------- |
307e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci**Example**
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ci```js
312e41f4b71Sopenharmony_cilet kvManager;
313e41f4b71Sopenharmony_cilet kvStore;
314e41f4b71Sopenharmony_ciconst options = {
315e41f4b71Sopenharmony_ci    createIfMissing: true,
316e41f4b71Sopenharmony_ci    encrypt: false,
317e41f4b71Sopenharmony_ci    backup: false,
318e41f4b71Sopenharmony_ci    autoSync: false,
319e41f4b71Sopenharmony_ci    kvStoreType: distributedData.KVStoreType.SINGLE_VERSION,
320e41f4b71Sopenharmony_ci    schema: undefined,
321e41f4b71Sopenharmony_ci    securityLevel: distributedData.SecurityLevel.S3,
322e41f4b71Sopenharmony_ci}
323e41f4b71Sopenharmony_citry {
324e41f4b71Sopenharmony_ci    kvManager.getKVStore('storeId', options).then(async (store) => {
325e41f4b71Sopenharmony_ci        console.log('getKVStore success');
326e41f4b71Sopenharmony_ci        kvStore = store;
327e41f4b71Sopenharmony_ci        kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => {
328e41f4b71Sopenharmony_ci            console.log('closeKVStore success');
329e41f4b71Sopenharmony_ci        }).catch((err) => {
330e41f4b71Sopenharmony_ci            console.log('closeKVStore err ' + JSON.stringify(err));
331e41f4b71Sopenharmony_ci        });
332e41f4b71Sopenharmony_ci    }).catch((err) => {
333e41f4b71Sopenharmony_ci        console.log('CloseKVStore getKVStore err ' + JSON.stringify(err));
334e41f4b71Sopenharmony_ci    });
335e41f4b71Sopenharmony_ci} catch (e) {
336e41f4b71Sopenharmony_ci    console.log('closeKVStore e ' + e);
337e41f4b71Sopenharmony_ci}
338e41f4b71Sopenharmony_ci```
339e41f4b71Sopenharmony_ci
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci### deleteKVStore<sup>8+</sup>
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_cideleteKVStore(appId: string, storeId: string, callback: AsyncCallback&lt;void&gt;): void
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ciDeletes a KV store. This API uses an asynchronous callback to return the result.
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci**Parameters**
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
352e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
353e41f4b71Sopenharmony_ci| appId  | string  | Yes  | Bundle name of the app that invokes the KV store.    |
354e41f4b71Sopenharmony_ci| storeId | string | Yes  | Unique identifier of the KV store to delete. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).|
355e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;  | Yes  | Callback used to return the result.|
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci**Example**
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci```js
360e41f4b71Sopenharmony_cilet kvManager;
361e41f4b71Sopenharmony_cilet kvStore;
362e41f4b71Sopenharmony_ciconst options = {
363e41f4b71Sopenharmony_ci    createIfMissing : true,
364e41f4b71Sopenharmony_ci    encrypt : false,
365e41f4b71Sopenharmony_ci    backup : false,
366e41f4b71Sopenharmony_ci    autoSync : true,
367e41f4b71Sopenharmony_ci    kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
368e41f4b71Sopenharmony_ci    schema : undefined,
369e41f4b71Sopenharmony_ci    securityLevel : distributedData.SecurityLevel.S3,
370e41f4b71Sopenharmony_ci}
371e41f4b71Sopenharmony_citry {
372e41f4b71Sopenharmony_ci    kvManager.getKVStore('store', options, async function (err, store) {
373e41f4b71Sopenharmony_ci        console.log('getKVStore success');
374e41f4b71Sopenharmony_ci        kvStore = store;
375e41f4b71Sopenharmony_ci        kvManager.deleteKVStore('appId', 'storeId', function (err, data) {
376e41f4b71Sopenharmony_ci            console.log('deleteKVStore success');
377e41f4b71Sopenharmony_ci        });
378e41f4b71Sopenharmony_ci    });
379e41f4b71Sopenharmony_ci} catch (e) {
380e41f4b71Sopenharmony_ci    console.log('DeleteKVStore e ' + e);
381e41f4b71Sopenharmony_ci}
382e41f4b71Sopenharmony_ci```
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ci### deleteKVStore<sup>8+</sup>
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_cideleteKVStore(appId: string, storeId: string): Promise&lt;void&gt;
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ciDeletes a KV store. This API uses a promise to return the result.
389e41f4b71Sopenharmony_ci
390e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_ci**Parameters**
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
395e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
396e41f4b71Sopenharmony_ci| appId  | string  | Yes  | Bundle name of the app that invokes the KV store.    |
397e41f4b71Sopenharmony_ci| storeId | string | Yes  | Unique identifier of the KV store to delete. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).|
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci**Return value**
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci| Type         | Description           |
403e41f4b71Sopenharmony_ci| ------------- | -------------- |
404e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise that returns no value.|
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci**Example**
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci```js
409e41f4b71Sopenharmony_cilet kvManager;
410e41f4b71Sopenharmony_cilet kvStore;
411e41f4b71Sopenharmony_ciconst options = {
412e41f4b71Sopenharmony_ci    createIfMissing : true,
413e41f4b71Sopenharmony_ci    encrypt : false,
414e41f4b71Sopenharmony_ci    backup : false,
415e41f4b71Sopenharmony_ci    autoSync : true,
416e41f4b71Sopenharmony_ci    kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
417e41f4b71Sopenharmony_ci    schema : undefined,
418e41f4b71Sopenharmony_ci    securityLevel : distributedData.SecurityLevel.S3,
419e41f4b71Sopenharmony_ci}
420e41f4b71Sopenharmony_citry {
421e41f4b71Sopenharmony_ci    kvManager.getKVStore('storeId', options).then(async (store) => {
422e41f4b71Sopenharmony_ci        console.log('getKVStore success');
423e41f4b71Sopenharmony_ci        kvStore = store;
424e41f4b71Sopenharmony_ci        kvManager.deleteKVStore('appId', 'storeId').then(() => {
425e41f4b71Sopenharmony_ci            console.log('deleteKVStore success');
426e41f4b71Sopenharmony_ci        }).catch((err) => {
427e41f4b71Sopenharmony_ci            console.log('deleteKVStore err ' + JSON.stringify(err));
428e41f4b71Sopenharmony_ci        });
429e41f4b71Sopenharmony_ci    }).catch((err) => {
430e41f4b71Sopenharmony_ci        console.log('getKVStore err ' + JSON.stringify(err));
431e41f4b71Sopenharmony_ci    });
432e41f4b71Sopenharmony_ci} catch (e) {
433e41f4b71Sopenharmony_ci    console.log('deleteKVStore e ' + e);
434e41f4b71Sopenharmony_ci}
435e41f4b71Sopenharmony_ci```
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_ci### getAllKVStoreId<sup>8+</sup>
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_cigetAllKVStoreId(appId: string, callback: AsyncCallback&lt;string[]&gt;): void
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ciObtains the IDs of all KV stores that are created by [getKVStore()](#getkvstore) and have not been deleted by [deleteKVStore()](#deletekvstore8). This API uses an asynchronous callback to return the result.
443e41f4b71Sopenharmony_ci
444e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
445e41f4b71Sopenharmony_ci
446e41f4b71Sopenharmony_ci**Parameters**
447e41f4b71Sopenharmony_ci
448e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
449e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
450e41f4b71Sopenharmony_ci| appId  | string  | Yes   | Bundle name of the app that invokes the KV store.    |
451e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;string[]&gt; | Yes  |Callback used to return the IDs of all created KV stores.|
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci**Example**
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ci```js
456e41f4b71Sopenharmony_cilet kvManager;
457e41f4b71Sopenharmony_citry {
458e41f4b71Sopenharmony_ci    kvManager.getAllKVStoreId('appId', function (err, data) {
459e41f4b71Sopenharmony_ci        console.log('GetAllKVStoreId success');
460e41f4b71Sopenharmony_ci        console.log('GetAllKVStoreId size = ' + data.length);
461e41f4b71Sopenharmony_ci    });
462e41f4b71Sopenharmony_ci} catch (e) {
463e41f4b71Sopenharmony_ci    console.log('GetAllKVStoreId e ' + e);
464e41f4b71Sopenharmony_ci}
465e41f4b71Sopenharmony_ci```
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci### getAllKVStoreId<sup>8+</sup>
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_cigetAllKVStoreId(appId: string): Promise&lt;string[]&gt;
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ciObtains the IDs of all KV stores that are created by [getKVStore()](#getkvstore) and have not been deleted by [deleteKVStore()](#deletekvstore8). This API uses a promise to return the result.
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci**Parameters**
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
479e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
480e41f4b71Sopenharmony_ci| appId  | string  | Yes   | Bundle name of the app that invokes the KV store.    |
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ci**Return value**
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_ci| Type         | Description           |
486e41f4b71Sopenharmony_ci| ------------- | -------------- |
487e41f4b71Sopenharmony_ci| Promise&lt;string[]&gt;| Promise used to return the IDs of all created KV stores.|
488e41f4b71Sopenharmony_ci
489e41f4b71Sopenharmony_ci**Example**
490e41f4b71Sopenharmony_ci
491e41f4b71Sopenharmony_ci```js
492e41f4b71Sopenharmony_cilet kvManager;
493e41f4b71Sopenharmony_citry {
494e41f4b71Sopenharmony_ci    console.log('GetAllKVStoreId');
495e41f4b71Sopenharmony_ci    kvManager.getAllKVStoreId('appId').then((data) => {
496e41f4b71Sopenharmony_ci        console.log('getAllKVStoreId success');
497e41f4b71Sopenharmony_ci        console.log('size = ' + data.length);
498e41f4b71Sopenharmony_ci    }).catch((err) => {
499e41f4b71Sopenharmony_ci        console.log('getAllKVStoreId err ' + JSON.stringify(err));
500e41f4b71Sopenharmony_ci    });
501e41f4b71Sopenharmony_ci} catch(e) {
502e41f4b71Sopenharmony_ci    console.log('getAllKVStoreId e ' + e);
503e41f4b71Sopenharmony_ci}
504e41f4b71Sopenharmony_ci```
505e41f4b71Sopenharmony_ci
506e41f4b71Sopenharmony_ci
507e41f4b71Sopenharmony_ci### on('distributedDataServiceDie')<sup>8+</sup>
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_cion(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): void
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ciSubscribes to service status changes.
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
514e41f4b71Sopenharmony_ci
515e41f4b71Sopenharmony_ci**Parameters**
516e41f4b71Sopenharmony_ci
517e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
518e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
519e41f4b71Sopenharmony_ci| event  | string | Yes   | Event type. The value is **distributedDataServiceDie**, which indicates service status changes.|
520e41f4b71Sopenharmony_ci| deathCallback  | Callback&lt;void&gt;  | Yes   | Callback used to return the service status change. |
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ci**Example**
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci```js
525e41f4b71Sopenharmony_cilet kvManager;
526e41f4b71Sopenharmony_citry {
527e41f4b71Sopenharmony_ci    console.log('KVManagerOn');
528e41f4b71Sopenharmony_ci    const deathCallback = function () {
529e41f4b71Sopenharmony_ci        console.log('death callback call');
530e41f4b71Sopenharmony_ci    }
531e41f4b71Sopenharmony_ci    kvManager.on('distributedDataServiceDie', deathCallback);
532e41f4b71Sopenharmony_ci} catch (e) {
533e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
534e41f4b71Sopenharmony_ci}
535e41f4b71Sopenharmony_ci```
536e41f4b71Sopenharmony_ci
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci### off('distributedDataServiceDie')<sup>8+</sup>
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_cioff(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): void
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ciUnsubscribes from service status changes.
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_ci**Parameters**
547e41f4b71Sopenharmony_ci
548e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
549e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
550e41f4b71Sopenharmony_ci| event  | string | Yes   | Event type. The value is **distributedDataServiceDie**, which indicates service status changes.|
551e41f4b71Sopenharmony_ci| deathCallback  | Callback&lt;void&gt;  | No   | Callback to unregister. If this parameter is not specified, all callbacks for **distributedDataServiceDie** will be unregistered.|
552e41f4b71Sopenharmony_ci
553e41f4b71Sopenharmony_ci
554e41f4b71Sopenharmony_ci**Example**
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ci```js
557e41f4b71Sopenharmony_cilet kvManager;
558e41f4b71Sopenharmony_citry {
559e41f4b71Sopenharmony_ci    console.log('KVManagerOff');
560e41f4b71Sopenharmony_ci    const deathCallback = function () {
561e41f4b71Sopenharmony_ci        console.log('death callback call');
562e41f4b71Sopenharmony_ci    }
563e41f4b71Sopenharmony_ci    kvManager.off('distributedDataServiceDie', deathCallback);
564e41f4b71Sopenharmony_ci} catch (e) {
565e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
566e41f4b71Sopenharmony_ci}
567e41f4b71Sopenharmony_ci    
568e41f4b71Sopenharmony_ci```
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ci## Options
571e41f4b71Sopenharmony_ci
572e41f4b71Sopenharmony_ciProvides KV store configuration.
573e41f4b71Sopenharmony_ci
574e41f4b71Sopenharmony_ci
575e41f4b71Sopenharmony_ci| Name | Type| Mandatory  | Description                   |
576e41f4b71Sopenharmony_ci| -----  | ------  | ------  | -------------------|
577e41f4b71Sopenharmony_ci| createIfMissing  | boolean | No| Whether to create a KV store if the database file does not exist. The default value is **true**, which means to create a KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core   |
578e41f4b71Sopenharmony_ci| encrypt  | boolean | No|Whether to encrypt the KV store. The default value is **false**, which means the KV store is not encrypted.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core    |
579e41f4b71Sopenharmony_ci| backup  | boolean | No|Whether to back up the KV store. The default value is **true**, which means to back up the KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core   |
580e41f4b71Sopenharmony_ci| autoSync  | boolean | No|Whether to automatically synchronize database files. The default value is **false**, which means the database files are manually synchronized.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core<br>**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC    |
581e41f4b71Sopenharmony_ci| kvStoreType | [KVStoreType](#kvstoretype) | No|Type of the KV store to create. The default value is **DEVICE_COLLABORATION**, which indicates a device KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
582e41f4b71Sopenharmony_ci| securityLevel | [SecurityLevel](#securitylevel) | No|Security level (S1 to S4) of the KV store.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core |
583e41f4b71Sopenharmony_ci| schema<sup>8+</sup> | [Schema](#schema8) | No| Schema that defines the values stored in the KV store. The default value is **undefined**, which means no schema is used.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ci
586e41f4b71Sopenharmony_ci## KVStoreType
587e41f4b71Sopenharmony_ci
588e41f4b71Sopenharmony_ciEnumerates the KV store types.
589e41f4b71Sopenharmony_ci
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci| Name | Value| Description                   |
592e41f4b71Sopenharmony_ci| ---   | ----  | ----------------------- |
593e41f4b71Sopenharmony_ci| DEVICE_COLLABORATION  | 0 | Device KV store.<br> The device KV store manages data by device, which eliminates conflicts. Data can be queried by device.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore  |
594e41f4b71Sopenharmony_ci| SINGLE_VERSION  | 1 | Single KV store.<br> The single KV store does not differentiate data by device. If the same key is modified by different devices, the data will be overwritten.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core|
595e41f4b71Sopenharmony_ci| MULTI_VERSION   | 2 | Multi-version KV store. This type is not supported currently.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore|
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_ci
598e41f4b71Sopenharmony_ci## SecurityLevel
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ciEnumerates the KV store security levels.
601e41f4b71Sopenharmony_ci
602e41f4b71Sopenharmony_ci| Name | Value| Description                   |
603e41f4b71Sopenharmony_ci| ---   | ----  | ----------------------- |
604e41f4b71Sopenharmony_ci| NO_LEVEL  | 0 | No security level is set for the KV store (deprecated).<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore  |
605e41f4b71Sopenharmony_ci| S0  | 1 | The KV store security level is public (deprecated).<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core   |
606e41f4b71Sopenharmony_ci| S1  | 2 | Low security level. If data leakage occurs, minor impact will be caused. For example, a KV store that contains system data such as wallpapers.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core   |
607e41f4b71Sopenharmony_ci| S2  | 3 | Medium security level. If data leakage occurs, moderate impact will be caused. For example, a KV store that contains information created by users or call records, such as audio or video clips.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core   |
608e41f4b71Sopenharmony_ci| S3  | 5 | High security level. If data leakage occurs, major impact will be caused. For example, a KV store that contains information such as user fitness, health, and location data.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core   |
609e41f4b71Sopenharmony_ci| S4  | 6 | Critical security level. If data leakage occurs, severe impact will be caused. For example, a KV store that contains information such as authentication credentials and financial data.<br>**System capability**: SystemCapability.DistributedDataManager.KVStore.Core   |
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_ci
612e41f4b71Sopenharmony_ci## Constants
613e41f4b71Sopenharmony_ci
614e41f4b71Sopenharmony_ciDefines the KV store constants.
615e41f4b71Sopenharmony_ci
616e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
617e41f4b71Sopenharmony_ci
618e41f4b71Sopenharmony_ci| Name | Value| Description                   |
619e41f4b71Sopenharmony_ci| ---   | ----  | ----------------------- |
620e41f4b71Sopenharmony_ci| MAX_KEY_LENGTH  | 1024 | Maximum length of a key in the KV store, in bytes. |
621e41f4b71Sopenharmony_ci| MAX_VALUE_LENGTH  | 4194303 | Maximum length of a value in the KV store, in bytes. |
622e41f4b71Sopenharmony_ci| MAX_KEY_LENGTH_DEVICE  | 896 | Maximum length of a device key, in bytes.|
623e41f4b71Sopenharmony_ci| MAX_STORE_ID_LENGTH  | 128 | Maximum length of a KV store ID, in bytes. |
624e41f4b71Sopenharmony_ci| MAX_QUERY_LENGTH  | 512000 | Maximum query length, in bytes.|
625e41f4b71Sopenharmony_ci| MAX_BATCH_SIZE  | 128 | Maximum number of batch operations.|
626e41f4b71Sopenharmony_ci
627e41f4b71Sopenharmony_ci## Schema<sup>8+</sup>
628e41f4b71Sopenharmony_ci
629e41f4b71Sopenharmony_ciDefines the schema of a KV store. You can create a **Schema** object and place it in [Options](#options) when creating or opening a KV store.
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ci| Name | Type| Readable| Writable| Description                   |
634e41f4b71Sopenharmony_ci| ---   | ----  | ----  | ----  | ----------------------- |
635e41f4b71Sopenharmony_ci| root<sup>8+</sup>  | [FieldNode](#fieldnode8) | Yes| Yes| JSON root object.|
636e41f4b71Sopenharmony_ci| indexes<sup>8+</sup>  | Array\<string> | Yes| Yes| String array in JSON format. |
637e41f4b71Sopenharmony_ci| mode<sup>8+</sup>  | number | Yes| Yes| Schema mode. |
638e41f4b71Sopenharmony_ci| skip<sup>8+</sup>  | number | Yes| Yes|  Size of a skip of the schema. |
639e41f4b71Sopenharmony_ci
640e41f4b71Sopenharmony_ci### constructor<sup>8+</sup> 
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ciconstructor()
643e41f4b71Sopenharmony_ci
644e41f4b71Sopenharmony_ciA constructor used to create a **Schema** instance.
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
647e41f4b71Sopenharmony_ci
648e41f4b71Sopenharmony_ci## FieldNode<sup>8+</sup>
649e41f4b71Sopenharmony_ci
650e41f4b71Sopenharmony_ciRepresents a **Schema** instance, which provides the APIs for defining the values stored in a KV store.
651e41f4b71Sopenharmony_ci
652e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
653e41f4b71Sopenharmony_ci
654e41f4b71Sopenharmony_ci| Name | Type| Readable| Writable| Description                   |
655e41f4b71Sopenharmony_ci| ---   | ----  | ----  | ----  | ----------------------- |
656e41f4b71Sopenharmony_ci| nullable<sup>8+</sup>  | boolean | Yes| Yes| Whether the database field can be null.  |
657e41f4b71Sopenharmony_ci| default<sup>8+</sup>  | string | Yes| Yes| Default value of a **FieldNode**.|
658e41f4b71Sopenharmony_ci| type<sup>8+</sup>  | number | Yes| Yes| Value of the data type corresponding to the specified node.|
659e41f4b71Sopenharmony_ci
660e41f4b71Sopenharmony_ci### constructor<sup>8+</sup>
661e41f4b71Sopenharmony_ci
662e41f4b71Sopenharmony_ciconstructor(name: string)
663e41f4b71Sopenharmony_ci
664e41f4b71Sopenharmony_ciA constructor used to create a **FieldNode** instance with a string field.
665e41f4b71Sopenharmony_ci
666e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
667e41f4b71Sopenharmony_ci
668e41f4b71Sopenharmony_ci**Parameters**
669e41f4b71Sopenharmony_ci
670e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description           |
671e41f4b71Sopenharmony_ci| ------ | -------- | ---- | --------------- |
672e41f4b71Sopenharmony_ci| name   | string   | Yes  | Value of **FieldNode**.|
673e41f4b71Sopenharmony_ci
674e41f4b71Sopenharmony_ci### appendChild<sup>8+</sup>
675e41f4b71Sopenharmony_ci
676e41f4b71Sopenharmony_ciappendChild(child: FieldNode): boolean
677e41f4b71Sopenharmony_ci
678e41f4b71Sopenharmony_ciAppends a child node to this **FieldNode**.
679e41f4b71Sopenharmony_ci
680e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
681e41f4b71Sopenharmony_ci
682e41f4b71Sopenharmony_ci**Parameters**
683e41f4b71Sopenharmony_ci
684e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
685e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
686e41f4b71Sopenharmony_ci| child  | [FieldNode](#fieldnode8) | Yes   | Child node to append.  |
687e41f4b71Sopenharmony_ci
688e41f4b71Sopenharmony_ci**Return value**
689e41f4b71Sopenharmony_ci
690e41f4b71Sopenharmony_ci| Type         | Description           |
691e41f4b71Sopenharmony_ci| ------------- | -------------- |
692e41f4b71Sopenharmony_ci| boolean |Returns **true** if the operation is successful; returns **false** otherwise.|
693e41f4b71Sopenharmony_ci
694e41f4b71Sopenharmony_ci**Example**
695e41f4b71Sopenharmony_ci
696e41f4b71Sopenharmony_ci```js
697e41f4b71Sopenharmony_ciimport ddm from '@ohos.data.distributedData';
698e41f4b71Sopenharmony_citry {
699e41f4b71Sopenharmony_ci    let node = new ddm.FieldNode("root");
700e41f4b71Sopenharmony_ci    let child1 = new ddm.FieldNode("child1");
701e41f4b71Sopenharmony_ci    let child2 = new ddm.FieldNode("child2");
702e41f4b71Sopenharmony_ci    let child3 = new ddm.FieldNode("child3");
703e41f4b71Sopenharmony_ci    node.appendChild(child1);
704e41f4b71Sopenharmony_ci    node.appendChild(child2);
705e41f4b71Sopenharmony_ci    node.appendChild(child3);
706e41f4b71Sopenharmony_ci    console.log("appendNode " + JSON.stringify(node));
707e41f4b71Sopenharmony_ci    child1 = null;
708e41f4b71Sopenharmony_ci    child2 = null;
709e41f4b71Sopenharmony_ci    child3 = null;
710e41f4b71Sopenharmony_ci    node = null;
711e41f4b71Sopenharmony_ci} catch (e) {
712e41f4b71Sopenharmony_ci    console.log("AppendChild " + e);
713e41f4b71Sopenharmony_ci}
714e41f4b71Sopenharmony_ci```
715e41f4b71Sopenharmony_ci
716e41f4b71Sopenharmony_ci
717e41f4b71Sopenharmony_ci## KvStoreResultSet<sup>8+</sup>
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ciProvides APIs to obtain the KV store result sets, and query and move the data read position.
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ciBefore calling any method in **KvStoreResultSet**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object.
722e41f4b71Sopenharmony_ci
723e41f4b71Sopenharmony_ci
724e41f4b71Sopenharmony_ci### getCount<sup>8+</sup>
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_cigetCount(): number
727e41f4b71Sopenharmony_ci
728e41f4b71Sopenharmony_ciObtains the total number of rows in the result set.
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
731e41f4b71Sopenharmony_ci
732e41f4b71Sopenharmony_ci**Return value**
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci| Type  | Description              |
735e41f4b71Sopenharmony_ci| ------ | --------------    |
736e41f4b71Sopenharmony_ci| number |Total number of rows obtained.         |
737e41f4b71Sopenharmony_ci
738e41f4b71Sopenharmony_ci**Example**
739e41f4b71Sopenharmony_ci
740e41f4b71Sopenharmony_ci```js
741e41f4b71Sopenharmony_cilet kvStore;
742e41f4b71Sopenharmony_citry {
743e41f4b71Sopenharmony_ci    let resultSet;
744e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
745e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
746e41f4b71Sopenharmony_ci        resultSet = result;
747e41f4b71Sopenharmony_ci    }).catch((err) => {
748e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
749e41f4b71Sopenharmony_ci    });
750e41f4b71Sopenharmony_ci    const count = resultSet.getCount();
751e41f4b71Sopenharmony_ci    console.log("getCount succeed:" + count);
752e41f4b71Sopenharmony_ci} catch (e) {
753e41f4b71Sopenharmony_ci    console.log("getCount failed: " + e);
754e41f4b71Sopenharmony_ci}
755e41f4b71Sopenharmony_ci```
756e41f4b71Sopenharmony_ci
757e41f4b71Sopenharmony_ci### getPosition<sup>8+</sup>
758e41f4b71Sopenharmony_ci
759e41f4b71Sopenharmony_cigetPosition(): number
760e41f4b71Sopenharmony_ci
761e41f4b71Sopenharmony_ciObtains the current data read position (position from which data is read) in the result set.
762e41f4b71Sopenharmony_ci
763e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
764e41f4b71Sopenharmony_ci
765e41f4b71Sopenharmony_ci**Return value**
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci| Type  | Description              |
768e41f4b71Sopenharmony_ci| ------ | --------------    |
769e41f4b71Sopenharmony_ci| number |Current data read position obtained.  |
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci**Example**
772e41f4b71Sopenharmony_ci
773e41f4b71Sopenharmony_ci```js
774e41f4b71Sopenharmony_cilet kvStore;
775e41f4b71Sopenharmony_citry {
776e41f4b71Sopenharmony_ci    let resultSet;
777e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
778e41f4b71Sopenharmony_ci        console.log('getResultSet succeeded.');
779e41f4b71Sopenharmony_ci        resultSet = result;
780e41f4b71Sopenharmony_ci    }).catch((err) => {
781e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
782e41f4b71Sopenharmony_ci    });
783e41f4b71Sopenharmony_ci    const position = resultSet.getPosition();
784e41f4b71Sopenharmony_ci    console.log("getPosition succeed:" + position);
785e41f4b71Sopenharmony_ci} catch (e) {
786e41f4b71Sopenharmony_ci    console.log("getPosition failed: " + e);
787e41f4b71Sopenharmony_ci}
788e41f4b71Sopenharmony_ci```
789e41f4b71Sopenharmony_ci
790e41f4b71Sopenharmony_ci
791e41f4b71Sopenharmony_ci### moveToFirst<sup>8+</sup>
792e41f4b71Sopenharmony_ci
793e41f4b71Sopenharmony_cimoveToFirst(): boolean
794e41f4b71Sopenharmony_ci
795e41f4b71Sopenharmony_ciMoves the data read position to the first row. If the result set is empty, **false** will be returned.
796e41f4b71Sopenharmony_ci
797e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
798e41f4b71Sopenharmony_ci
799e41f4b71Sopenharmony_ci**Return value**
800e41f4b71Sopenharmony_ci
801e41f4b71Sopenharmony_ci| Type   | Description              |
802e41f4b71Sopenharmony_ci| ------  | --------------    |
803e41f4b71Sopenharmony_ci| boolean |Returns **true** if the operation is successful; returns **false** otherwise.  |
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_ci**Example**
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_ci```js
808e41f4b71Sopenharmony_cilet kvStore;
809e41f4b71Sopenharmony_citry {
810e41f4b71Sopenharmony_ci    let resultSet;
811e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
812e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
813e41f4b71Sopenharmony_ci        resultSet = result;
814e41f4b71Sopenharmony_ci    }).catch((err) => {
815e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
816e41f4b71Sopenharmony_ci    });
817e41f4b71Sopenharmony_ci    const moved1 = resultSet.moveToFirst();
818e41f4b71Sopenharmony_ci    console.log("moveToFirst succeed: " + moved1);
819e41f4b71Sopenharmony_ci} catch (e) {
820e41f4b71Sopenharmony_ci    console.log("moveToFirst failed " + e);
821e41f4b71Sopenharmony_ci}
822e41f4b71Sopenharmony_ci```
823e41f4b71Sopenharmony_ci
824e41f4b71Sopenharmony_ci
825e41f4b71Sopenharmony_ci### moveToLast<sup>8+</sup>
826e41f4b71Sopenharmony_ci
827e41f4b71Sopenharmony_cimoveToLast(): boolean
828e41f4b71Sopenharmony_ci
829e41f4b71Sopenharmony_ciMoves the data read position to the last row. If the result set is empty, **false** will be returned.
830e41f4b71Sopenharmony_ci
831e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
832e41f4b71Sopenharmony_ci
833e41f4b71Sopenharmony_ci**Return value**
834e41f4b71Sopenharmony_ci
835e41f4b71Sopenharmony_ci| Type   | Description              |
836e41f4b71Sopenharmony_ci| ------  | --------------    |
837e41f4b71Sopenharmony_ci| boolean |Returns **true** if the operation is successful; returns **false** otherwise.  |
838e41f4b71Sopenharmony_ci
839e41f4b71Sopenharmony_ci**Example**
840e41f4b71Sopenharmony_ci
841e41f4b71Sopenharmony_ci```js
842e41f4b71Sopenharmony_cilet kvStore;
843e41f4b71Sopenharmony_citry {
844e41f4b71Sopenharmony_ci    let resultSet;
845e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
846e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
847e41f4b71Sopenharmony_ci        resultSet = result;
848e41f4b71Sopenharmony_ci    }).catch((err) => {
849e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
850e41f4b71Sopenharmony_ci    });
851e41f4b71Sopenharmony_ci    const moved2 = resultSet.moveToLast();
852e41f4b71Sopenharmony_ci    console.log("moveToLast succeed:" + moved2);
853e41f4b71Sopenharmony_ci} catch (e) {
854e41f4b71Sopenharmony_ci    console.log("moveToLast failed: " + e);
855e41f4b71Sopenharmony_ci}
856e41f4b71Sopenharmony_ci```
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ci
859e41f4b71Sopenharmony_ci### moveToNext<sup>8+</sup>
860e41f4b71Sopenharmony_ci
861e41f4b71Sopenharmony_cimoveToNext(): boolean
862e41f4b71Sopenharmony_ci
863e41f4b71Sopenharmony_ciMoves the data read position to the next row. If the result set is empty, **false** will be returned.
864e41f4b71Sopenharmony_ci
865e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
866e41f4b71Sopenharmony_ci
867e41f4b71Sopenharmony_ci**Return value**
868e41f4b71Sopenharmony_ci
869e41f4b71Sopenharmony_ci| Type   | Description              |
870e41f4b71Sopenharmony_ci| ------  | --------------    |
871e41f4b71Sopenharmony_ci| boolean |Returns **true** if the operation is successful; returns **false** otherwise.  |
872e41f4b71Sopenharmony_ci
873e41f4b71Sopenharmony_ci**Example**
874e41f4b71Sopenharmony_ci
875e41f4b71Sopenharmony_ci```js
876e41f4b71Sopenharmony_cilet kvStore;
877e41f4b71Sopenharmony_citry {
878e41f4b71Sopenharmony_ci    let resultSet;
879e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
880e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
881e41f4b71Sopenharmony_ci        resultSet = result;
882e41f4b71Sopenharmony_ci    }).catch((err) => {
883e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
884e41f4b71Sopenharmony_ci    });
885e41f4b71Sopenharmony_ci    const moved3 = resultSet.moveToNext();
886e41f4b71Sopenharmony_ci    console.log("moveToNext succeed: " + moved3);
887e41f4b71Sopenharmony_ci} catch (e) {
888e41f4b71Sopenharmony_ci    console.log("moveToNext failed: " + e);
889e41f4b71Sopenharmony_ci}
890e41f4b71Sopenharmony_ci```
891e41f4b71Sopenharmony_ci
892e41f4b71Sopenharmony_ci
893e41f4b71Sopenharmony_ci### moveToPrevious<sup>8+</sup>
894e41f4b71Sopenharmony_ci
895e41f4b71Sopenharmony_cimoveToPrevious(): boolean
896e41f4b71Sopenharmony_ci
897e41f4b71Sopenharmony_ciMoves the data read position to the previous row. If the result set is empty, **false** will be returned.
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
900e41f4b71Sopenharmony_ci
901e41f4b71Sopenharmony_ci**Return value**
902e41f4b71Sopenharmony_ci
903e41f4b71Sopenharmony_ci| Type   | Description              |
904e41f4b71Sopenharmony_ci| ------  | --------------    |
905e41f4b71Sopenharmony_ci| boolean |Returns **true** if the operation is successful; returns **false** otherwise.  |
906e41f4b71Sopenharmony_ci
907e41f4b71Sopenharmony_ci**Example**
908e41f4b71Sopenharmony_ci
909e41f4b71Sopenharmony_ci```js
910e41f4b71Sopenharmony_cilet kvStore;
911e41f4b71Sopenharmony_citry {
912e41f4b71Sopenharmony_ci    let resultSet;
913e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
914e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
915e41f4b71Sopenharmony_ci        resultSet = result;
916e41f4b71Sopenharmony_ci    }).catch((err) => {
917e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
918e41f4b71Sopenharmony_ci    });
919e41f4b71Sopenharmony_ci    const moved4 = resultSet.moveToPrevious();
920e41f4b71Sopenharmony_ci    console.log("moveToPrevious succeed:" + moved4);
921e41f4b71Sopenharmony_ci} catch (e) {
922e41f4b71Sopenharmony_ci    console.log("moveToPrevious failed: " + e);
923e41f4b71Sopenharmony_ci}
924e41f4b71Sopenharmony_ci```
925e41f4b71Sopenharmony_ci
926e41f4b71Sopenharmony_ci
927e41f4b71Sopenharmony_ci### move<sup>8+</sup>
928e41f4b71Sopenharmony_ci
929e41f4b71Sopenharmony_cimove(offset: number): boolean
930e41f4b71Sopenharmony_ci
931e41f4b71Sopenharmony_ciMoves the data read position with the specified offset from the current position.
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
934e41f4b71Sopenharmony_ci
935e41f4b71Sopenharmony_ci**Parameters**
936e41f4b71Sopenharmony_ci
937e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
938e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
939e41f4b71Sopenharmony_ci| offset  | number  | Yes   | Offset to move the data read position. A negative value means to move backward, and a positive value means to move forward.  |
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ci**Return value**
942e41f4b71Sopenharmony_ci
943e41f4b71Sopenharmony_ci| Type   | Description              |
944e41f4b71Sopenharmony_ci| ------  | --------------    |
945e41f4b71Sopenharmony_ci| boolean |Returns **true** if the operation is successful; returns **false** otherwise.  |
946e41f4b71Sopenharmony_ci
947e41f4b71Sopenharmony_ci**Example**
948e41f4b71Sopenharmony_ci
949e41f4b71Sopenharmony_ci```js
950e41f4b71Sopenharmony_cilet kvStore;
951e41f4b71Sopenharmony_citry {
952e41f4b71Sopenharmony_ci    let resultSet;
953e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
954e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
955e41f4b71Sopenharmony_ci        resultSet = result;
956e41f4b71Sopenharmony_ci    }).catch((err) => {
957e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
958e41f4b71Sopenharmony_ci    });
959e41f4b71Sopenharmony_ci    const moved5 = resultSet.move(1);
960e41f4b71Sopenharmony_ci    console.log("move succeed:" + moved5);
961e41f4b71Sopenharmony_ci} catch (e) {
962e41f4b71Sopenharmony_ci    console.log("move failed: " + e);
963e41f4b71Sopenharmony_ci}
964e41f4b71Sopenharmony_ci```
965e41f4b71Sopenharmony_ci
966e41f4b71Sopenharmony_ci
967e41f4b71Sopenharmony_ci### moveToPosition<sup>8+</sup>
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_cimoveToPosition(position: number): boolean
970e41f4b71Sopenharmony_ci
971e41f4b71Sopenharmony_ciMoves the data read position from 0 to an absolute position.
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
974e41f4b71Sopenharmony_ci
975e41f4b71Sopenharmony_ci**Parameters**
976e41f4b71Sopenharmony_ci
977e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
978e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
979e41f4b71Sopenharmony_ci| position  | number  | Yes   |Absolute position to move to.         |
980e41f4b71Sopenharmony_ci
981e41f4b71Sopenharmony_ci**Return value**
982e41f4b71Sopenharmony_ci
983e41f4b71Sopenharmony_ci| Type   | Description              |
984e41f4b71Sopenharmony_ci| ------  | --------------    |
985e41f4b71Sopenharmony_ci| boolean |Returns **true** if the operation is successful; returns **false** otherwise.  |
986e41f4b71Sopenharmony_ci
987e41f4b71Sopenharmony_ci**Example**
988e41f4b71Sopenharmony_ci
989e41f4b71Sopenharmony_ci```js
990e41f4b71Sopenharmony_cilet kvStore;
991e41f4b71Sopenharmony_citry {
992e41f4b71Sopenharmony_ci    let resultSet;
993e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
994e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
995e41f4b71Sopenharmony_ci        resultSet = result;
996e41f4b71Sopenharmony_ci    }).catch((err) => {
997e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
998e41f4b71Sopenharmony_ci    });
999e41f4b71Sopenharmony_ci    const moved6 = resultSet.moveToPosition(1);
1000e41f4b71Sopenharmony_ci    console.log("moveToPosition succeed: " + moved6);
1001e41f4b71Sopenharmony_ci} catch (e) {
1002e41f4b71Sopenharmony_ci    console.log("moveToPosition failed: " + e);
1003e41f4b71Sopenharmony_ci}
1004e41f4b71Sopenharmony_ci```
1005e41f4b71Sopenharmony_ci
1006e41f4b71Sopenharmony_ci
1007e41f4b71Sopenharmony_ci### isFirst<sup>8+</sup>
1008e41f4b71Sopenharmony_ci
1009e41f4b71Sopenharmony_ciisFirst(): boolean
1010e41f4b71Sopenharmony_ci
1011e41f4b71Sopenharmony_ciChecks whether the data read position is the first row.
1012e41f4b71Sopenharmony_ci
1013e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_ci**Return value**
1016e41f4b71Sopenharmony_ci
1017e41f4b71Sopenharmony_ci| Type   | Description              |
1018e41f4b71Sopenharmony_ci| ------  | --------------    |
1019e41f4b71Sopenharmony_ci| boolean |Returns **true** if the first row is being read; returns **false** otherwise.  |
1020e41f4b71Sopenharmony_ci
1021e41f4b71Sopenharmony_ci**Example**
1022e41f4b71Sopenharmony_ci
1023e41f4b71Sopenharmony_ci```js
1024e41f4b71Sopenharmony_cilet kvStore;
1025e41f4b71Sopenharmony_citry {
1026e41f4b71Sopenharmony_ci    let resultSet;
1027e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
1028e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
1029e41f4b71Sopenharmony_ci        resultSet = result;
1030e41f4b71Sopenharmony_ci    }).catch((err) => {
1031e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
1032e41f4b71Sopenharmony_ci    });
1033e41f4b71Sopenharmony_ci    const isfirst = resultSet.isFirst();
1034e41f4b71Sopenharmony_ci    console.log("Check isFirst succeed:" + isfirst);
1035e41f4b71Sopenharmony_ci} catch (e) {
1036e41f4b71Sopenharmony_ci    console.log("Check isFirst failed: " + e);
1037e41f4b71Sopenharmony_ci}
1038e41f4b71Sopenharmony_ci```
1039e41f4b71Sopenharmony_ci
1040e41f4b71Sopenharmony_ci
1041e41f4b71Sopenharmony_ci### isLast<sup>8+</sup>
1042e41f4b71Sopenharmony_ci
1043e41f4b71Sopenharmony_ciisLast(): boolean
1044e41f4b71Sopenharmony_ci
1045e41f4b71Sopenharmony_ciChecks whether the data read position is the last row.
1046e41f4b71Sopenharmony_ci
1047e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1048e41f4b71Sopenharmony_ci
1049e41f4b71Sopenharmony_ci**Return value**
1050e41f4b71Sopenharmony_ci
1051e41f4b71Sopenharmony_ci| Type   | Description              |
1052e41f4b71Sopenharmony_ci| ------  | --------------    |
1053e41f4b71Sopenharmony_ci| boolean |Returns **true** if the last row is being read; returns **false** otherwise.  |
1054e41f4b71Sopenharmony_ci
1055e41f4b71Sopenharmony_ci**Example**
1056e41f4b71Sopenharmony_ci
1057e41f4b71Sopenharmony_ci```js
1058e41f4b71Sopenharmony_cilet kvStore;
1059e41f4b71Sopenharmony_citry {
1060e41f4b71Sopenharmony_ci    let resultSet;
1061e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
1062e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
1063e41f4b71Sopenharmony_ci        resultSet = result;
1064e41f4b71Sopenharmony_ci    }).catch((err) => {
1065e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
1066e41f4b71Sopenharmony_ci    });
1067e41f4b71Sopenharmony_ci    const islast = resultSet.isLast();
1068e41f4b71Sopenharmony_ci    console.log("Check isLast succeed: " + islast);
1069e41f4b71Sopenharmony_ci} catch (e) {
1070e41f4b71Sopenharmony_ci    console.log("Check isLast failed: " + e);
1071e41f4b71Sopenharmony_ci}
1072e41f4b71Sopenharmony_ci```
1073e41f4b71Sopenharmony_ci
1074e41f4b71Sopenharmony_ci### isBeforeFirst<sup>8+</sup>
1075e41f4b71Sopenharmony_ci
1076e41f4b71Sopenharmony_ciisBeforeFirst(): boolean
1077e41f4b71Sopenharmony_ci
1078e41f4b71Sopenharmony_ciChecks whether the data read position is before the first row.
1079e41f4b71Sopenharmony_ci
1080e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1081e41f4b71Sopenharmony_ci
1082e41f4b71Sopenharmony_ci**Return value**
1083e41f4b71Sopenharmony_ci
1084e41f4b71Sopenharmony_ci| Type   | Description              |
1085e41f4b71Sopenharmony_ci| ------  | --------------    |
1086e41f4b71Sopenharmony_ci| boolean |Returns **true** if the data read position is before the first row; returns **false** otherwise. |
1087e41f4b71Sopenharmony_ci
1088e41f4b71Sopenharmony_ci**Example**
1089e41f4b71Sopenharmony_ci
1090e41f4b71Sopenharmony_ci```js
1091e41f4b71Sopenharmony_cilet kvStore;
1092e41f4b71Sopenharmony_citry {
1093e41f4b71Sopenharmony_ci    let resultSet;
1094e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
1095e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
1096e41f4b71Sopenharmony_ci        resultSet = result;
1097e41f4b71Sopenharmony_ci    }).catch((err) => {
1098e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
1099e41f4b71Sopenharmony_ci    });
1100e41f4b71Sopenharmony_ci    const isbeforefirst = resultSet.isBeforeFirst();
1101e41f4b71Sopenharmony_ci    console.log("Check isBeforeFirst succeed: " + isbeforefirst);
1102e41f4b71Sopenharmony_ci} catch (e) {
1103e41f4b71Sopenharmony_ci    console.log("Check isBeforeFirst failed: " + e);
1104e41f4b71Sopenharmony_ci}
1105e41f4b71Sopenharmony_ci```
1106e41f4b71Sopenharmony_ci
1107e41f4b71Sopenharmony_ci
1108e41f4b71Sopenharmony_ci### isAfterLast<sup>8+</sup>
1109e41f4b71Sopenharmony_ci
1110e41f4b71Sopenharmony_ciisAfterLast(): boolean
1111e41f4b71Sopenharmony_ci
1112e41f4b71Sopenharmony_ciChecks whether the data read position is after the last row.
1113e41f4b71Sopenharmony_ci
1114e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1115e41f4b71Sopenharmony_ci
1116e41f4b71Sopenharmony_ci**Return value**
1117e41f4b71Sopenharmony_ci
1118e41f4b71Sopenharmony_ci| Type   | Description              |
1119e41f4b71Sopenharmony_ci| ------  | --------------    |
1120e41f4b71Sopenharmony_ci| boolean |Returns **true** if the data read position is after the last row; returns **false** otherwise. |
1121e41f4b71Sopenharmony_ci
1122e41f4b71Sopenharmony_ci**Example**
1123e41f4b71Sopenharmony_ci
1124e41f4b71Sopenharmony_ci```js
1125e41f4b71Sopenharmony_cilet kvStore;
1126e41f4b71Sopenharmony_citry {
1127e41f4b71Sopenharmony_ci    let resultSet;
1128e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
1129e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
1130e41f4b71Sopenharmony_ci        resultSet = result;
1131e41f4b71Sopenharmony_ci    }).catch((err) => {
1132e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
1133e41f4b71Sopenharmony_ci    });
1134e41f4b71Sopenharmony_ci    const isafterlast = resultSet.isAfterLast();
1135e41f4b71Sopenharmony_ci    console.log("Check isAfterLast succeed:" + isafterlast);
1136e41f4b71Sopenharmony_ci} catch (e) {
1137e41f4b71Sopenharmony_ci    console.log("Check isAfterLast failed: " + e);
1138e41f4b71Sopenharmony_ci}
1139e41f4b71Sopenharmony_ci```
1140e41f4b71Sopenharmony_ci
1141e41f4b71Sopenharmony_ci
1142e41f4b71Sopenharmony_ci### getEntry<sup>8+</sup>
1143e41f4b71Sopenharmony_ci
1144e41f4b71Sopenharmony_cigetEntry(): Entry
1145e41f4b71Sopenharmony_ci
1146e41f4b71Sopenharmony_ciObtains the KV pair from the current position.
1147e41f4b71Sopenharmony_ci
1148e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1149e41f4b71Sopenharmony_ci
1150e41f4b71Sopenharmony_ci**Return value**
1151e41f4b71Sopenharmony_ci
1152e41f4b71Sopenharmony_ci| Type   | Description      |
1153e41f4b71Sopenharmony_ci| ------  | -------   |
1154e41f4b71Sopenharmony_ci| [Entry](#entry) |KV pair obtained.|
1155e41f4b71Sopenharmony_ci
1156e41f4b71Sopenharmony_ci**Example**
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ci```js
1159e41f4b71Sopenharmony_cilet kvStore;
1160e41f4b71Sopenharmony_citry {
1161e41f4b71Sopenharmony_ci    let resultSet;
1162e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
1163e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
1164e41f4b71Sopenharmony_ci        resultSet = result;
1165e41f4b71Sopenharmony_ci    }).catch((err) => {
1166e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + err);
1167e41f4b71Sopenharmony_ci    });
1168e41f4b71Sopenharmony_ci    const entry  = resultSet.getEntry();
1169e41f4b71Sopenharmony_ci    console.log("getEntry succeed:" + JSON.stringify(entry));
1170e41f4b71Sopenharmony_ci} catch (e) {
1171e41f4b71Sopenharmony_ci    console.log("getEntry failed: " + e);
1172e41f4b71Sopenharmony_ci}
1173e41f4b71Sopenharmony_ci```
1174e41f4b71Sopenharmony_ci
1175e41f4b71Sopenharmony_ci
1176e41f4b71Sopenharmony_ci## Query<sup>8+</sup>
1177e41f4b71Sopenharmony_ci
1178e41f4b71Sopenharmony_ciProvides APIs to create a **Query** object, which defines different data query criteria.
1179e41f4b71Sopenharmony_ci
1180e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1181e41f4b71Sopenharmony_ci
1182e41f4b71Sopenharmony_ci### constructor<sup>8+</sup>
1183e41f4b71Sopenharmony_ci
1184e41f4b71Sopenharmony_ciconstructor() 
1185e41f4b71Sopenharmony_ci
1186e41f4b71Sopenharmony_ciA constructor used to create a **Schema** instance.
1187e41f4b71Sopenharmony_ci
1188e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1189e41f4b71Sopenharmony_ci
1190e41f4b71Sopenharmony_ci
1191e41f4b71Sopenharmony_ci### reset<sup>8+</sup>
1192e41f4b71Sopenharmony_ci
1193e41f4b71Sopenharmony_cireset(): Query
1194e41f4b71Sopenharmony_ci
1195e41f4b71Sopenharmony_ciResets the **Query** object.
1196e41f4b71Sopenharmony_ci
1197e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1198e41f4b71Sopenharmony_ci
1199e41f4b71Sopenharmony_ci
1200e41f4b71Sopenharmony_ci**Return value**
1201e41f4b71Sopenharmony_ci
1202e41f4b71Sopenharmony_ci| Type   | Description      |
1203e41f4b71Sopenharmony_ci| ------  | -------   |
1204e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object reset.|
1205e41f4b71Sopenharmony_ci
1206e41f4b71Sopenharmony_ci**Example**
1207e41f4b71Sopenharmony_ci
1208e41f4b71Sopenharmony_ci```js
1209e41f4b71Sopenharmony_citry {
1210e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1211e41f4b71Sopenharmony_ci    query.equalTo("key", "value");
1212e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1213e41f4b71Sopenharmony_ci    query.reset();
1214e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1215e41f4b71Sopenharmony_ci    query = null;
1216e41f4b71Sopenharmony_ci} catch (e) {
1217e41f4b71Sopenharmony_ci    console.log("simply calls should be ok :" + e);
1218e41f4b71Sopenharmony_ci}
1219e41f4b71Sopenharmony_ci```
1220e41f4b71Sopenharmony_ci
1221e41f4b71Sopenharmony_ci
1222e41f4b71Sopenharmony_ci### equalTo<sup>8+</sup>
1223e41f4b71Sopenharmony_ci
1224e41f4b71Sopenharmony_ciequalTo(field: string, value: number|string|boolean): Query
1225e41f4b71Sopenharmony_ci
1226e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is equal to the given value.
1227e41f4b71Sopenharmony_ci
1228e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1229e41f4b71Sopenharmony_ci
1230e41f4b71Sopenharmony_ci**Parameters**
1231e41f4b71Sopenharmony_ci
1232e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1233e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1234e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1235e41f4b71Sopenharmony_ci| value  | number\|string\|boolean  | Yes   | Value specified.|
1236e41f4b71Sopenharmony_ci
1237e41f4b71Sopenharmony_ci**Return value**
1238e41f4b71Sopenharmony_ci
1239e41f4b71Sopenharmony_ci| Type   | Description      |
1240e41f4b71Sopenharmony_ci| ------  | -------   |
1241e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1242e41f4b71Sopenharmony_ci
1243e41f4b71Sopenharmony_ci**Example**
1244e41f4b71Sopenharmony_ci
1245e41f4b71Sopenharmony_ci```js
1246e41f4b71Sopenharmony_citry {
1247e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1248e41f4b71Sopenharmony_ci    query.equalTo("field", "value");
1249e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1250e41f4b71Sopenharmony_ci    query = null;
1251e41f4b71Sopenharmony_ci} catch (e) {
1252e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1253e41f4b71Sopenharmony_ci}
1254e41f4b71Sopenharmony_ci```
1255e41f4b71Sopenharmony_ci
1256e41f4b71Sopenharmony_ci
1257e41f4b71Sopenharmony_ci### notEqualTo<sup>8+</sup>
1258e41f4b71Sopenharmony_ci
1259e41f4b71Sopenharmony_cinotEqualTo(field: string, value: number|string|boolean): Query
1260e41f4b71Sopenharmony_ci
1261e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is not equal to the specified value.
1262e41f4b71Sopenharmony_ci
1263e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1264e41f4b71Sopenharmony_ci
1265e41f4b71Sopenharmony_ci**Parameters**
1266e41f4b71Sopenharmony_ci
1267e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1268e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1269e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1270e41f4b71Sopenharmony_ci| value  | number\|string\|boolean  | Yes   | Value specified.|
1271e41f4b71Sopenharmony_ci
1272e41f4b71Sopenharmony_ci**Return value**
1273e41f4b71Sopenharmony_ci
1274e41f4b71Sopenharmony_ci| Type   | Description      |
1275e41f4b71Sopenharmony_ci| ------  | -------   |
1276e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1277e41f4b71Sopenharmony_ci
1278e41f4b71Sopenharmony_ci**Example**
1279e41f4b71Sopenharmony_ci
1280e41f4b71Sopenharmony_ci```js
1281e41f4b71Sopenharmony_citry {
1282e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1283e41f4b71Sopenharmony_ci    query.notEqualTo("field", "value");
1284e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1285e41f4b71Sopenharmony_ci    query = null;
1286e41f4b71Sopenharmony_ci} catch (e) {
1287e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1288e41f4b71Sopenharmony_ci}
1289e41f4b71Sopenharmony_ci```
1290e41f4b71Sopenharmony_ci
1291e41f4b71Sopenharmony_ci
1292e41f4b71Sopenharmony_ci### greaterThan<sup>8+</sup>
1293e41f4b71Sopenharmony_ci
1294e41f4b71Sopenharmony_cigreaterThan(field: string, value: number|string|boolean): Query
1295e41f4b71Sopenharmony_ci
1296e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is greater than the specified value.
1297e41f4b71Sopenharmony_ci
1298e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1299e41f4b71Sopenharmony_ci
1300e41f4b71Sopenharmony_ci**Parameters**
1301e41f4b71Sopenharmony_ci
1302e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1303e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1304e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1305e41f4b71Sopenharmony_ci| value  | number\|string\|boolean  | Yes   | Value specified.|
1306e41f4b71Sopenharmony_ci
1307e41f4b71Sopenharmony_ci**Return value**
1308e41f4b71Sopenharmony_ci
1309e41f4b71Sopenharmony_ci| Type   | Description      |
1310e41f4b71Sopenharmony_ci| ------  | -------   |
1311e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1312e41f4b71Sopenharmony_ci
1313e41f4b71Sopenharmony_ci**Example**
1314e41f4b71Sopenharmony_ci
1315e41f4b71Sopenharmony_ci```js
1316e41f4b71Sopenharmony_citry {
1317e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1318e41f4b71Sopenharmony_ci    query.greaterThan("field", "value");
1319e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1320e41f4b71Sopenharmony_ci    query = null;
1321e41f4b71Sopenharmony_ci} catch (e) {
1322e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1323e41f4b71Sopenharmony_ci}
1324e41f4b71Sopenharmony_ci```
1325e41f4b71Sopenharmony_ci
1326e41f4b71Sopenharmony_ci
1327e41f4b71Sopenharmony_ci### lessThan<sup>8+</sup>
1328e41f4b71Sopenharmony_ci
1329e41f4b71Sopenharmony_cilessThan(field: string, value: number|string): Query
1330e41f4b71Sopenharmony_ci
1331e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is less than the specified value.
1332e41f4b71Sopenharmony_ci
1333e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1334e41f4b71Sopenharmony_ci
1335e41f4b71Sopenharmony_ci**Parameters**
1336e41f4b71Sopenharmony_ci
1337e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1338e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1339e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1340e41f4b71Sopenharmony_ci| value  | number\|string  | Yes   | Value specified.|
1341e41f4b71Sopenharmony_ci
1342e41f4b71Sopenharmony_ci**Return value**
1343e41f4b71Sopenharmony_ci
1344e41f4b71Sopenharmony_ci| Type   | Description      |
1345e41f4b71Sopenharmony_ci| ------  | -------   |
1346e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1347e41f4b71Sopenharmony_ci
1348e41f4b71Sopenharmony_ci**Example**
1349e41f4b71Sopenharmony_ci
1350e41f4b71Sopenharmony_ci```js
1351e41f4b71Sopenharmony_citry {
1352e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1353e41f4b71Sopenharmony_ci    query.lessThan("field", "value");
1354e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1355e41f4b71Sopenharmony_ci    query = null;
1356e41f4b71Sopenharmony_ci} catch (e) {
1357e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1358e41f4b71Sopenharmony_ci}
1359e41f4b71Sopenharmony_ci```
1360e41f4b71Sopenharmony_ci
1361e41f4b71Sopenharmony_ci
1362e41f4b71Sopenharmony_ci### greaterThanOrEqualTo<sup>8+</sup>
1363e41f4b71Sopenharmony_ci
1364e41f4b71Sopenharmony_cigreaterThanOrEqualTo(field: string, value: number|string): Query
1365e41f4b71Sopenharmony_ci
1366e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is greater than or equal to the specified value.
1367e41f4b71Sopenharmony_ci
1368e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1369e41f4b71Sopenharmony_ci
1370e41f4b71Sopenharmony_ci**Parameters**
1371e41f4b71Sopenharmony_ci
1372e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1373e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1374e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1375e41f4b71Sopenharmony_ci| value  | number\|string  | Yes   | Value specified.|
1376e41f4b71Sopenharmony_ci
1377e41f4b71Sopenharmony_ci**Return value**
1378e41f4b71Sopenharmony_ci
1379e41f4b71Sopenharmony_ci| Type   | Description      |
1380e41f4b71Sopenharmony_ci| ------  | -------   |
1381e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1382e41f4b71Sopenharmony_ci
1383e41f4b71Sopenharmony_ci**Example**
1384e41f4b71Sopenharmony_ci
1385e41f4b71Sopenharmony_ci```js
1386e41f4b71Sopenharmony_citry {
1387e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1388e41f4b71Sopenharmony_ci    query.greaterThanOrEqualTo("field", "value");
1389e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1390e41f4b71Sopenharmony_ci    query = null;
1391e41f4b71Sopenharmony_ci} catch (e) {
1392e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1393e41f4b71Sopenharmony_ci}
1394e41f4b71Sopenharmony_ci```
1395e41f4b71Sopenharmony_ci
1396e41f4b71Sopenharmony_ci
1397e41f4b71Sopenharmony_ci### lessThanOrEqualTo<sup>8+</sup>
1398e41f4b71Sopenharmony_ci
1399e41f4b71Sopenharmony_cilessThanOrEqualTo(field: string, value: number|string): Query
1400e41f4b71Sopenharmony_ci
1401e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is less than or equal to the specified value.
1402e41f4b71Sopenharmony_ci
1403e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1404e41f4b71Sopenharmony_ci
1405e41f4b71Sopenharmony_ci**Parameters**
1406e41f4b71Sopenharmony_ci
1407e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1408e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1409e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1410e41f4b71Sopenharmony_ci| value  | number\|string  | Yes   | Value specified.|
1411e41f4b71Sopenharmony_ci
1412e41f4b71Sopenharmony_ci**Return value**
1413e41f4b71Sopenharmony_ci
1414e41f4b71Sopenharmony_ci| Type   | Description      |
1415e41f4b71Sopenharmony_ci| ------  | -------   |
1416e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1417e41f4b71Sopenharmony_ci
1418e41f4b71Sopenharmony_ci**Example**
1419e41f4b71Sopenharmony_ci
1420e41f4b71Sopenharmony_ci```js
1421e41f4b71Sopenharmony_citry {
1422e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1423e41f4b71Sopenharmony_ci    query.lessThanOrEqualTo("field", "value");
1424e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1425e41f4b71Sopenharmony_ci    query = null;
1426e41f4b71Sopenharmony_ci} catch (e) {
1427e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1428e41f4b71Sopenharmony_ci}
1429e41f4b71Sopenharmony_ci```
1430e41f4b71Sopenharmony_ci
1431e41f4b71Sopenharmony_ci
1432e41f4b71Sopenharmony_ci### isNull<sup>8+</sup>
1433e41f4b71Sopenharmony_ci
1434e41f4b71Sopenharmony_ciisNull(field: string): Query
1435e41f4b71Sopenharmony_ci
1436e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is **null**.
1437e41f4b71Sopenharmony_ci
1438e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1439e41f4b71Sopenharmony_ci
1440e41f4b71Sopenharmony_ci**Parameters**
1441e41f4b71Sopenharmony_ci
1442e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1443e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1444e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1445e41f4b71Sopenharmony_ci
1446e41f4b71Sopenharmony_ci**Return value**
1447e41f4b71Sopenharmony_ci
1448e41f4b71Sopenharmony_ci| Type   | Description      |
1449e41f4b71Sopenharmony_ci| ------  | -------   |
1450e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1451e41f4b71Sopenharmony_ci
1452e41f4b71Sopenharmony_ci**Example**
1453e41f4b71Sopenharmony_ci
1454e41f4b71Sopenharmony_ci```js
1455e41f4b71Sopenharmony_citry {
1456e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1457e41f4b71Sopenharmony_ci    query.isNull("field");
1458e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1459e41f4b71Sopenharmony_ci    query = null;
1460e41f4b71Sopenharmony_ci} catch (e) {
1461e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1462e41f4b71Sopenharmony_ci}
1463e41f4b71Sopenharmony_ci```
1464e41f4b71Sopenharmony_ci
1465e41f4b71Sopenharmony_ci
1466e41f4b71Sopenharmony_ci### inNumber<sup>8+</sup>
1467e41f4b71Sopenharmony_ci
1468e41f4b71Sopenharmony_ciinNumber(field: string, valueList: number[]): Query
1469e41f4b71Sopenharmony_ci
1470e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is within the specified list of numbers.
1471e41f4b71Sopenharmony_ci
1472e41f4b71Sopenharmony_ci
1473e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1474e41f4b71Sopenharmony_ci
1475e41f4b71Sopenharmony_ci**Parameters**
1476e41f4b71Sopenharmony_ci
1477e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1478e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1479e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1480e41f4b71Sopenharmony_ci| valueList  | number[]  | Yes   | List of numbers.|
1481e41f4b71Sopenharmony_ci
1482e41f4b71Sopenharmony_ci**Return value**
1483e41f4b71Sopenharmony_ci
1484e41f4b71Sopenharmony_ci| Type   | Description      |
1485e41f4b71Sopenharmony_ci| ------  | -------   |
1486e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1487e41f4b71Sopenharmony_ci
1488e41f4b71Sopenharmony_ci**Example**
1489e41f4b71Sopenharmony_ci
1490e41f4b71Sopenharmony_ci```js
1491e41f4b71Sopenharmony_citry {
1492e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1493e41f4b71Sopenharmony_ci    query.inNumber("field", [0, 1]);
1494e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1495e41f4b71Sopenharmony_ci    query = null;
1496e41f4b71Sopenharmony_ci} catch (e) {
1497e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1498e41f4b71Sopenharmony_ci}
1499e41f4b71Sopenharmony_ci```
1500e41f4b71Sopenharmony_ci
1501e41f4b71Sopenharmony_ci
1502e41f4b71Sopenharmony_ci### inString<sup>8+</sup>
1503e41f4b71Sopenharmony_ci
1504e41f4b71Sopenharmony_ciinString(field: string, valueList: string[]): Query
1505e41f4b71Sopenharmony_ci
1506e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is within the specified list of strings.
1507e41f4b71Sopenharmony_ci
1508e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1509e41f4b71Sopenharmony_ci
1510e41f4b71Sopenharmony_ci**Parameters**
1511e41f4b71Sopenharmony_ci
1512e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1513e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1514e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1515e41f4b71Sopenharmony_ci| valueList  | string[]  | Yes   | List of strings.|
1516e41f4b71Sopenharmony_ci
1517e41f4b71Sopenharmony_ci**Return value**
1518e41f4b71Sopenharmony_ci
1519e41f4b71Sopenharmony_ci| Type   | Description      |
1520e41f4b71Sopenharmony_ci| ------  | -------   |
1521e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1522e41f4b71Sopenharmony_ci
1523e41f4b71Sopenharmony_ci**Example**
1524e41f4b71Sopenharmony_ci
1525e41f4b71Sopenharmony_ci```js
1526e41f4b71Sopenharmony_citry {
1527e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1528e41f4b71Sopenharmony_ci    query.inString("field", ['test1', 'test2']);
1529e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1530e41f4b71Sopenharmony_ci    query = null;
1531e41f4b71Sopenharmony_ci} catch (e) {
1532e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1533e41f4b71Sopenharmony_ci}
1534e41f4b71Sopenharmony_ci```
1535e41f4b71Sopenharmony_ci
1536e41f4b71Sopenharmony_ci
1537e41f4b71Sopenharmony_ci### notInNumber<sup>8+</sup>
1538e41f4b71Sopenharmony_ci
1539e41f4b71Sopenharmony_cinotInNumber(field: string, valueList: number[]): Query
1540e41f4b71Sopenharmony_ci
1541e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is not within the specified list of numbers.
1542e41f4b71Sopenharmony_ci
1543e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1544e41f4b71Sopenharmony_ci
1545e41f4b71Sopenharmony_ci**Parameters**
1546e41f4b71Sopenharmony_ci
1547e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1548e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1549e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1550e41f4b71Sopenharmony_ci| valueList  | number[]  | Yes   | List of numbers.|
1551e41f4b71Sopenharmony_ci
1552e41f4b71Sopenharmony_ci**Return value**
1553e41f4b71Sopenharmony_ci
1554e41f4b71Sopenharmony_ci| Type   | Description      |
1555e41f4b71Sopenharmony_ci| ------  | -------   |
1556e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1557e41f4b71Sopenharmony_ci
1558e41f4b71Sopenharmony_ci**Example**
1559e41f4b71Sopenharmony_ci
1560e41f4b71Sopenharmony_ci```js
1561e41f4b71Sopenharmony_citry {
1562e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1563e41f4b71Sopenharmony_ci    query.notInNumber("field", [0, 1]);
1564e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1565e41f4b71Sopenharmony_ci    query = null;
1566e41f4b71Sopenharmony_ci} catch (e) {
1567e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1568e41f4b71Sopenharmony_ci}
1569e41f4b71Sopenharmony_ci```
1570e41f4b71Sopenharmony_ci
1571e41f4b71Sopenharmony_ci
1572e41f4b71Sopenharmony_ci### notInString<sup>8+</sup>
1573e41f4b71Sopenharmony_ci
1574e41f4b71Sopenharmony_cinotInString(field: string, valueList: string[]): Query
1575e41f4b71Sopenharmony_ci
1576e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is not within the specified list of strings.
1577e41f4b71Sopenharmony_ci
1578e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1579e41f4b71Sopenharmony_ci
1580e41f4b71Sopenharmony_ci**Parameters**
1581e41f4b71Sopenharmony_ci
1582e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1583e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1584e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1585e41f4b71Sopenharmony_ci| valueList  | string[]  | Yes   | List of strings.|
1586e41f4b71Sopenharmony_ci
1587e41f4b71Sopenharmony_ci**Return value**
1588e41f4b71Sopenharmony_ci
1589e41f4b71Sopenharmony_ci| Type   | Description      |
1590e41f4b71Sopenharmony_ci| ------  | -------   |
1591e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1592e41f4b71Sopenharmony_ci
1593e41f4b71Sopenharmony_ci**Example**
1594e41f4b71Sopenharmony_ci
1595e41f4b71Sopenharmony_ci```js
1596e41f4b71Sopenharmony_citry {
1597e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1598e41f4b71Sopenharmony_ci    query.notInString("field", ['test1', 'test2']);
1599e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1600e41f4b71Sopenharmony_ci    query = null;
1601e41f4b71Sopenharmony_ci} catch (e) {
1602e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1603e41f4b71Sopenharmony_ci}
1604e41f4b71Sopenharmony_ci```
1605e41f4b71Sopenharmony_ci
1606e41f4b71Sopenharmony_ci
1607e41f4b71Sopenharmony_ci### like<sup>8+</sup>
1608e41f4b71Sopenharmony_ci
1609e41f4b71Sopenharmony_cilike(field: string, value: string): Query
1610e41f4b71Sopenharmony_ci
1611e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is similar to the specified string.
1612e41f4b71Sopenharmony_ci
1613e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1614e41f4b71Sopenharmony_ci
1615e41f4b71Sopenharmony_ci**Parameters**
1616e41f4b71Sopenharmony_ci
1617e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1618e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1619e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1620e41f4b71Sopenharmony_ci| value  | string  | Yes   | String specified.|
1621e41f4b71Sopenharmony_ci
1622e41f4b71Sopenharmony_ci**Return value**
1623e41f4b71Sopenharmony_ci
1624e41f4b71Sopenharmony_ci| Type   | Description      |
1625e41f4b71Sopenharmony_ci| ------  | -------   |
1626e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1627e41f4b71Sopenharmony_ci
1628e41f4b71Sopenharmony_ci**Example**
1629e41f4b71Sopenharmony_ci
1630e41f4b71Sopenharmony_ci```js
1631e41f4b71Sopenharmony_citry {
1632e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1633e41f4b71Sopenharmony_ci    query.like("field", "value");
1634e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1635e41f4b71Sopenharmony_ci    query = null;
1636e41f4b71Sopenharmony_ci} catch (e) {
1637e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1638e41f4b71Sopenharmony_ci}
1639e41f4b71Sopenharmony_ci```
1640e41f4b71Sopenharmony_ci
1641e41f4b71Sopenharmony_ci
1642e41f4b71Sopenharmony_ci### unlike<sup>8+</sup>
1643e41f4b71Sopenharmony_ci
1644e41f4b71Sopenharmony_ciunlike(field: string, value: string): Query
1645e41f4b71Sopenharmony_ci
1646e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is not similar to the specified string.
1647e41f4b71Sopenharmony_ci
1648e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1649e41f4b71Sopenharmony_ci
1650e41f4b71Sopenharmony_ci**Parameters**
1651e41f4b71Sopenharmony_ci
1652e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1653e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1654e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1655e41f4b71Sopenharmony_ci| value  | string  | Yes   | String specified.|
1656e41f4b71Sopenharmony_ci
1657e41f4b71Sopenharmony_ci**Return value**
1658e41f4b71Sopenharmony_ci
1659e41f4b71Sopenharmony_ci| Type   | Description      |
1660e41f4b71Sopenharmony_ci| ------  | -------   |
1661e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1662e41f4b71Sopenharmony_ci
1663e41f4b71Sopenharmony_ci**Example**
1664e41f4b71Sopenharmony_ci
1665e41f4b71Sopenharmony_ci```js
1666e41f4b71Sopenharmony_citry {
1667e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1668e41f4b71Sopenharmony_ci    query.unlike("field", "value");
1669e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1670e41f4b71Sopenharmony_ci    query = null;
1671e41f4b71Sopenharmony_ci} catch (e) {
1672e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1673e41f4b71Sopenharmony_ci}
1674e41f4b71Sopenharmony_ci```
1675e41f4b71Sopenharmony_ci
1676e41f4b71Sopenharmony_ci
1677e41f4b71Sopenharmony_ci### and<sup>8+</sup>
1678e41f4b71Sopenharmony_ci
1679e41f4b71Sopenharmony_ciand(): Query
1680e41f4b71Sopenharmony_ci
1681e41f4b71Sopenharmony_ciCreates a **Query** object with the AND condition.
1682e41f4b71Sopenharmony_ci
1683e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1684e41f4b71Sopenharmony_ci
1685e41f4b71Sopenharmony_ci**Return value**
1686e41f4b71Sopenharmony_ci
1687e41f4b71Sopenharmony_ci| Type   | Description      |
1688e41f4b71Sopenharmony_ci| ------  | -------   |
1689e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1690e41f4b71Sopenharmony_ci
1691e41f4b71Sopenharmony_ci**Example**
1692e41f4b71Sopenharmony_ci
1693e41f4b71Sopenharmony_ci```js
1694e41f4b71Sopenharmony_citry {
1695e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1696e41f4b71Sopenharmony_ci    query.notEqualTo("field", "value1");
1697e41f4b71Sopenharmony_ci    query.and();
1698e41f4b71Sopenharmony_ci    query.notEqualTo("field", "value2");
1699e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1700e41f4b71Sopenharmony_ci    query = null;
1701e41f4b71Sopenharmony_ci} catch (e) {
1702e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1703e41f4b71Sopenharmony_ci}
1704e41f4b71Sopenharmony_ci```
1705e41f4b71Sopenharmony_ci
1706e41f4b71Sopenharmony_ci
1707e41f4b71Sopenharmony_ci### or<sup>8+</sup>
1708e41f4b71Sopenharmony_ci
1709e41f4b71Sopenharmony_cior(): Query
1710e41f4b71Sopenharmony_ci
1711e41f4b71Sopenharmony_ciCreates a **Query** object with the OR condition.
1712e41f4b71Sopenharmony_ci
1713e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1714e41f4b71Sopenharmony_ci
1715e41f4b71Sopenharmony_ci**Return value**
1716e41f4b71Sopenharmony_ci
1717e41f4b71Sopenharmony_ci| Type   | Description      |
1718e41f4b71Sopenharmony_ci| ------  | -------   |
1719e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1720e41f4b71Sopenharmony_ci
1721e41f4b71Sopenharmony_ci**Example**
1722e41f4b71Sopenharmony_ci
1723e41f4b71Sopenharmony_ci```js
1724e41f4b71Sopenharmony_citry {
1725e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1726e41f4b71Sopenharmony_ci    query.notEqualTo("field", "value1");
1727e41f4b71Sopenharmony_ci    query.or();
1728e41f4b71Sopenharmony_ci    query.notEqualTo("field", "value2");
1729e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1730e41f4b71Sopenharmony_ci    query = null;
1731e41f4b71Sopenharmony_ci} catch (e) {
1732e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1733e41f4b71Sopenharmony_ci}
1734e41f4b71Sopenharmony_ci```
1735e41f4b71Sopenharmony_ci
1736e41f4b71Sopenharmony_ci
1737e41f4b71Sopenharmony_ci### orderByAsc<sup>8+</sup>
1738e41f4b71Sopenharmony_ci
1739e41f4b71Sopenharmony_ciorderByAsc(field: string): Query
1740e41f4b71Sopenharmony_ci
1741e41f4b71Sopenharmony_ciCreates a **Query** object to sort the query results in ascending order.
1742e41f4b71Sopenharmony_ci
1743e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1744e41f4b71Sopenharmony_ci
1745e41f4b71Sopenharmony_ci**Parameters**
1746e41f4b71Sopenharmony_ci
1747e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1748e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1749e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1750e41f4b71Sopenharmony_ci
1751e41f4b71Sopenharmony_ci**Return value**
1752e41f4b71Sopenharmony_ci
1753e41f4b71Sopenharmony_ci| Type   | Description      |
1754e41f4b71Sopenharmony_ci| ------  | -------   |
1755e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1756e41f4b71Sopenharmony_ci
1757e41f4b71Sopenharmony_ci**Example**
1758e41f4b71Sopenharmony_ci
1759e41f4b71Sopenharmony_ci```js
1760e41f4b71Sopenharmony_citry {
1761e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1762e41f4b71Sopenharmony_ci    query.notEqualTo("field", "value");
1763e41f4b71Sopenharmony_ci    query.orderByAsc("field");
1764e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1765e41f4b71Sopenharmony_ci    query = null;
1766e41f4b71Sopenharmony_ci} catch (e) {
1767e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1768e41f4b71Sopenharmony_ci}
1769e41f4b71Sopenharmony_ci```
1770e41f4b71Sopenharmony_ci
1771e41f4b71Sopenharmony_ci
1772e41f4b71Sopenharmony_ci### orderByDesc<sup>8+</sup>
1773e41f4b71Sopenharmony_ci
1774e41f4b71Sopenharmony_ciorderByDesc(field: string): Query
1775e41f4b71Sopenharmony_ci
1776e41f4b71Sopenharmony_ciCreates a **Query** object to sort the query results in descending order.
1777e41f4b71Sopenharmony_ci
1778e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1779e41f4b71Sopenharmony_ci
1780e41f4b71Sopenharmony_ci**Parameters**
1781e41f4b71Sopenharmony_ci
1782e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1783e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1784e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'. |
1785e41f4b71Sopenharmony_ci
1786e41f4b71Sopenharmony_ci**Return value**
1787e41f4b71Sopenharmony_ci
1788e41f4b71Sopenharmony_ci| Type   | Description      |
1789e41f4b71Sopenharmony_ci| ------  | -------   |
1790e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1791e41f4b71Sopenharmony_ci
1792e41f4b71Sopenharmony_ci**Example**
1793e41f4b71Sopenharmony_ci
1794e41f4b71Sopenharmony_ci```js
1795e41f4b71Sopenharmony_citry {
1796e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1797e41f4b71Sopenharmony_ci    query.notEqualTo("field", "value");
1798e41f4b71Sopenharmony_ci    query.orderByDesc("field");
1799e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1800e41f4b71Sopenharmony_ci    query = null;
1801e41f4b71Sopenharmony_ci} catch (e) {
1802e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1803e41f4b71Sopenharmony_ci}
1804e41f4b71Sopenharmony_ci```
1805e41f4b71Sopenharmony_ci
1806e41f4b71Sopenharmony_ci
1807e41f4b71Sopenharmony_ci### limit<sup>8+</sup>
1808e41f4b71Sopenharmony_ci
1809e41f4b71Sopenharmony_cilimit(total: number, offset: number): Query
1810e41f4b71Sopenharmony_ci
1811e41f4b71Sopenharmony_ciCreates a **Query** object to specify the number of results and where to start.
1812e41f4b71Sopenharmony_ci
1813e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1814e41f4b71Sopenharmony_ci
1815e41f4b71Sopenharmony_ci**Parameters**
1816e41f4b71Sopenharmony_ci
1817e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1818e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1819e41f4b71Sopenharmony_ci| total  | number  | Yes   |Number of results to query. |
1820e41f4b71Sopenharmony_ci| offset | number  | Yes   |Start position for query. |
1821e41f4b71Sopenharmony_ci
1822e41f4b71Sopenharmony_ci**Return value**
1823e41f4b71Sopenharmony_ci
1824e41f4b71Sopenharmony_ci| Type   | Description      |
1825e41f4b71Sopenharmony_ci| ------  | -------   |
1826e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1827e41f4b71Sopenharmony_ci
1828e41f4b71Sopenharmony_ci**Example**
1829e41f4b71Sopenharmony_ci
1830e41f4b71Sopenharmony_ci```js
1831e41f4b71Sopenharmony_cilet total = 10;
1832e41f4b71Sopenharmony_cilet offset = 1;
1833e41f4b71Sopenharmony_citry {
1834e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1835e41f4b71Sopenharmony_ci    query.notEqualTo("field", "value");
1836e41f4b71Sopenharmony_ci    query.limit(total, offset);
1837e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1838e41f4b71Sopenharmony_ci    query = null;
1839e41f4b71Sopenharmony_ci} catch (e) {
1840e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1841e41f4b71Sopenharmony_ci}
1842e41f4b71Sopenharmony_ci```
1843e41f4b71Sopenharmony_ci
1844e41f4b71Sopenharmony_ci
1845e41f4b71Sopenharmony_ci### isNotNull<sup>8+</sup>
1846e41f4b71Sopenharmony_ci
1847e41f4b71Sopenharmony_ciisNotNull(field: string): Query
1848e41f4b71Sopenharmony_ci
1849e41f4b71Sopenharmony_ciCreates a **Query** object to match the specified field whose value is not **null**.
1850e41f4b71Sopenharmony_ci
1851e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1852e41f4b71Sopenharmony_ci
1853e41f4b71Sopenharmony_ci**Parameters**
1854e41f4b71Sopenharmony_ci
1855e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1856e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1857e41f4b71Sopenharmony_ci| field  | string  | Yes   |Field to match. It cannot contain '^'.     |
1858e41f4b71Sopenharmony_ci
1859e41f4b71Sopenharmony_ci**Return value**
1860e41f4b71Sopenharmony_ci
1861e41f4b71Sopenharmony_ci| Type   | Description      |
1862e41f4b71Sopenharmony_ci| ------  | -------   |
1863e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1864e41f4b71Sopenharmony_ci
1865e41f4b71Sopenharmony_ci**Example**
1866e41f4b71Sopenharmony_ci
1867e41f4b71Sopenharmony_ci```js
1868e41f4b71Sopenharmony_citry {
1869e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1870e41f4b71Sopenharmony_ci    query.isNotNull("field");
1871e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1872e41f4b71Sopenharmony_ci    query = null;
1873e41f4b71Sopenharmony_ci} catch (e) {
1874e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1875e41f4b71Sopenharmony_ci}
1876e41f4b71Sopenharmony_ci```
1877e41f4b71Sopenharmony_ci
1878e41f4b71Sopenharmony_ci
1879e41f4b71Sopenharmony_ci### beginGroup<sup>8+</sup>
1880e41f4b71Sopenharmony_ci
1881e41f4b71Sopenharmony_cibeginGroup(): Query
1882e41f4b71Sopenharmony_ci
1883e41f4b71Sopenharmony_ciCreates a **Query** object for a query condition group with a left parenthesis.
1884e41f4b71Sopenharmony_ci
1885e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1886e41f4b71Sopenharmony_ci
1887e41f4b71Sopenharmony_ci**Return value**
1888e41f4b71Sopenharmony_ci
1889e41f4b71Sopenharmony_ci| Type   | Description      |
1890e41f4b71Sopenharmony_ci| ------  | -------   |
1891e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1892e41f4b71Sopenharmony_ci
1893e41f4b71Sopenharmony_ci**Example**
1894e41f4b71Sopenharmony_ci
1895e41f4b71Sopenharmony_ci```js
1896e41f4b71Sopenharmony_citry {
1897e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1898e41f4b71Sopenharmony_ci    query.beginGroup();
1899e41f4b71Sopenharmony_ci    query.isNotNull("field");
1900e41f4b71Sopenharmony_ci    query.endGroup();
1901e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1902e41f4b71Sopenharmony_ci    query = null;
1903e41f4b71Sopenharmony_ci} catch (e) {
1904e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1905e41f4b71Sopenharmony_ci}
1906e41f4b71Sopenharmony_ci```
1907e41f4b71Sopenharmony_ci
1908e41f4b71Sopenharmony_ci
1909e41f4b71Sopenharmony_ci### endGroup<sup>8+</sup>
1910e41f4b71Sopenharmony_ci
1911e41f4b71Sopenharmony_ciendGroup(): Query
1912e41f4b71Sopenharmony_ci
1913e41f4b71Sopenharmony_ciCreates a **Query** object for a query condition group with a right parenthesis.
1914e41f4b71Sopenharmony_ci
1915e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1916e41f4b71Sopenharmony_ci
1917e41f4b71Sopenharmony_ci**Return value**
1918e41f4b71Sopenharmony_ci
1919e41f4b71Sopenharmony_ci| Type   | Description      |
1920e41f4b71Sopenharmony_ci| ------  | -------   |
1921e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1922e41f4b71Sopenharmony_ci
1923e41f4b71Sopenharmony_ci**Example**
1924e41f4b71Sopenharmony_ci
1925e41f4b71Sopenharmony_ci```js
1926e41f4b71Sopenharmony_citry {
1927e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1928e41f4b71Sopenharmony_ci    query.beginGroup();
1929e41f4b71Sopenharmony_ci    query.isNotNull("field");
1930e41f4b71Sopenharmony_ci    query.endGroup();
1931e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1932e41f4b71Sopenharmony_ci    query = null;
1933e41f4b71Sopenharmony_ci} catch (e) {
1934e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1935e41f4b71Sopenharmony_ci}
1936e41f4b71Sopenharmony_ci```
1937e41f4b71Sopenharmony_ci
1938e41f4b71Sopenharmony_ci
1939e41f4b71Sopenharmony_ci### prefixKey<sup>8+</sup>
1940e41f4b71Sopenharmony_ci
1941e41f4b71Sopenharmony_ciprefixKey(prefix: string): Query
1942e41f4b71Sopenharmony_ci
1943e41f4b71Sopenharmony_ciCreates a **Query** object with a specified key prefix.
1944e41f4b71Sopenharmony_ci
1945e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1946e41f4b71Sopenharmony_ci
1947e41f4b71Sopenharmony_ci**Parameters**
1948e41f4b71Sopenharmony_ci
1949e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1950e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1951e41f4b71Sopenharmony_ci| prefix | string  | Yes   |Key prefix.    |
1952e41f4b71Sopenharmony_ci
1953e41f4b71Sopenharmony_ci**Return value**
1954e41f4b71Sopenharmony_ci
1955e41f4b71Sopenharmony_ci| Type   | Description      |
1956e41f4b71Sopenharmony_ci| ------  | -------   |
1957e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1958e41f4b71Sopenharmony_ci
1959e41f4b71Sopenharmony_ci**Example**
1960e41f4b71Sopenharmony_ci
1961e41f4b71Sopenharmony_ci```js
1962e41f4b71Sopenharmony_citry {
1963e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1964e41f4b71Sopenharmony_ci    query.prefixKey("$.name");
1965e41f4b71Sopenharmony_ci    query.prefixKey("0");
1966e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
1967e41f4b71Sopenharmony_ci    query = null;
1968e41f4b71Sopenharmony_ci} catch (e) {
1969e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok :" + e);
1970e41f4b71Sopenharmony_ci}
1971e41f4b71Sopenharmony_ci```
1972e41f4b71Sopenharmony_ci
1973e41f4b71Sopenharmony_ci
1974e41f4b71Sopenharmony_ci### setSuggestIndex<sup>8+</sup>
1975e41f4b71Sopenharmony_ci
1976e41f4b71Sopenharmony_cisetSuggestIndex(index: string): Query
1977e41f4b71Sopenharmony_ci
1978e41f4b71Sopenharmony_ciCreates a **Query** object with an index preferentially used for query.
1979e41f4b71Sopenharmony_ci
1980e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
1981e41f4b71Sopenharmony_ci
1982e41f4b71Sopenharmony_ci**Parameters**
1983e41f4b71Sopenharmony_ci
1984e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
1985e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
1986e41f4b71Sopenharmony_ci| index  | string  | Yes   |Index preferentially used for query.  |
1987e41f4b71Sopenharmony_ci
1988e41f4b71Sopenharmony_ci**Return value**
1989e41f4b71Sopenharmony_ci
1990e41f4b71Sopenharmony_ci| Type   | Description      |
1991e41f4b71Sopenharmony_ci| ------  | -------   |
1992e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
1993e41f4b71Sopenharmony_ci
1994e41f4b71Sopenharmony_ci**Example**
1995e41f4b71Sopenharmony_ci
1996e41f4b71Sopenharmony_ci```js
1997e41f4b71Sopenharmony_citry {
1998e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
1999e41f4b71Sopenharmony_ci    query.setSuggestIndex("$.name");
2000e41f4b71Sopenharmony_ci    query.setSuggestIndex("0");
2001e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
2002e41f4b71Sopenharmony_ci    query = null;
2003e41f4b71Sopenharmony_ci} catch (e) {
2004e41f4b71Sopenharmony_ci   console.log("duplicated calls should be ok :" + e);
2005e41f4b71Sopenharmony_ci}
2006e41f4b71Sopenharmony_ci```
2007e41f4b71Sopenharmony_ci
2008e41f4b71Sopenharmony_ci
2009e41f4b71Sopenharmony_ci### deviceId<sup>8+</sup>
2010e41f4b71Sopenharmony_ci
2011e41f4b71Sopenharmony_cideviceId(deviceId:string):Query
2012e41f4b71Sopenharmony_ci
2013e41f4b71Sopenharmony_ciCreates a **Query** object with the device ID as the key prefix.
2014e41f4b71Sopenharmony_ci> **NOTE**
2015e41f4b71Sopenharmony_ci>
2016e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
2017e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
2018e41f4b71Sopenharmony_ci
2019e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2020e41f4b71Sopenharmony_ci
2021e41f4b71Sopenharmony_ci**Parameters**
2022e41f4b71Sopenharmony_ci
2023e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2024e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2025e41f4b71Sopenharmony_ci| deviceId | string  | Yes   |Device ID.  |
2026e41f4b71Sopenharmony_ci
2027e41f4b71Sopenharmony_ci
2028e41f4b71Sopenharmony_ci**Return value**
2029e41f4b71Sopenharmony_ci
2030e41f4b71Sopenharmony_ci| Type   | Description      |
2031e41f4b71Sopenharmony_ci| ------  | -------   |
2032e41f4b71Sopenharmony_ci| [Query](#query8) |**Query** object created.|
2033e41f4b71Sopenharmony_ci
2034e41f4b71Sopenharmony_ci**Example**
2035e41f4b71Sopenharmony_ci
2036e41f4b71Sopenharmony_ci```js
2037e41f4b71Sopenharmony_citry {
2038e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
2039e41f4b71Sopenharmony_ci    query.deviceId("deviceId");
2040e41f4b71Sopenharmony_ci    console.log("query is " + query.getSqlLike());
2041e41f4b71Sopenharmony_ci} catch (e) {
2042e41f4b71Sopenharmony_ci    console.log("should be ok on Method Chaining : " + e);
2043e41f4b71Sopenharmony_ci}
2044e41f4b71Sopenharmony_ci```
2045e41f4b71Sopenharmony_ci
2046e41f4b71Sopenharmony_ci
2047e41f4b71Sopenharmony_ci### getSqlLike<sup>8+</sup>
2048e41f4b71Sopenharmony_ci
2049e41f4b71Sopenharmony_cigetSqlLike():string
2050e41f4b71Sopenharmony_ci
2051e41f4b71Sopenharmony_ciObtains the query statement of the **Query** object.
2052e41f4b71Sopenharmony_ci
2053e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2054e41f4b71Sopenharmony_ci
2055e41f4b71Sopenharmony_ci**Return value**
2056e41f4b71Sopenharmony_ci
2057e41f4b71Sopenharmony_ci| Type   | Description      |
2058e41f4b71Sopenharmony_ci| ------  | -------   |
2059e41f4b71Sopenharmony_ci| string |Returns the query statement obtained.|
2060e41f4b71Sopenharmony_ci
2061e41f4b71Sopenharmony_ci**Example**
2062e41f4b71Sopenharmony_ci
2063e41f4b71Sopenharmony_ci```js
2064e41f4b71Sopenharmony_citry {
2065e41f4b71Sopenharmony_ci    let query = new distributedData.Query();
2066e41f4b71Sopenharmony_ci    let sql1 = query.getSqlLike();
2067e41f4b71Sopenharmony_ci    console.log("GetSqlLike sql=" + sql1);
2068e41f4b71Sopenharmony_ci} catch (e) {
2069e41f4b71Sopenharmony_ci    console.log("duplicated calls should be ok : " + e);
2070e41f4b71Sopenharmony_ci}
2071e41f4b71Sopenharmony_ci```
2072e41f4b71Sopenharmony_ci
2073e41f4b71Sopenharmony_ci
2074e41f4b71Sopenharmony_ci## KVStore
2075e41f4b71Sopenharmony_ci
2076e41f4b71Sopenharmony_ciProvides APIs to manage data in a KV store, for example, adding or deleting data and subscribing to data changes or completion of data sync.
2077e41f4b71Sopenharmony_ci
2078e41f4b71Sopenharmony_ciBefore calling any method in **KVStore**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object.
2079e41f4b71Sopenharmony_ci
2080e41f4b71Sopenharmony_ci### put
2081e41f4b71Sopenharmony_ci
2082e41f4b71Sopenharmony_ciput(key: string, value: Uint8Array | string | number | boolean, callback: AsyncCallback&lt;void&gt;): void
2083e41f4b71Sopenharmony_ci
2084e41f4b71Sopenharmony_ciAdds a KV pair of the specified type to this KV store. This API uses an asynchronous callback to return the result.
2085e41f4b71Sopenharmony_ci
2086e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2087e41f4b71Sopenharmony_ci
2088e41f4b71Sopenharmony_ci**Parameters**
2089e41f4b71Sopenharmony_ci
2090e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2091e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2092e41f4b71Sopenharmony_ci| key    | string  | Yes   |Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants).  |
2093e41f4b71Sopenharmony_ci| value  | Uint8Array \| string \| number \| boolean | Yes   |Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX_VALUE_LENGTH](#constants).  |
2094e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes   |Callback used to return the result.  |
2095e41f4b71Sopenharmony_ci
2096e41f4b71Sopenharmony_ci**Example**
2097e41f4b71Sopenharmony_ci
2098e41f4b71Sopenharmony_ci```js
2099e41f4b71Sopenharmony_cilet kvStore;
2100e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string';
2101e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-test-string';
2102e41f4b71Sopenharmony_citry {
2103e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
2104e41f4b71Sopenharmony_ci        if (err != undefined) {
2105e41f4b71Sopenharmony_ci            console.log("put err: " + JSON.stringify(err));
2106e41f4b71Sopenharmony_ci            return;
2107e41f4b71Sopenharmony_ci        }
2108e41f4b71Sopenharmony_ci        console.log("put success");
2109e41f4b71Sopenharmony_ci    });
2110e41f4b71Sopenharmony_ci}catch (e) {
2111e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
2112e41f4b71Sopenharmony_ci}
2113e41f4b71Sopenharmony_ci```
2114e41f4b71Sopenharmony_ci
2115e41f4b71Sopenharmony_ci### put
2116e41f4b71Sopenharmony_ci
2117e41f4b71Sopenharmony_ciput(key: string, value: Uint8Array | string | number | boolean): Promise&lt;void&gt;
2118e41f4b71Sopenharmony_ci
2119e41f4b71Sopenharmony_ciAdds a KV pair of the specified type to this KV store. This API uses a promise to return the result.
2120e41f4b71Sopenharmony_ci
2121e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2122e41f4b71Sopenharmony_ci
2123e41f4b71Sopenharmony_ci**Parameters**
2124e41f4b71Sopenharmony_ci
2125e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2126e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2127e41f4b71Sopenharmony_ci| key    | string  | Yes   |Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants).  |
2128e41f4b71Sopenharmony_ci| value  | Uint8Array \| string \| number \| boolean | Yes   |Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX_VALUE_LENGTH](#constants).  |
2129e41f4b71Sopenharmony_ci
2130e41f4b71Sopenharmony_ci**Return value**
2131e41f4b71Sopenharmony_ci
2132e41f4b71Sopenharmony_ci| Type   | Description      |
2133e41f4b71Sopenharmony_ci| ------  | -------   |
2134e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2135e41f4b71Sopenharmony_ci
2136e41f4b71Sopenharmony_ci**Example**
2137e41f4b71Sopenharmony_ci
2138e41f4b71Sopenharmony_ci```js
2139e41f4b71Sopenharmony_cilet kvStore;
2140e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string';
2141e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-test-string';
2142e41f4b71Sopenharmony_citry {
2143e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
2144e41f4b71Sopenharmony_ci        console.log("put success: " + JSON.stringify(data));
2145e41f4b71Sopenharmony_ci    }).catch((err) => {
2146e41f4b71Sopenharmony_ci        console.log("put err: " + JSON.stringify(err));
2147e41f4b71Sopenharmony_ci    });
2148e41f4b71Sopenharmony_ci}catch (e) {
2149e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
2150e41f4b71Sopenharmony_ci}
2151e41f4b71Sopenharmony_ci```
2152e41f4b71Sopenharmony_ci
2153e41f4b71Sopenharmony_ci### delete
2154e41f4b71Sopenharmony_ci
2155e41f4b71Sopenharmony_cidelete(key: string, callback: AsyncCallback&lt;void&gt;): void
2156e41f4b71Sopenharmony_ci
2157e41f4b71Sopenharmony_ciDeletes a KV pair from this KV store. This API uses an asynchronous callback to return the result.
2158e41f4b71Sopenharmony_ci
2159e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2160e41f4b71Sopenharmony_ci
2161e41f4b71Sopenharmony_ci**Parameters**
2162e41f4b71Sopenharmony_ci
2163e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2164e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2165e41f4b71Sopenharmony_ci| key    | string  | Yes   |Key of the KV pair to delete. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants).  |
2166e41f4b71Sopenharmony_ci| callback  | AsyncCallback&lt;void&gt;  | Yes   |Callback used to return the result.  |
2167e41f4b71Sopenharmony_ci
2168e41f4b71Sopenharmony_ci**Example**
2169e41f4b71Sopenharmony_ci
2170e41f4b71Sopenharmony_ci```js
2171e41f4b71Sopenharmony_cilet kvStore;
2172e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string';
2173e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-test-string';
2174e41f4b71Sopenharmony_citry {
2175e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
2176e41f4b71Sopenharmony_ci        if (err != undefined) {
2177e41f4b71Sopenharmony_ci            console.log("put err: " + JSON.stringify(err));
2178e41f4b71Sopenharmony_ci            return;
2179e41f4b71Sopenharmony_ci        }
2180e41f4b71Sopenharmony_ci        console.log("put success");
2181e41f4b71Sopenharmony_ci        kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err,data) {
2182e41f4b71Sopenharmony_ci            if (err != undefined) {
2183e41f4b71Sopenharmony_ci                console.log("delete err: " + JSON.stringify(err));
2184e41f4b71Sopenharmony_ci                return;
2185e41f4b71Sopenharmony_ci            }
2186e41f4b71Sopenharmony_ci            console.log("delete success");
2187e41f4b71Sopenharmony_ci        });
2188e41f4b71Sopenharmony_ci    });
2189e41f4b71Sopenharmony_ci}catch (e) {
2190e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
2191e41f4b71Sopenharmony_ci}
2192e41f4b71Sopenharmony_ci```
2193e41f4b71Sopenharmony_ci
2194e41f4b71Sopenharmony_ci### delete
2195e41f4b71Sopenharmony_ci
2196e41f4b71Sopenharmony_cidelete(key: string): Promise&lt;void&gt;
2197e41f4b71Sopenharmony_ci
2198e41f4b71Sopenharmony_ciDeletes a KV pair from this KV store. This API uses a promise to return the result.
2199e41f4b71Sopenharmony_ci
2200e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2201e41f4b71Sopenharmony_ci
2202e41f4b71Sopenharmony_ci**Parameters**
2203e41f4b71Sopenharmony_ci
2204e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2205e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2206e41f4b71Sopenharmony_ci| key    | string  | Yes   |Key of the KV pair to delete. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants).  |
2207e41f4b71Sopenharmony_ci
2208e41f4b71Sopenharmony_ci**Return value**
2209e41f4b71Sopenharmony_ci
2210e41f4b71Sopenharmony_ci| Type   | Description      |
2211e41f4b71Sopenharmony_ci| ------  | -------   |
2212e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2213e41f4b71Sopenharmony_ci
2214e41f4b71Sopenharmony_ci**Example**
2215e41f4b71Sopenharmony_ci
2216e41f4b71Sopenharmony_ci```js
2217e41f4b71Sopenharmony_cilet kvStore;
2218e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string';
2219e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-test-string';
2220e41f4b71Sopenharmony_citry {
2221e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
2222e41f4b71Sopenharmony_ci        console.log("put success: " + JSON.stringify(data));
2223e41f4b71Sopenharmony_ci        kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => {
2224e41f4b71Sopenharmony_ci            console.log("delete success");
2225e41f4b71Sopenharmony_ci        }).catch((err) => {
2226e41f4b71Sopenharmony_ci            console.log("delete err: " + JSON.stringify(err));
2227e41f4b71Sopenharmony_ci        });
2228e41f4b71Sopenharmony_ci    }).catch((err) => {
2229e41f4b71Sopenharmony_ci        console.log("put err: " + JSON.stringify(err));
2230e41f4b71Sopenharmony_ci    });
2231e41f4b71Sopenharmony_ci}catch (e) {
2232e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
2233e41f4b71Sopenharmony_ci}
2234e41f4b71Sopenharmony_ci```
2235e41f4b71Sopenharmony_ci
2236e41f4b71Sopenharmony_ci### on('dataChange')
2237e41f4b71Sopenharmony_ci
2238e41f4b71Sopenharmony_cion(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
2239e41f4b71Sopenharmony_ci
2240e41f4b71Sopenharmony_ciSubscribes to data changes of the specified type.
2241e41f4b71Sopenharmony_ci
2242e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2243e41f4b71Sopenharmony_ci
2244e41f4b71Sopenharmony_ci**Parameters**
2245e41f4b71Sopenharmony_ci
2246e41f4b71Sopenharmony_ci| Name  | Type                                                     | Mandatory| Description                                                |
2247e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------- |
2248e41f4b71Sopenharmony_ci| event    | string                                                    | Yes  | Event type. The value is **dataChange**, which indicates data changes.|
2249e41f4b71Sopenharmony_ci| type     | [SubscribeType](#subscribetype)                           | Yes  | Type of data change.                                    |
2250e41f4b71Sopenharmony_ci| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes   |Callback used to return the data change.|
2251e41f4b71Sopenharmony_ci
2252e41f4b71Sopenharmony_ci**Example**
2253e41f4b71Sopenharmony_ci
2254e41f4b71Sopenharmony_ci```js
2255e41f4b71Sopenharmony_cilet kvStore;
2256e41f4b71Sopenharmony_cikvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) {
2257e41f4b71Sopenharmony_ci    console.log("dataChange callback call data: " + JSON.stringify(data));
2258e41f4b71Sopenharmony_ci});
2259e41f4b71Sopenharmony_ci```
2260e41f4b71Sopenharmony_ci
2261e41f4b71Sopenharmony_ci### on('syncComplete')
2262e41f4b71Sopenharmony_ci
2263e41f4b71Sopenharmony_cion(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
2264e41f4b71Sopenharmony_ci
2265e41f4b71Sopenharmony_ciSubscribes to sync complete events.
2266e41f4b71Sopenharmony_ci
2267e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2268e41f4b71Sopenharmony_ci
2269e41f4b71Sopenharmony_ci**Parameters**
2270e41f4b71Sopenharmony_ci
2271e41f4b71Sopenharmony_ci| Name      | Type                                         | Mandatory| Description                                                  |
2272e41f4b71Sopenharmony_ci| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------ |
2273e41f4b71Sopenharmony_ci| event        | string                                        | Yes  | Event type. The value is **syncComplete**, which indicates a sync complete event.|
2274e41f4b71Sopenharmony_ci| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes  | Callback used to return a sync complete event.            |
2275e41f4b71Sopenharmony_ci
2276e41f4b71Sopenharmony_ci**Example**
2277e41f4b71Sopenharmony_ci
2278e41f4b71Sopenharmony_ci```js
2279e41f4b71Sopenharmony_cilet kvStore;
2280e41f4b71Sopenharmony_cikvStore.on('syncComplete', function (data) {
2281e41f4b71Sopenharmony_ci    console.log("callback call data: " + data);
2282e41f4b71Sopenharmony_ci});
2283e41f4b71Sopenharmony_ci```
2284e41f4b71Sopenharmony_ci
2285e41f4b71Sopenharmony_ci### off('dataChange')<sup>8+</sup>
2286e41f4b71Sopenharmony_ci
2287e41f4b71Sopenharmony_cioff(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
2288e41f4b71Sopenharmony_ci
2289e41f4b71Sopenharmony_ciUnsubscribes from data changes.
2290e41f4b71Sopenharmony_ci
2291e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2292e41f4b71Sopenharmony_ci
2293e41f4b71Sopenharmony_ci**Parameters**
2294e41f4b71Sopenharmony_ci
2295e41f4b71Sopenharmony_ci| Name  | Type                                                     | Mandatory| Description                                                    |
2296e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- |
2297e41f4b71Sopenharmony_ci| event    | string                                                    | Yes  | Event type. The value is **dataChange**, which indicates data changes.|
2298e41f4b71Sopenharmony_ci| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | No  | Callback to unregister. If this parameter is not specified, all callbacks for data changes will be unregistered.|
2299e41f4b71Sopenharmony_ci
2300e41f4b71Sopenharmony_ci
2301e41f4b71Sopenharmony_ci
2302e41f4b71Sopenharmony_ci**Example**
2303e41f4b71Sopenharmony_ci
2304e41f4b71Sopenharmony_ci```js
2305e41f4b71Sopenharmony_cilet kvStore;
2306e41f4b71Sopenharmony_ciclass KvstoreModel {
2307e41f4b71Sopenharmony_ci    call(data) {
2308e41f4b71Sopenharmony_ci        console.log("dataChange: " + data);
2309e41f4b71Sopenharmony_ci    }
2310e41f4b71Sopenharmony_ci    subscribeDataChange() {
2311e41f4b71Sopenharmony_ci        if (kvStore != null) {
2312e41f4b71Sopenharmony_ci            kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
2313e41f4b71Sopenharmony_ci        }
2314e41f4b71Sopenharmony_ci    }
2315e41f4b71Sopenharmony_ci    unsubscribeDataChange() {
2316e41f4b71Sopenharmony_ci        if (kvStore != null) {
2317e41f4b71Sopenharmony_ci            kvStore.off('dataChange', this.call);
2318e41f4b71Sopenharmony_ci        }
2319e41f4b71Sopenharmony_ci    }
2320e41f4b71Sopenharmony_ci}
2321e41f4b71Sopenharmony_ci```
2322e41f4b71Sopenharmony_ci
2323e41f4b71Sopenharmony_ci### off('syncComplete')<sup>8+</sup>
2324e41f4b71Sopenharmony_ci
2325e41f4b71Sopenharmony_cioff(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
2326e41f4b71Sopenharmony_ci
2327e41f4b71Sopenharmony_ciUnsubscribes from sync complete events.
2328e41f4b71Sopenharmony_ci
2329e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2330e41f4b71Sopenharmony_ci
2331e41f4b71Sopenharmony_ci**Parameters**
2332e41f4b71Sopenharmony_ci
2333e41f4b71Sopenharmony_ci| Name      | Type                                         | Mandatory| Description                                                      |
2334e41f4b71Sopenharmony_ci| ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- |
2335e41f4b71Sopenharmony_ci| event        | string                                        | Yes  | Event type. The value is **syncComplete**, which indicates a sync complete event.|
2336e41f4b71Sopenharmony_ci| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | No  | Callback to unregister. If this parameter is not specified, all callbacks for the sync complete event will be unregistered.|
2337e41f4b71Sopenharmony_ci
2338e41f4b71Sopenharmony_ci**Example**
2339e41f4b71Sopenharmony_ci
2340e41f4b71Sopenharmony_ci```js
2341e41f4b71Sopenharmony_cilet kvStore;
2342e41f4b71Sopenharmony_ciclass KvstoreModel {
2343e41f4b71Sopenharmony_ci    call(data) {
2344e41f4b71Sopenharmony_ci        console.log("syncComplete: " + data);
2345e41f4b71Sopenharmony_ci    }
2346e41f4b71Sopenharmony_ci    subscribeSyncComplete() {
2347e41f4b71Sopenharmony_ci        if (kvStore != null) {
2348e41f4b71Sopenharmony_ci            kvStore.on('syncComplete', this.call);
2349e41f4b71Sopenharmony_ci        }
2350e41f4b71Sopenharmony_ci    }
2351e41f4b71Sopenharmony_ci    unsubscribeSyncComplete() {
2352e41f4b71Sopenharmony_ci        if (kvStore != null) {
2353e41f4b71Sopenharmony_ci            kvStore.off('syncComplete', this.call);
2354e41f4b71Sopenharmony_ci        }
2355e41f4b71Sopenharmony_ci    }
2356e41f4b71Sopenharmony_ci}
2357e41f4b71Sopenharmony_ci```
2358e41f4b71Sopenharmony_ci
2359e41f4b71Sopenharmony_ci### putBatch<sup>8+</sup>
2360e41f4b71Sopenharmony_ci
2361e41f4b71Sopenharmony_ciputBatch(entries: Entry[], callback: AsyncCallback&lt;void&gt;): void
2362e41f4b71Sopenharmony_ci
2363e41f4b71Sopenharmony_ciInserts KV pairs in batches to this KV store. This API uses an asynchronous callback to return the result.
2364e41f4b71Sopenharmony_ci
2365e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2366e41f4b71Sopenharmony_ci
2367e41f4b71Sopenharmony_ci**Parameters**
2368e41f4b71Sopenharmony_ci
2369e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2370e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2371e41f4b71Sopenharmony_ci| entries  |[Entry](#entry)[] | Yes   |KV pairs to insert in batches. |
2372e41f4b71Sopenharmony_ci| callback |AsyncCallback&lt;void&gt; |Yes    |Callback used to return the result.|
2373e41f4b71Sopenharmony_ci
2374e41f4b71Sopenharmony_ci**Example**
2375e41f4b71Sopenharmony_ci
2376e41f4b71Sopenharmony_ci```js
2377e41f4b71Sopenharmony_cilet kvStore;
2378e41f4b71Sopenharmony_citry {
2379e41f4b71Sopenharmony_ci    let entries = [];
2380e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
2381e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
2382e41f4b71Sopenharmony_ci        var entry = {
2383e41f4b71Sopenharmony_ci            key : key + i,
2384e41f4b71Sopenharmony_ci            value : {
2385e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
2386e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
2387e41f4b71Sopenharmony_ci            }
2388e41f4b71Sopenharmony_ci        }
2389e41f4b71Sopenharmony_ci        entries.push(entry);
2390e41f4b71Sopenharmony_ci    }
2391e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
2392e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err,data) {
2393e41f4b71Sopenharmony_ci        console.log('putBatch success');
2394e41f4b71Sopenharmony_ci        kvStore.getEntries('batch_test_string_key', function (err,entries) {
2395e41f4b71Sopenharmony_ci            console.log('getEntries success');
2396e41f4b71Sopenharmony_ci            console.log('entries.length: ' + entries.length);
2397e41f4b71Sopenharmony_ci            console.log('entries[0]: ' + JSON.stringify(entries[0]));
2398e41f4b71Sopenharmony_ci        });
2399e41f4b71Sopenharmony_ci    });
2400e41f4b71Sopenharmony_ci}catch(e) {
2401e41f4b71Sopenharmony_ci    console.log('PutBatch e ' + JSON.stringify(e));
2402e41f4b71Sopenharmony_ci}
2403e41f4b71Sopenharmony_ci```
2404e41f4b71Sopenharmony_ci
2405e41f4b71Sopenharmony_ci
2406e41f4b71Sopenharmony_ci### putBatch<sup>8+</sup>
2407e41f4b71Sopenharmony_ci
2408e41f4b71Sopenharmony_ciputBatch(entries: Entry[]): Promise&lt;void&gt;
2409e41f4b71Sopenharmony_ci
2410e41f4b71Sopenharmony_ciInserts KV pairs in batches to this KV store. This API uses a promise to return the result.
2411e41f4b71Sopenharmony_ci
2412e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2413e41f4b71Sopenharmony_ci
2414e41f4b71Sopenharmony_ci**Parameters**
2415e41f4b71Sopenharmony_ci
2416e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2417e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2418e41f4b71Sopenharmony_ci| entries  |[Entry](#entry)[] | Yes   |KV pairs to insert in batches. |
2419e41f4b71Sopenharmony_ci
2420e41f4b71Sopenharmony_ci**Return value**
2421e41f4b71Sopenharmony_ci
2422e41f4b71Sopenharmony_ci| Type   | Description      |
2423e41f4b71Sopenharmony_ci| ------  | -------   |
2424e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2425e41f4b71Sopenharmony_ci
2426e41f4b71Sopenharmony_ci**Example**
2427e41f4b71Sopenharmony_ci
2428e41f4b71Sopenharmony_ci```js
2429e41f4b71Sopenharmony_cilet kvStore;
2430e41f4b71Sopenharmony_citry {
2431e41f4b71Sopenharmony_ci    let entries = [];
2432e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
2433e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
2434e41f4b71Sopenharmony_ci        var entry = {
2435e41f4b71Sopenharmony_ci            key : key + i,
2436e41f4b71Sopenharmony_ci            value : {
2437e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
2438e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
2439e41f4b71Sopenharmony_ci            }
2440e41f4b71Sopenharmony_ci        }
2441e41f4b71Sopenharmony_ci        entries.push(entry);
2442e41f4b71Sopenharmony_ci    }
2443e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
2444e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
2445e41f4b71Sopenharmony_ci        console.log('putBatch success');
2446e41f4b71Sopenharmony_ci        kvStore.getEntries('batch_test_string_key').then((entries) => {
2447e41f4b71Sopenharmony_ci            console.log('getEntries success');
2448e41f4b71Sopenharmony_ci            console.log('PutBatch ' + JSON.stringify(entries));
2449e41f4b71Sopenharmony_ci        }).catch((err) => {
2450e41f4b71Sopenharmony_ci            console.log('getEntries fail ' + JSON.stringify(err));
2451e41f4b71Sopenharmony_ci        });
2452e41f4b71Sopenharmony_ci    }).catch((err) => {
2453e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
2454e41f4b71Sopenharmony_ci    });
2455e41f4b71Sopenharmony_ci}catch(e) {
2456e41f4b71Sopenharmony_ci    console.log('PutBatch e ' + JSON.stringify(e));
2457e41f4b71Sopenharmony_ci}
2458e41f4b71Sopenharmony_ci```
2459e41f4b71Sopenharmony_ci
2460e41f4b71Sopenharmony_ci### deleteBatch<sup>8+</sup>
2461e41f4b71Sopenharmony_ci
2462e41f4b71Sopenharmony_cideleteBatch(keys: string[], callback: AsyncCallback&lt;void&gt;): void
2463e41f4b71Sopenharmony_ci
2464e41f4b71Sopenharmony_ciDeletes KV pairs in batches from this KV store. This API uses an asynchronous callback to return the result.
2465e41f4b71Sopenharmony_ci
2466e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2467e41f4b71Sopenharmony_ci
2468e41f4b71Sopenharmony_ci**Parameters**
2469e41f4b71Sopenharmony_ci
2470e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2471e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2472e41f4b71Sopenharmony_ci| keys  |string[] | Yes   |KV pairs to delete in batches. |
2473e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt; | Yes   |Callback used to return the result. |
2474e41f4b71Sopenharmony_ci
2475e41f4b71Sopenharmony_ci**Example**
2476e41f4b71Sopenharmony_ci
2477e41f4b71Sopenharmony_ci```js
2478e41f4b71Sopenharmony_cilet kvStore;
2479e41f4b71Sopenharmony_citry {
2480e41f4b71Sopenharmony_ci    let entries = [];
2481e41f4b71Sopenharmony_ci    let keys = [];
2482e41f4b71Sopenharmony_ci    for (var i = 0; i < 5; i++) {
2483e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
2484e41f4b71Sopenharmony_ci        var entry = {
2485e41f4b71Sopenharmony_ci            key : key + i,
2486e41f4b71Sopenharmony_ci            value : {
2487e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
2488e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
2489e41f4b71Sopenharmony_ci            }
2490e41f4b71Sopenharmony_ci        }
2491e41f4b71Sopenharmony_ci        entries.push(entry);
2492e41f4b71Sopenharmony_ci        keys.push(key + i);
2493e41f4b71Sopenharmony_ci    }
2494e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
2495e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err,data) {
2496e41f4b71Sopenharmony_ci        console.log('putBatch success');
2497e41f4b71Sopenharmony_ci        kvStore.deleteBatch(keys, async function (err,data) {
2498e41f4b71Sopenharmony_ci            console.log('deleteBatch success');
2499e41f4b71Sopenharmony_ci        });
2500e41f4b71Sopenharmony_ci    });
2501e41f4b71Sopenharmony_ci}catch(e) {
2502e41f4b71Sopenharmony_ci    console.log('DeleteBatch e ' + e);
2503e41f4b71Sopenharmony_ci}
2504e41f4b71Sopenharmony_ci```
2505e41f4b71Sopenharmony_ci
2506e41f4b71Sopenharmony_ci
2507e41f4b71Sopenharmony_ci### deleteBatch<sup>8+</sup>
2508e41f4b71Sopenharmony_ci
2509e41f4b71Sopenharmony_cideleteBatch(keys: string[]): Promise&lt;void&gt;
2510e41f4b71Sopenharmony_ci
2511e41f4b71Sopenharmony_ciDeletes KV pairs in batches from this KV store. This API uses a promise to return the result.
2512e41f4b71Sopenharmony_ci
2513e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2514e41f4b71Sopenharmony_ci
2515e41f4b71Sopenharmony_ci**Parameters**
2516e41f4b71Sopenharmony_ci
2517e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2518e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2519e41f4b71Sopenharmony_ci| keys   |string[] | Yes   |KV pairs to delete in batches. |
2520e41f4b71Sopenharmony_ci
2521e41f4b71Sopenharmony_ci**Return value**
2522e41f4b71Sopenharmony_ci
2523e41f4b71Sopenharmony_ci| Type   | Description      |
2524e41f4b71Sopenharmony_ci| ------  | -------   |
2525e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2526e41f4b71Sopenharmony_ci
2527e41f4b71Sopenharmony_ci**Example**
2528e41f4b71Sopenharmony_ci
2529e41f4b71Sopenharmony_ci```js
2530e41f4b71Sopenharmony_cilet kvStore;
2531e41f4b71Sopenharmony_citry {
2532e41f4b71Sopenharmony_ci    let entries = [];
2533e41f4b71Sopenharmony_ci    let keys = [];
2534e41f4b71Sopenharmony_ci    for (var i = 0; i < 5; i++) {
2535e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
2536e41f4b71Sopenharmony_ci        var entry = {
2537e41f4b71Sopenharmony_ci            key : key + i,
2538e41f4b71Sopenharmony_ci            value : {
2539e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
2540e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
2541e41f4b71Sopenharmony_ci            }
2542e41f4b71Sopenharmony_ci        }
2543e41f4b71Sopenharmony_ci        entries.push(entry);
2544e41f4b71Sopenharmony_ci        keys.push(key + i);
2545e41f4b71Sopenharmony_ci    }
2546e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
2547e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
2548e41f4b71Sopenharmony_ci        console.log('putBatch success');
2549e41f4b71Sopenharmony_ci        kvStore.deleteBatch(keys).then((err) => {
2550e41f4b71Sopenharmony_ci            console.log('deleteBatch success');
2551e41f4b71Sopenharmony_ci        }).catch((err) => {
2552e41f4b71Sopenharmony_ci            console.log('deleteBatch fail ' + JSON.stringify(err));
2553e41f4b71Sopenharmony_ci        });
2554e41f4b71Sopenharmony_ci    }).catch((err) => {
2555e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
2556e41f4b71Sopenharmony_ci    });
2557e41f4b71Sopenharmony_ci}catch(e) {
2558e41f4b71Sopenharmony_ci    console.log('DeleteBatch e ' + e);
2559e41f4b71Sopenharmony_ci}
2560e41f4b71Sopenharmony_ci```
2561e41f4b71Sopenharmony_ci
2562e41f4b71Sopenharmony_ci
2563e41f4b71Sopenharmony_ci### startTransaction<sup>8+</sup>
2564e41f4b71Sopenharmony_ci
2565e41f4b71Sopenharmony_cistartTransaction(callback: AsyncCallback&lt;void&gt;): void
2566e41f4b71Sopenharmony_ci
2567e41f4b71Sopenharmony_ciStarts the transaction in this KV store. This API uses an asynchronous callback to return the result.
2568e41f4b71Sopenharmony_ci
2569e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2570e41f4b71Sopenharmony_ci
2571e41f4b71Sopenharmony_ci**Parameters**
2572e41f4b71Sopenharmony_ci
2573e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2574e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2575e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt; | Yes   |Callback used to return the result. |
2576e41f4b71Sopenharmony_ci
2577e41f4b71Sopenharmony_ci**Example**
2578e41f4b71Sopenharmony_ci
2579e41f4b71Sopenharmony_ci```js
2580e41f4b71Sopenharmony_cilet kvStore;
2581e41f4b71Sopenharmony_cifunction putBatchString(len, prefix) {
2582e41f4b71Sopenharmony_ci    let entries = [];
2583e41f4b71Sopenharmony_ci    for (var i = 0; i < len; i++) {
2584e41f4b71Sopenharmony_ci        var entry = {
2585e41f4b71Sopenharmony_ci            key : prefix + i,
2586e41f4b71Sopenharmony_ci            value : {
2587e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
2588e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
2589e41f4b71Sopenharmony_ci            }
2590e41f4b71Sopenharmony_ci        }
2591e41f4b71Sopenharmony_ci        entries.push(entry);
2592e41f4b71Sopenharmony_ci    }
2593e41f4b71Sopenharmony_ci    return entries;
2594e41f4b71Sopenharmony_ci}
2595e41f4b71Sopenharmony_citry {
2596e41f4b71Sopenharmony_ci    var count = 0;
2597e41f4b71Sopenharmony_ci    kvStore.on('dataChange', 0, function (data) {
2598e41f4b71Sopenharmony_ci        console.log('startTransaction 0' + data)
2599e41f4b71Sopenharmony_ci        count++;
2600e41f4b71Sopenharmony_ci    });
2601e41f4b71Sopenharmony_ci    kvStore.startTransaction(async function (err,data) {
2602e41f4b71Sopenharmony_ci        console.log('startTransaction success');
2603e41f4b71Sopenharmony_ci        let entries = putBatchString(10, 'batch_test_string_key');
2604e41f4b71Sopenharmony_ci        console.log('entries: ' + JSON.stringify(entries));
2605e41f4b71Sopenharmony_ci        kvStore.putBatch(entries, async function (err,data) {
2606e41f4b71Sopenharmony_ci            console.log('putBatch success');
2607e41f4b71Sopenharmony_ci        });
2608e41f4b71Sopenharmony_ci    });
2609e41f4b71Sopenharmony_ci}catch(e) {
2610e41f4b71Sopenharmony_ci    console.log('startTransaction e ' + e);
2611e41f4b71Sopenharmony_ci}
2612e41f4b71Sopenharmony_ci```
2613e41f4b71Sopenharmony_ci
2614e41f4b71Sopenharmony_ci
2615e41f4b71Sopenharmony_ci### startTransaction<sup>8+</sup>
2616e41f4b71Sopenharmony_ci
2617e41f4b71Sopenharmony_cistartTransaction(): Promise&lt;void&gt;
2618e41f4b71Sopenharmony_ci
2619e41f4b71Sopenharmony_ciStarts the transaction in this KV store. This API uses a promise to return the result.
2620e41f4b71Sopenharmony_ci
2621e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2622e41f4b71Sopenharmony_ci
2623e41f4b71Sopenharmony_ci**Return value**
2624e41f4b71Sopenharmony_ci
2625e41f4b71Sopenharmony_ci| Type   | Description      |
2626e41f4b71Sopenharmony_ci| ------  | -------   |
2627e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2628e41f4b71Sopenharmony_ci
2629e41f4b71Sopenharmony_ci**Example**
2630e41f4b71Sopenharmony_ci
2631e41f4b71Sopenharmony_ci```js
2632e41f4b71Sopenharmony_cilet kvStore;
2633e41f4b71Sopenharmony_citry {
2634e41f4b71Sopenharmony_ci    var count = 0;
2635e41f4b71Sopenharmony_ci    kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
2636e41f4b71Sopenharmony_ci        console.log('startTransaction ' + JSON.stringify(data));
2637e41f4b71Sopenharmony_ci        count++;
2638e41f4b71Sopenharmony_ci    });
2639e41f4b71Sopenharmony_ci    kvStore.startTransaction().then(async (err) => {
2640e41f4b71Sopenharmony_ci        console.log('startTransaction success');
2641e41f4b71Sopenharmony_ci    }).catch((err) => {
2642e41f4b71Sopenharmony_ci        console.log('startTransaction fail ' + JSON.stringify(err));
2643e41f4b71Sopenharmony_ci    });
2644e41f4b71Sopenharmony_ci}catch(e) {
2645e41f4b71Sopenharmony_ci    console.log('startTransaction e ' + e);
2646e41f4b71Sopenharmony_ci}
2647e41f4b71Sopenharmony_ci```
2648e41f4b71Sopenharmony_ci
2649e41f4b71Sopenharmony_ci
2650e41f4b71Sopenharmony_ci### commit<sup>8+</sup>
2651e41f4b71Sopenharmony_ci
2652e41f4b71Sopenharmony_cicommit(callback: AsyncCallback&lt;void&gt;): void
2653e41f4b71Sopenharmony_ci
2654e41f4b71Sopenharmony_ciCommits the transaction in this KV store. This API uses an asynchronous callback to return the result.
2655e41f4b71Sopenharmony_ci
2656e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2657e41f4b71Sopenharmony_ci
2658e41f4b71Sopenharmony_ci**Parameters**
2659e41f4b71Sopenharmony_ci
2660e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2661e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2662e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt; | Yes   |Callback used to return the result. |
2663e41f4b71Sopenharmony_ci
2664e41f4b71Sopenharmony_ci**Example**
2665e41f4b71Sopenharmony_ci
2666e41f4b71Sopenharmony_ci```js
2667e41f4b71Sopenharmony_cilet kvStore;
2668e41f4b71Sopenharmony_citry {
2669e41f4b71Sopenharmony_ci    kvStore.commit(function (err,data) {
2670e41f4b71Sopenharmony_ci        if (err == undefined) {
2671e41f4b71Sopenharmony_ci            console.log('commit success');
2672e41f4b71Sopenharmony_ci        } else {
2673e41f4b71Sopenharmony_ci            console.log('commit fail');
2674e41f4b71Sopenharmony_ci        }
2675e41f4b71Sopenharmony_ci    });
2676e41f4b71Sopenharmony_ci}catch(e) {
2677e41f4b71Sopenharmony_ci    console.log('Commit e ' + e);
2678e41f4b71Sopenharmony_ci}
2679e41f4b71Sopenharmony_ci```
2680e41f4b71Sopenharmony_ci
2681e41f4b71Sopenharmony_ci
2682e41f4b71Sopenharmony_ci### commit<sup>8+</sup>
2683e41f4b71Sopenharmony_ci
2684e41f4b71Sopenharmony_cicommit(): Promise&lt;void&gt;
2685e41f4b71Sopenharmony_ci
2686e41f4b71Sopenharmony_ciCommits the transaction in this KV store. This API uses a promise to return the result.
2687e41f4b71Sopenharmony_ci
2688e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2689e41f4b71Sopenharmony_ci
2690e41f4b71Sopenharmony_ci**Return value**
2691e41f4b71Sopenharmony_ci
2692e41f4b71Sopenharmony_ci| Type   | Description      |
2693e41f4b71Sopenharmony_ci| ------  | -------   |
2694e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2695e41f4b71Sopenharmony_ci
2696e41f4b71Sopenharmony_ci**Example**
2697e41f4b71Sopenharmony_ci
2698e41f4b71Sopenharmony_ci```js
2699e41f4b71Sopenharmony_cilet kvStore;
2700e41f4b71Sopenharmony_citry {
2701e41f4b71Sopenharmony_ci    kvStore.commit().then(async (err) => {
2702e41f4b71Sopenharmony_ci        console.log('commit success');
2703e41f4b71Sopenharmony_ci    }).catch((err) => {
2704e41f4b71Sopenharmony_ci        console.log('commit fail ' + JSON.stringify(err));
2705e41f4b71Sopenharmony_ci    });
2706e41f4b71Sopenharmony_ci}catch(e) {
2707e41f4b71Sopenharmony_ci    console.log('Commit e ' + e);
2708e41f4b71Sopenharmony_ci}
2709e41f4b71Sopenharmony_ci```
2710e41f4b71Sopenharmony_ci
2711e41f4b71Sopenharmony_ci
2712e41f4b71Sopenharmony_ci### rollback<sup>8+</sup>
2713e41f4b71Sopenharmony_ci
2714e41f4b71Sopenharmony_cirollback(callback: AsyncCallback&lt;void&gt;): void
2715e41f4b71Sopenharmony_ci
2716e41f4b71Sopenharmony_ciRolls back the transaction in this KV store. This API uses an asynchronous callback to return the result.
2717e41f4b71Sopenharmony_ci
2718e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2719e41f4b71Sopenharmony_ci
2720e41f4b71Sopenharmony_ci**Parameters**
2721e41f4b71Sopenharmony_ci
2722e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2723e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2724e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt; | Yes   |Callback used to return the result. |
2725e41f4b71Sopenharmony_ci
2726e41f4b71Sopenharmony_ci**Example**
2727e41f4b71Sopenharmony_ci
2728e41f4b71Sopenharmony_ci```js
2729e41f4b71Sopenharmony_cilet kvStore;
2730e41f4b71Sopenharmony_citry {
2731e41f4b71Sopenharmony_ci    kvStore.rollback(function (err,data) {
2732e41f4b71Sopenharmony_ci        if (err == undefined) {
2733e41f4b71Sopenharmony_ci            console.log('commit success');
2734e41f4b71Sopenharmony_ci        } else {
2735e41f4b71Sopenharmony_ci            console.log('commit fail');
2736e41f4b71Sopenharmony_ci        }
2737e41f4b71Sopenharmony_ci    });
2738e41f4b71Sopenharmony_ci}catch(e) {
2739e41f4b71Sopenharmony_ci    console.log('Rollback e ' + e);
2740e41f4b71Sopenharmony_ci}
2741e41f4b71Sopenharmony_ci```
2742e41f4b71Sopenharmony_ci
2743e41f4b71Sopenharmony_ci
2744e41f4b71Sopenharmony_ci### rollback<sup>8+</sup>
2745e41f4b71Sopenharmony_ci
2746e41f4b71Sopenharmony_cirollback(): Promise&lt;void&gt;
2747e41f4b71Sopenharmony_ci
2748e41f4b71Sopenharmony_ciRolls back the transaction in this KV store. This API uses a promise to return the result.
2749e41f4b71Sopenharmony_ci
2750e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2751e41f4b71Sopenharmony_ci
2752e41f4b71Sopenharmony_ci**Return value**
2753e41f4b71Sopenharmony_ci
2754e41f4b71Sopenharmony_ci| Type   | Description      |
2755e41f4b71Sopenharmony_ci| ------  | -------   |
2756e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2757e41f4b71Sopenharmony_ci
2758e41f4b71Sopenharmony_ci**Example**
2759e41f4b71Sopenharmony_ci
2760e41f4b71Sopenharmony_ci```js
2761e41f4b71Sopenharmony_cilet kvStore;
2762e41f4b71Sopenharmony_citry {
2763e41f4b71Sopenharmony_ci    kvStore.rollback().then(async (err) => {
2764e41f4b71Sopenharmony_ci        console.log('rollback success');
2765e41f4b71Sopenharmony_ci    }).catch((err) => {
2766e41f4b71Sopenharmony_ci        console.log('rollback fail ' + JSON.stringify(err));
2767e41f4b71Sopenharmony_ci    });
2768e41f4b71Sopenharmony_ci}catch(e) {
2769e41f4b71Sopenharmony_ci    console.log('Rollback e ' + e);
2770e41f4b71Sopenharmony_ci}
2771e41f4b71Sopenharmony_ci```
2772e41f4b71Sopenharmony_ci
2773e41f4b71Sopenharmony_ci
2774e41f4b71Sopenharmony_ci### enableSync<sup>8+</sup>
2775e41f4b71Sopenharmony_ci
2776e41f4b71Sopenharmony_cienableSync(enabled: boolean, callback: AsyncCallback&lt;void&gt;): void
2777e41f4b71Sopenharmony_ci
2778e41f4b71Sopenharmony_ciSets data sync, which can be enabled or disabled. This API uses an asynchronous callback to return the result.
2779e41f4b71Sopenharmony_ci
2780e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2781e41f4b71Sopenharmony_ci
2782e41f4b71Sopenharmony_ci**Parameters**
2783e41f4b71Sopenharmony_ci
2784e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2785e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2786e41f4b71Sopenharmony_ci| enabled  |boolean | Yes   |Whether to enable data sync. The value **true** means to enable data sync, and **false** means the opposite. |
2787e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt; | Yes   |Callback used to return the result. |
2788e41f4b71Sopenharmony_ci
2789e41f4b71Sopenharmony_ci**Example**
2790e41f4b71Sopenharmony_ci
2791e41f4b71Sopenharmony_ci```js
2792e41f4b71Sopenharmony_cilet kvStore;
2793e41f4b71Sopenharmony_citry {
2794e41f4b71Sopenharmony_ci    kvStore.enableSync(true, function (err,data) {
2795e41f4b71Sopenharmony_ci        if (err == undefined) {
2796e41f4b71Sopenharmony_ci            console.log('enableSync success');
2797e41f4b71Sopenharmony_ci        } else {
2798e41f4b71Sopenharmony_ci            console.log('enableSync fail');
2799e41f4b71Sopenharmony_ci        }
2800e41f4b71Sopenharmony_ci    });
2801e41f4b71Sopenharmony_ci}catch(e) {
2802e41f4b71Sopenharmony_ci    console.log('EnableSync e ' + e);
2803e41f4b71Sopenharmony_ci}
2804e41f4b71Sopenharmony_ci```
2805e41f4b71Sopenharmony_ci
2806e41f4b71Sopenharmony_ci
2807e41f4b71Sopenharmony_ci### enableSync<sup>8+</sup>
2808e41f4b71Sopenharmony_ci
2809e41f4b71Sopenharmony_cienableSync(enabled: boolean): Promise&lt;void&gt;
2810e41f4b71Sopenharmony_ci
2811e41f4b71Sopenharmony_ciSets data sync, which can be enabled or disabled. This API uses a promise to return the result.
2812e41f4b71Sopenharmony_ci
2813e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2814e41f4b71Sopenharmony_ci
2815e41f4b71Sopenharmony_ci**Parameters**
2816e41f4b71Sopenharmony_ci
2817e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2818e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2819e41f4b71Sopenharmony_ci| enabled  |boolean | Yes   |Whether to enable data sync. The value **true** means to enable data sync, and **false** means the opposite. |
2820e41f4b71Sopenharmony_ci
2821e41f4b71Sopenharmony_ci**Return value**
2822e41f4b71Sopenharmony_ci
2823e41f4b71Sopenharmony_ci| Type   | Description      |
2824e41f4b71Sopenharmony_ci| ------  | -------   |
2825e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2826e41f4b71Sopenharmony_ci
2827e41f4b71Sopenharmony_ci**Example**
2828e41f4b71Sopenharmony_ci
2829e41f4b71Sopenharmony_ci```js
2830e41f4b71Sopenharmony_cilet kvStore;
2831e41f4b71Sopenharmony_citry {
2832e41f4b71Sopenharmony_ci    kvStore.enableSync(true).then((err) => {
2833e41f4b71Sopenharmony_ci        console.log('enableSync success');
2834e41f4b71Sopenharmony_ci    }).catch((err) => {
2835e41f4b71Sopenharmony_ci        console.log('enableSync fail ' + JSON.stringify(err));
2836e41f4b71Sopenharmony_ci    });
2837e41f4b71Sopenharmony_ci}catch(e) {
2838e41f4b71Sopenharmony_ci    console.log('EnableSync e ' + e);
2839e41f4b71Sopenharmony_ci}
2840e41f4b71Sopenharmony_ci```
2841e41f4b71Sopenharmony_ci
2842e41f4b71Sopenharmony_ci
2843e41f4b71Sopenharmony_ci### setSyncRange<sup>8+</sup>
2844e41f4b71Sopenharmony_ci
2845e41f4b71Sopenharmony_cisetSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: AsyncCallback&lt;void&gt;): void
2846e41f4b71Sopenharmony_ci
2847e41f4b71Sopenharmony_ciSets the data sync range. This API uses an asynchronous callback to return the result.
2848e41f4b71Sopenharmony_ci
2849e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2850e41f4b71Sopenharmony_ci
2851e41f4b71Sopenharmony_ci**Parameters**
2852e41f4b71Sopenharmony_ci
2853e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2854e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2855e41f4b71Sopenharmony_ci| localLabels  |string[] | Yes   |Sync labels set for the local device. |
2856e41f4b71Sopenharmony_ci| remoteSupportLabels  |string[] | Yes   |Sync labels set for remote devices. |
2857e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt; | Yes   |Callback used to return the result. |
2858e41f4b71Sopenharmony_ci
2859e41f4b71Sopenharmony_ci**Example**
2860e41f4b71Sopenharmony_ci
2861e41f4b71Sopenharmony_ci```js
2862e41f4b71Sopenharmony_cilet kvStore;
2863e41f4b71Sopenharmony_citry {
2864e41f4b71Sopenharmony_ci    const localLabels = ['A', 'B'];
2865e41f4b71Sopenharmony_ci    const remoteSupportLabels = ['C', 'D'];
2866e41f4b71Sopenharmony_ci    kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err,data) {
2867e41f4b71Sopenharmony_ci        console.log('SetSyncRange put success');
2868e41f4b71Sopenharmony_ci    });
2869e41f4b71Sopenharmony_ci}catch(e) {
2870e41f4b71Sopenharmony_ci    console.log('SetSyncRange e ' + e);
2871e41f4b71Sopenharmony_ci}
2872e41f4b71Sopenharmony_ci```
2873e41f4b71Sopenharmony_ci
2874e41f4b71Sopenharmony_ci
2875e41f4b71Sopenharmony_ci### setSyncRange<sup>8+</sup>
2876e41f4b71Sopenharmony_ci
2877e41f4b71Sopenharmony_cisetSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise&lt;void&gt;
2878e41f4b71Sopenharmony_ci
2879e41f4b71Sopenharmony_ciSets the data sync range. This API uses a promise to return the result.
2880e41f4b71Sopenharmony_ci
2881e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2882e41f4b71Sopenharmony_ci
2883e41f4b71Sopenharmony_ci**Parameters**
2884e41f4b71Sopenharmony_ci
2885e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2886e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2887e41f4b71Sopenharmony_ci| localLabels  |string[] | Yes   |Sync labels set for the local device. |
2888e41f4b71Sopenharmony_ci| remoteSupportLabels  |string[] | Yes   |Sync labels set for remote devices. |
2889e41f4b71Sopenharmony_ci
2890e41f4b71Sopenharmony_ci
2891e41f4b71Sopenharmony_ci**Return value**
2892e41f4b71Sopenharmony_ci
2893e41f4b71Sopenharmony_ci| Type   | Description      |
2894e41f4b71Sopenharmony_ci| ------  | -------   |
2895e41f4b71Sopenharmony_ci| Promise&lt;void&gt; |Promise that returns no value.|
2896e41f4b71Sopenharmony_ci
2897e41f4b71Sopenharmony_ci**Example**
2898e41f4b71Sopenharmony_ci
2899e41f4b71Sopenharmony_ci```js
2900e41f4b71Sopenharmony_cilet kvStore;
2901e41f4b71Sopenharmony_citry {
2902e41f4b71Sopenharmony_ci    const localLabels = ['A', 'B'];
2903e41f4b71Sopenharmony_ci    const remoteSupportLabels = ['C', 'D'];
2904e41f4b71Sopenharmony_ci    kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => {
2905e41f4b71Sopenharmony_ci        console.log('setSyncRange success');
2906e41f4b71Sopenharmony_ci    }).catch((err) => {
2907e41f4b71Sopenharmony_ci        console.log('delete fail ' + err);
2908e41f4b71Sopenharmony_ci    });
2909e41f4b71Sopenharmony_ci}catch(e) {
2910e41f4b71Sopenharmony_ci    console.log('SetSyncRange e ' + e);
2911e41f4b71Sopenharmony_ci}
2912e41f4b71Sopenharmony_ci```
2913e41f4b71Sopenharmony_ci
2914e41f4b71Sopenharmony_ci
2915e41f4b71Sopenharmony_ci## SubscribeType
2916e41f4b71Sopenharmony_ci
2917e41f4b71Sopenharmony_ciEnumerates the subscription types.
2918e41f4b71Sopenharmony_ci
2919e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2920e41f4b71Sopenharmony_ci
2921e41f4b71Sopenharmony_ci| Name | Value  | Description                   |
2922e41f4b71Sopenharmony_ci| -----  | ------   | ----------------------- |
2923e41f4b71Sopenharmony_ci| SUBSCRIBE_TYPE_LOCAL  |0 |Local data changes. |
2924e41f4b71Sopenharmony_ci| SUBSCRIBE_TYPE_REMOTE |1 |Remote data changes. |
2925e41f4b71Sopenharmony_ci| SUBSCRIBE_TYPE_ALL  |2 |Local and remote data changes. |
2926e41f4b71Sopenharmony_ci
2927e41f4b71Sopenharmony_ci## ChangeNotification
2928e41f4b71Sopenharmony_ci
2929e41f4b71Sopenharmony_ciDefines the content of data change notifications, including inserted data, updated data, deleted data, and device ID.
2930e41f4b71Sopenharmony_ci
2931e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2932e41f4b71Sopenharmony_ci
2933e41f4b71Sopenharmony_ci| Name | Type  |Mandatory  | Description                   |
2934e41f4b71Sopenharmony_ci| ----- | -------   | ------|------------------------ |
2935e41f4b71Sopenharmony_ci| insertEntries | [Entry](#entry)[]   | Yes|Data inserted.  |
2936e41f4b71Sopenharmony_ci| updateEntries | [Entry](#entry)[]   | Yes|Data updated.  |
2937e41f4b71Sopenharmony_ci| deleteEntries | [Entry](#entry)[]   | Yes|Data deleted.  |
2938e41f4b71Sopenharmony_ci| deviceId | string   | Yes|UUID of the device. |
2939e41f4b71Sopenharmony_ci
2940e41f4b71Sopenharmony_ci## Entry
2941e41f4b71Sopenharmony_ci
2942e41f4b71Sopenharmony_ciDefines the KV pairs stored in the KV store.
2943e41f4b71Sopenharmony_ci
2944e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2945e41f4b71Sopenharmony_ci
2946e41f4b71Sopenharmony_ci| Name | Type  |Mandatory  | Description                   |
2947e41f4b71Sopenharmony_ci| ----- | -------   | ------|------------------------ |
2948e41f4b71Sopenharmony_ci| key | string   | Yes|Key of the KV pair stored in the KV store.  |
2949e41f4b71Sopenharmony_ci| value | [Value](#value) | Yes|Value of the KV pair stored in the KV store.  |
2950e41f4b71Sopenharmony_ci
2951e41f4b71Sopenharmony_ci
2952e41f4b71Sopenharmony_ci## Value
2953e41f4b71Sopenharmony_ci
2954e41f4b71Sopenharmony_ciDefines the **value** object in a KV store.
2955e41f4b71Sopenharmony_ci
2956e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2957e41f4b71Sopenharmony_ci
2958e41f4b71Sopenharmony_ci| Name | Type  |Mandatory  | Description                   |
2959e41f4b71Sopenharmony_ci| ----- | -------   | ------|------------------------ |
2960e41f4b71Sopenharmony_ci| type | [ValueType](#value)   | Yes|Type of the value.  |
2961e41f4b71Sopenharmony_ci| value | Uint8Array \| string \| number \| boolean| Yes|Value of the KV pair stored in the KV store.  |
2962e41f4b71Sopenharmony_ci
2963e41f4b71Sopenharmony_ci## ValueType
2964e41f4b71Sopenharmony_ci
2965e41f4b71Sopenharmony_ciEnumerates the data types.
2966e41f4b71Sopenharmony_ci
2967e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2968e41f4b71Sopenharmony_ci
2969e41f4b71Sopenharmony_ci| Name | Value  | Description                   |
2970e41f4b71Sopenharmony_ci| -----  | ------   | ----------------------- |
2971e41f4b71Sopenharmony_ci| STRING  |0 |String. |
2972e41f4b71Sopenharmony_ci| INTEGER |1 |Integer. |
2973e41f4b71Sopenharmony_ci| FLOAT   |2 |Float (single-precision floating point). |
2974e41f4b71Sopenharmony_ci| BYTE_ARRAY   |3 |Byte array. |
2975e41f4b71Sopenharmony_ci| BOOLEAN   |4 |Boolean. |
2976e41f4b71Sopenharmony_ci| DOUBLE   |5 |Double (double-precision floating point). |
2977e41f4b71Sopenharmony_ci
2978e41f4b71Sopenharmony_ci## SingleKVStore
2979e41f4b71Sopenharmony_ci
2980e41f4b71Sopenharmony_ciProvides APIs to query and synchronize data in a single KV store. This class inherits from [KVStore](#kvstore).
2981e41f4b71Sopenharmony_ci
2982e41f4b71Sopenharmony_ciData is not distinguished by device in a single KV store. The data written to different devices using the same key will be overwritten. For example, a single KV store can be used to synchronize a user's calendar and contact data between different devices.
2983e41f4b71Sopenharmony_ci
2984e41f4b71Sopenharmony_ciBefore calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** instance.
2985e41f4b71Sopenharmony_ci
2986e41f4b71Sopenharmony_ci### get
2987e41f4b71Sopenharmony_ci
2988e41f4b71Sopenharmony_ciget(key: string, callback: AsyncCallback&lt;Uint8Array | string | boolean | number&gt;): void
2989e41f4b71Sopenharmony_ci
2990e41f4b71Sopenharmony_ciObtains the value of the specified key. This API uses an asynchronous callback to return the result.
2991e41f4b71Sopenharmony_ci
2992e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
2993e41f4b71Sopenharmony_ci
2994e41f4b71Sopenharmony_ci**Parameters**
2995e41f4b71Sopenharmony_ci
2996e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
2997e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
2998e41f4b71Sopenharmony_ci| key    |string   | Yes   |Key of the value to obtain. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). |
2999e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;Uint8Array \| string \| boolean \| number&gt; | Yes   |Callback used to return the value obtained. |
3000e41f4b71Sopenharmony_ci
3001e41f4b71Sopenharmony_ci**Example**
3002e41f4b71Sopenharmony_ci
3003e41f4b71Sopenharmony_ci```js
3004e41f4b71Sopenharmony_cilet kvStore;
3005e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string';
3006e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-test-string';
3007e41f4b71Sopenharmony_citry {
3008e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) {
3009e41f4b71Sopenharmony_ci        if (err != undefined) {
3010e41f4b71Sopenharmony_ci            console.log("put err: " + JSON.stringify(err));
3011e41f4b71Sopenharmony_ci            return;
3012e41f4b71Sopenharmony_ci        }
3013e41f4b71Sopenharmony_ci        console.log("put success");
3014e41f4b71Sopenharmony_ci        kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) {
3015e41f4b71Sopenharmony_ci            console.log("get success data: " + data);
3016e41f4b71Sopenharmony_ci        });
3017e41f4b71Sopenharmony_ci    });
3018e41f4b71Sopenharmony_ci}catch (e) {
3019e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
3020e41f4b71Sopenharmony_ci}
3021e41f4b71Sopenharmony_ci```
3022e41f4b71Sopenharmony_ci
3023e41f4b71Sopenharmony_ci
3024e41f4b71Sopenharmony_ci### get
3025e41f4b71Sopenharmony_ci
3026e41f4b71Sopenharmony_ciget(key: string): Promise&lt;Uint8Array | string | boolean | number&gt;
3027e41f4b71Sopenharmony_ci
3028e41f4b71Sopenharmony_ciObtains the value of the specified key. This API uses a promise to return the result.
3029e41f4b71Sopenharmony_ci
3030e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3031e41f4b71Sopenharmony_ci
3032e41f4b71Sopenharmony_ci**Parameters**
3033e41f4b71Sopenharmony_ci
3034e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3035e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
3036e41f4b71Sopenharmony_ci| key    |string   | Yes   |Key of the value to obtain. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). |
3037e41f4b71Sopenharmony_ci
3038e41f4b71Sopenharmony_ci
3039e41f4b71Sopenharmony_ci**Return value**
3040e41f4b71Sopenharmony_ci
3041e41f4b71Sopenharmony_ci| Type   | Description      |
3042e41f4b71Sopenharmony_ci| ------  | -------   |
3043e41f4b71Sopenharmony_ci|Promise&lt;Uint8Array \| string \| boolean \| number&gt; |Promise used to return the value obtained.|
3044e41f4b71Sopenharmony_ci
3045e41f4b71Sopenharmony_ci**Example**
3046e41f4b71Sopenharmony_ci
3047e41f4b71Sopenharmony_ci```js
3048e41f4b71Sopenharmony_cilet kvStore;
3049e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string';
3050e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-test-string';
3051e41f4b71Sopenharmony_citry {
3052e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => {
3053e41f4b71Sopenharmony_ci        console.log("put success: " + JSON.stringify(data));
3054e41f4b71Sopenharmony_ci        kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
3055e41f4b71Sopenharmony_ci            console.log("get success data: " + data);
3056e41f4b71Sopenharmony_ci        }).catch((err) => {
3057e41f4b71Sopenharmony_ci            console.log("get err: " + JSON.stringify(err));
3058e41f4b71Sopenharmony_ci        });
3059e41f4b71Sopenharmony_ci    }).catch((err) => {
3060e41f4b71Sopenharmony_ci        console.log("put err: " + JSON.stringify(err));
3061e41f4b71Sopenharmony_ci    });
3062e41f4b71Sopenharmony_ci}catch (e) {
3063e41f4b71Sopenharmony_ci    console.log("An unexpected error occurred. Error:" + e);
3064e41f4b71Sopenharmony_ci}
3065e41f4b71Sopenharmony_ci```
3066e41f4b71Sopenharmony_ci
3067e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
3068e41f4b71Sopenharmony_ci
3069e41f4b71Sopenharmony_cigetEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
3070e41f4b71Sopenharmony_ci
3071e41f4b71Sopenharmony_ciObtains all KV pairs that match the specified key prefix. This API uses an asynchronous callback to return the result.
3072e41f4b71Sopenharmony_ci
3073e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3074e41f4b71Sopenharmony_ci
3075e41f4b71Sopenharmony_ci**Parameters**
3076e41f4b71Sopenharmony_ci
3077e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3078e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
3079e41f4b71Sopenharmony_ci| keyPrefix    |string   | Yes   |Key prefix to match. |
3080e41f4b71Sopenharmony_ci| callback    |AsyncCallback&lt;[Entry](#entry)[]&gt;   | Yes   |Callback used to return the KV pairs that match the specified prefix. |
3081e41f4b71Sopenharmony_ci
3082e41f4b71Sopenharmony_ci**Example**
3083e41f4b71Sopenharmony_ci
3084e41f4b71Sopenharmony_ci```js
3085e41f4b71Sopenharmony_cilet kvStore;
3086e41f4b71Sopenharmony_citry {
3087e41f4b71Sopenharmony_ci    let entries = [];
3088e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3089e41f4b71Sopenharmony_ci        var key = 'batch_test_number_key';
3090e41f4b71Sopenharmony_ci        var entry = {
3091e41f4b71Sopenharmony_ci            key : key + i,
3092e41f4b71Sopenharmony_ci            value : {
3093e41f4b71Sopenharmony_ci                type : distributedData.ValueType.INTEGER,
3094e41f4b71Sopenharmony_ci                value : 222
3095e41f4b71Sopenharmony_ci            }
3096e41f4b71Sopenharmony_ci        }
3097e41f4b71Sopenharmony_ci        entries.push(entry);
3098e41f4b71Sopenharmony_ci    }
3099e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err,data) {
3100e41f4b71Sopenharmony_ci        console.log('putBatch success');
3101e41f4b71Sopenharmony_ci        kvStore.getEntries('batch_test_number_key', function (err,entries) {
3102e41f4b71Sopenharmony_ci            console.log('getEntries success');
3103e41f4b71Sopenharmony_ci            console.log('entries.length: ' + entries.length);
3104e41f4b71Sopenharmony_ci            console.log('entries[0]: ' + JSON.stringify(entries[0]));
3105e41f4b71Sopenharmony_ci        });
3106e41f4b71Sopenharmony_ci    });
3107e41f4b71Sopenharmony_ci}catch(e) {
3108e41f4b71Sopenharmony_ci    console.log('PutBatch e ' + e);
3109e41f4b71Sopenharmony_ci}
3110e41f4b71Sopenharmony_ci```
3111e41f4b71Sopenharmony_ci
3112e41f4b71Sopenharmony_ci
3113e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
3114e41f4b71Sopenharmony_ci
3115e41f4b71Sopenharmony_cigetEntries(keyPrefix: string): Promise&lt;Entry[]&gt;
3116e41f4b71Sopenharmony_ci
3117e41f4b71Sopenharmony_ciObtains all KV pairs that match the specified key prefix. This API uses a promise to return the result.
3118e41f4b71Sopenharmony_ci
3119e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3120e41f4b71Sopenharmony_ci
3121e41f4b71Sopenharmony_ci**Parameters**
3122e41f4b71Sopenharmony_ci
3123e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3124e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
3125e41f4b71Sopenharmony_ci| keyPrefix    |string   | Yes   |Key prefix to match. |
3126e41f4b71Sopenharmony_ci
3127e41f4b71Sopenharmony_ci**Return value**
3128e41f4b71Sopenharmony_ci
3129e41f4b71Sopenharmony_ci| Type   | Description      |
3130e41f4b71Sopenharmony_ci| ------  | -------   |
3131e41f4b71Sopenharmony_ci|Promise&lt;[Entry](#entry)[]&gt; |Promise used to return the KV pairs that match the specified prefix.|
3132e41f4b71Sopenharmony_ci
3133e41f4b71Sopenharmony_ci**Example**
3134e41f4b71Sopenharmony_ci
3135e41f4b71Sopenharmony_ci```js
3136e41f4b71Sopenharmony_cilet kvStore;
3137e41f4b71Sopenharmony_citry {
3138e41f4b71Sopenharmony_ci    let entries = [];
3139e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3140e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
3141e41f4b71Sopenharmony_ci        var entry = {
3142e41f4b71Sopenharmony_ci            key : key + i,
3143e41f4b71Sopenharmony_ci            value : {
3144e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
3145e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
3146e41f4b71Sopenharmony_ci            }
3147e41f4b71Sopenharmony_ci        }
3148e41f4b71Sopenharmony_ci        entries.push(entry);
3149e41f4b71Sopenharmony_ci    }
3150e41f4b71Sopenharmony_ci    console.log('entries: ' + entries);
3151e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
3152e41f4b71Sopenharmony_ci        console.log('putBatch success');
3153e41f4b71Sopenharmony_ci        kvStore.getEntries('batch_test_string_key').then((entries) => {
3154e41f4b71Sopenharmony_ci            console.log('getEntries success');
3155e41f4b71Sopenharmony_ci            console.log('entries.length: ' + entries.length);
3156e41f4b71Sopenharmony_ci            console.log('entries[0]: ' + JSON.stringify(entries[0]));
3157e41f4b71Sopenharmony_ci            console.log('entries[0].value: ' + JSON.stringify(entries[0].value));
3158e41f4b71Sopenharmony_ci            console.log('entries[0].value.value: ' + entries[0].value.value);
3159e41f4b71Sopenharmony_ci        }).catch((err) => {
3160e41f4b71Sopenharmony_ci            console.log('getEntries fail ' + JSON.stringify(err));
3161e41f4b71Sopenharmony_ci        });
3162e41f4b71Sopenharmony_ci    }).catch((err) => {
3163e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
3164e41f4b71Sopenharmony_ci    });
3165e41f4b71Sopenharmony_ci}catch(e) {
3166e41f4b71Sopenharmony_ci    console.log('PutBatch e ' + e);
3167e41f4b71Sopenharmony_ci}
3168e41f4b71Sopenharmony_ci```
3169e41f4b71Sopenharmony_ci
3170e41f4b71Sopenharmony_ci
3171e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
3172e41f4b71Sopenharmony_ci
3173e41f4b71Sopenharmony_cigetEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
3174e41f4b71Sopenharmony_ci
3175e41f4b71Sopenharmony_ciObtains the KV pairs that match the specified **Query** object. This API uses an asynchronous callback to return the result.
3176e41f4b71Sopenharmony_ci
3177e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3178e41f4b71Sopenharmony_ci
3179e41f4b71Sopenharmony_ci**Parameters**
3180e41f4b71Sopenharmony_ci
3181e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3182e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
3183e41f4b71Sopenharmony_ci| query  |[Query](#query8)   | Yes   |Key prefix to match. |
3184e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;[Entry](#entry)[]&gt;   | Yes   |Callback used to return the KV pairs that match the specified **Query** object. |
3185e41f4b71Sopenharmony_ci
3186e41f4b71Sopenharmony_ci**Example**
3187e41f4b71Sopenharmony_ci
3188e41f4b71Sopenharmony_ci```js
3189e41f4b71Sopenharmony_cilet kvStore;
3190e41f4b71Sopenharmony_citry {
3191e41f4b71Sopenharmony_ci    var arr = new Uint8Array([21,31]);
3192e41f4b71Sopenharmony_ci    let entries = [];
3193e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3194e41f4b71Sopenharmony_ci        var key = 'batch_test_bool_key';
3195e41f4b71Sopenharmony_ci        var entry = {
3196e41f4b71Sopenharmony_ci            key : key + i,
3197e41f4b71Sopenharmony_ci            value : {
3198e41f4b71Sopenharmony_ci                type : distributedData.ValueType.BYTE_ARRAY,
3199e41f4b71Sopenharmony_ci                value : arr
3200e41f4b71Sopenharmony_ci            }
3201e41f4b71Sopenharmony_ci        }
3202e41f4b71Sopenharmony_ci        entries.push(entry);
3203e41f4b71Sopenharmony_ci    }
3204e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
3205e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err,data) {
3206e41f4b71Sopenharmony_ci        console.log('putBatch success');
3207e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
3208e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
3209e41f4b71Sopenharmony_ci        kvStore.getEntries(query, function (err,entries) {
3210e41f4b71Sopenharmony_ci            console.log('getEntries success');
3211e41f4b71Sopenharmony_ci            console.log('entries.length: ' + entries.length);
3212e41f4b71Sopenharmony_ci            console.log('entries[0]: ' + JSON.stringify(entries[0]));
3213e41f4b71Sopenharmony_ci        });
3214e41f4b71Sopenharmony_ci    });
3215e41f4b71Sopenharmony_ci    console.log('GetEntries success');
3216e41f4b71Sopenharmony_ci}catch(e) {
3217e41f4b71Sopenharmony_ci    console.log('GetEntries e ' + e);
3218e41f4b71Sopenharmony_ci}
3219e41f4b71Sopenharmony_ci```
3220e41f4b71Sopenharmony_ci
3221e41f4b71Sopenharmony_ci
3222e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
3223e41f4b71Sopenharmony_ci
3224e41f4b71Sopenharmony_cigetEntries(query: Query): Promise&lt;Entry[]&gt;
3225e41f4b71Sopenharmony_ci
3226e41f4b71Sopenharmony_ciObtains the KV pairs that match the specified **Query** object. This API uses a promise to return the result.
3227e41f4b71Sopenharmony_ci
3228e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3229e41f4b71Sopenharmony_ci
3230e41f4b71Sopenharmony_ci**Parameters**
3231e41f4b71Sopenharmony_ci
3232e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3233e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
3234e41f4b71Sopenharmony_ci| query  |[Query](#query8)   | Yes   |**Query** object to match. |
3235e41f4b71Sopenharmony_ci
3236e41f4b71Sopenharmony_ci**Return value**
3237e41f4b71Sopenharmony_ci
3238e41f4b71Sopenharmony_ci| Type   | Description      |
3239e41f4b71Sopenharmony_ci| ------  | -------   |
3240e41f4b71Sopenharmony_ci|Promise&lt;[Entry](#entry)[]&gt; |Promise used to return the KV pairs that match the specified **Query** object.|
3241e41f4b71Sopenharmony_ci
3242e41f4b71Sopenharmony_ci**Example**
3243e41f4b71Sopenharmony_ci
3244e41f4b71Sopenharmony_ci```js
3245e41f4b71Sopenharmony_cilet kvStore;
3246e41f4b71Sopenharmony_citry {
3247e41f4b71Sopenharmony_ci    var arr = new Uint8Array([21,31]);
3248e41f4b71Sopenharmony_ci    let entries = [];
3249e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3250e41f4b71Sopenharmony_ci        var key = 'batch_test_bool_key';
3251e41f4b71Sopenharmony_ci        var entry = {
3252e41f4b71Sopenharmony_ci            key : key + i,
3253e41f4b71Sopenharmony_ci            value : {
3254e41f4b71Sopenharmony_ci                type : distributedData.ValueType.BYTE_ARRAY,
3255e41f4b71Sopenharmony_ci                value : arr
3256e41f4b71Sopenharmony_ci            }
3257e41f4b71Sopenharmony_ci        }
3258e41f4b71Sopenharmony_ci        entries.push(entry);
3259e41f4b71Sopenharmony_ci    }
3260e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
3261e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
3262e41f4b71Sopenharmony_ci        console.log('putBatch success');
3263e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
3264e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
3265e41f4b71Sopenharmony_ci        kvStore.getEntries(query).then((entries) => {
3266e41f4b71Sopenharmony_ci            console.log('getEntries success');
3267e41f4b71Sopenharmony_ci        }).catch((err) => {
3268e41f4b71Sopenharmony_ci            console.log('getEntries fail ' + JSON.stringify(err));
3269e41f4b71Sopenharmony_ci        });
3270e41f4b71Sopenharmony_ci    }).catch((err) => {
3271e41f4b71Sopenharmony_ci        console.log('GetEntries putBatch fail ' + JSON.stringify(err))
3272e41f4b71Sopenharmony_ci    });
3273e41f4b71Sopenharmony_ci    console.log('GetEntries success');
3274e41f4b71Sopenharmony_ci}catch(e) {
3275e41f4b71Sopenharmony_ci    console.log('GetEntries e ' + e);
3276e41f4b71Sopenharmony_ci}
3277e41f4b71Sopenharmony_ci```
3278e41f4b71Sopenharmony_ci
3279e41f4b71Sopenharmony_ci
3280e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup><a name="singlekvstore_getresultset"></a>
3281e41f4b71Sopenharmony_ci
3282e41f4b71Sopenharmony_cigetResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
3283e41f4b71Sopenharmony_ci
3284e41f4b71Sopenharmony_ciObtains the result set with the specified prefix. This API uses an asynchronous callback to return the result.
3285e41f4b71Sopenharmony_ci
3286e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3287e41f4b71Sopenharmony_ci
3288e41f4b71Sopenharmony_ci**Parameters**
3289e41f4b71Sopenharmony_ci
3290e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3291e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
3292e41f4b71Sopenharmony_ci| keyPrefix  |string   | Yes   |Key prefix to match.|
3293e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt;   | Yes   |Callback used to return the result set with the specified prefix.|
3294e41f4b71Sopenharmony_ci
3295e41f4b71Sopenharmony_ci**Example**
3296e41f4b71Sopenharmony_ci
3297e41f4b71Sopenharmony_ci```js
3298e41f4b71Sopenharmony_cilet kvStore;
3299e41f4b71Sopenharmony_citry {
3300e41f4b71Sopenharmony_ci    let resultSet;
3301e41f4b71Sopenharmony_ci    let entries = [];
3302e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3303e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
3304e41f4b71Sopenharmony_ci        var entry = {
3305e41f4b71Sopenharmony_ci            key : key + i,
3306e41f4b71Sopenharmony_ci            value : {
3307e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
3308e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
3309e41f4b71Sopenharmony_ci            }
3310e41f4b71Sopenharmony_ci        }
3311e41f4b71Sopenharmony_ci        entries.push(entry);
3312e41f4b71Sopenharmony_ci    }
3313e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err, data) {
3314e41f4b71Sopenharmony_ci        console.log('GetResultSet putBatch success');
3315e41f4b71Sopenharmony_ci        kvStore.getResultSet('batch_test_string_key', async function (err, result) {
3316e41f4b71Sopenharmony_ci            console.log('GetResultSet getResultSet succeed.');
3317e41f4b71Sopenharmony_ci            resultSet = result;
3318e41f4b71Sopenharmony_ci            kvStore.closeResultSet(resultSet, function (err, data) {
3319e41f4b71Sopenharmony_ci                console.log('GetResultSet closeResultSet success');
3320e41f4b71Sopenharmony_ci            })
3321e41f4b71Sopenharmony_ci        });
3322e41f4b71Sopenharmony_ci    });
3323e41f4b71Sopenharmony_ci}catch(e) {
3324e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
3325e41f4b71Sopenharmony_ci}
3326e41f4b71Sopenharmony_ci```
3327e41f4b71Sopenharmony_ci
3328e41f4b71Sopenharmony_ci
3329e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup>
3330e41f4b71Sopenharmony_ci
3331e41f4b71Sopenharmony_cigetResultSet(keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
3332e41f4b71Sopenharmony_ci
3333e41f4b71Sopenharmony_ciObtains the result set with the specified prefix. This API uses a promise to return the result.
3334e41f4b71Sopenharmony_ci
3335e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3336e41f4b71Sopenharmony_ci
3337e41f4b71Sopenharmony_ci**Parameters**
3338e41f4b71Sopenharmony_ci
3339e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3340e41f4b71Sopenharmony_ci| -----  | ------  | ----  | ----------------------- |
3341e41f4b71Sopenharmony_ci| keyPrefix  |string   | Yes   |Key prefix to match.|
3342e41f4b71Sopenharmony_ci
3343e41f4b71Sopenharmony_ci**Return value**
3344e41f4b71Sopenharmony_ci
3345e41f4b71Sopenharmony_ci| Type   | Description      |
3346e41f4b71Sopenharmony_ci| ------  | -------   |
3347e41f4b71Sopenharmony_ci|Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise used to return the result set with the specified prefix.|
3348e41f4b71Sopenharmony_ci
3349e41f4b71Sopenharmony_ci**Example**
3350e41f4b71Sopenharmony_ci
3351e41f4b71Sopenharmony_ci```js
3352e41f4b71Sopenharmony_cilet kvStore;
3353e41f4b71Sopenharmony_citry {
3354e41f4b71Sopenharmony_ci    let resultSet;
3355e41f4b71Sopenharmony_ci    let entries = [];
3356e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3357e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
3358e41f4b71Sopenharmony_ci        var entry = {
3359e41f4b71Sopenharmony_ci            key : key + i,
3360e41f4b71Sopenharmony_ci            value : {
3361e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
3362e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
3363e41f4b71Sopenharmony_ci            }
3364e41f4b71Sopenharmony_ci        }
3365e41f4b71Sopenharmony_ci        entries.push(entry);
3366e41f4b71Sopenharmony_ci    }
3367e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
3368e41f4b71Sopenharmony_ci        console.log('putBatch success');
3369e41f4b71Sopenharmony_ci    }).catch((err) => {
3370e41f4b71Sopenharmony_ci        console.log('PutBatch putBatch fail ' + JSON.stringify(err));
3371e41f4b71Sopenharmony_ci    });
3372e41f4b71Sopenharmony_ci    kvStore.getResultSet('batch_test_string_key').then((result) => {
3373e41f4b71Sopenharmony_ci        console.log('GetResult getResultSet succeed.');
3374e41f4b71Sopenharmony_ci        resultSet = result;
3375e41f4b71Sopenharmony_ci    }).catch((err) => {
3376e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + JSON.stringify(err));
3377e41f4b71Sopenharmony_ci    });
3378e41f4b71Sopenharmony_ci    kvStore.closeResultSet(resultSet).then((err) => {
3379e41f4b71Sopenharmony_ci        console.log('GetResult closeResultSet success');
3380e41f4b71Sopenharmony_ci    }).catch((err) => {
3381e41f4b71Sopenharmony_ci        console.log('closeResultSet fail ' + JSON.stringify(err));
3382e41f4b71Sopenharmony_ci    });
3383e41f4b71Sopenharmony_ci}catch(e) {
3384e41f4b71Sopenharmony_ci    console.log('GetResult e ' + e);
3385e41f4b71Sopenharmony_ci}
3386e41f4b71Sopenharmony_ci```
3387e41f4b71Sopenharmony_ci
3388e41f4b71Sopenharmony_ci
3389e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup>
3390e41f4b71Sopenharmony_ci
3391e41f4b71Sopenharmony_cigetResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
3392e41f4b71Sopenharmony_ci
3393e41f4b71Sopenharmony_ciObtains a **KvStoreResultSet** object that matches the specified **Query** object. This API uses an asynchronous callback to return the result.
3394e41f4b71Sopenharmony_ci
3395e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3396e41f4b71Sopenharmony_ci
3397e41f4b71Sopenharmony_ci**Parameters**
3398e41f4b71Sopenharmony_ci
3399e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3400e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3401e41f4b71Sopenharmony_ci| query  |Query    | Yes   |**Query** object to match.            |
3402e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt;   | Yes   |Callback used to return the **KvStoreResultSet** object obtained.|
3403e41f4b71Sopenharmony_ci
3404e41f4b71Sopenharmony_ci**Example**
3405e41f4b71Sopenharmony_ci
3406e41f4b71Sopenharmony_ci```js
3407e41f4b71Sopenharmony_cilet kvStore;
3408e41f4b71Sopenharmony_citry {
3409e41f4b71Sopenharmony_ci    let resultSet;
3410e41f4b71Sopenharmony_ci    let entries = [];
3411e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3412e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
3413e41f4b71Sopenharmony_ci        var entry = {
3414e41f4b71Sopenharmony_ci            key : key + i,
3415e41f4b71Sopenharmony_ci            value : {
3416e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
3417e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
3418e41f4b71Sopenharmony_ci            }
3419e41f4b71Sopenharmony_ci        }
3420e41f4b71Sopenharmony_ci        entries.push(entry);
3421e41f4b71Sopenharmony_ci    }
3422e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err, data) {
3423e41f4b71Sopenharmony_ci        console.log('putBatch success');
3424e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
3425e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
3426e41f4b71Sopenharmony_ci        kvStore.getResultSet(query, async function (err, result) {
3427e41f4b71Sopenharmony_ci            console.log('getResultSet succeed.');
3428e41f4b71Sopenharmony_ci            resultSet = result;
3429e41f4b71Sopenharmony_ci        });
3430e41f4b71Sopenharmony_ci    });
3431e41f4b71Sopenharmony_ci} catch(e) {
3432e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
3433e41f4b71Sopenharmony_ci}
3434e41f4b71Sopenharmony_ci```
3435e41f4b71Sopenharmony_ci
3436e41f4b71Sopenharmony_ci
3437e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup>
3438e41f4b71Sopenharmony_ci
3439e41f4b71Sopenharmony_cigetResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
3440e41f4b71Sopenharmony_ci
3441e41f4b71Sopenharmony_ciObtains a **KvStoreResultSet** object that matches the specified **Query** object. This API uses a promise to return the result.
3442e41f4b71Sopenharmony_ci
3443e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3444e41f4b71Sopenharmony_ci
3445e41f4b71Sopenharmony_ci**Parameters**
3446e41f4b71Sopenharmony_ci
3447e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3448e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3449e41f4b71Sopenharmony_ci| query  |[Query](#query8)    | Yes   |**Query** object to match.            |
3450e41f4b71Sopenharmony_ci
3451e41f4b71Sopenharmony_ci**Return value**
3452e41f4b71Sopenharmony_ci
3453e41f4b71Sopenharmony_ci| Type   | Description      |
3454e41f4b71Sopenharmony_ci| ------  | -------   |
3455e41f4b71Sopenharmony_ci|Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise used to return the **KvStoreResultSet** object obtained.|
3456e41f4b71Sopenharmony_ci
3457e41f4b71Sopenharmony_ci**Example**
3458e41f4b71Sopenharmony_ci
3459e41f4b71Sopenharmony_ci```js
3460e41f4b71Sopenharmony_cilet kvStore;
3461e41f4b71Sopenharmony_citry {
3462e41f4b71Sopenharmony_ci    let resultSet;
3463e41f4b71Sopenharmony_ci    let entries = [];
3464e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3465e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
3466e41f4b71Sopenharmony_ci        var entry = {
3467e41f4b71Sopenharmony_ci            key : key + i,
3468e41f4b71Sopenharmony_ci            value : {
3469e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
3470e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
3471e41f4b71Sopenharmony_ci            }
3472e41f4b71Sopenharmony_ci        }
3473e41f4b71Sopenharmony_ci        entries.push(entry);
3474e41f4b71Sopenharmony_ci    }
3475e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
3476e41f4b71Sopenharmony_ci        console.log('putBatch success');
3477e41f4b71Sopenharmony_ci    }).catch((err) => {
3478e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
3479e41f4b71Sopenharmony_ci    });
3480e41f4b71Sopenharmony_ci    const query = new distributedData.Query();
3481e41f4b71Sopenharmony_ci    query.prefixKey("batch_test");
3482e41f4b71Sopenharmony_ci    kvStore.getResultSet(query).then((result) => {
3483e41f4b71Sopenharmony_ci        console.log(' getResultSet succeed.');
3484e41f4b71Sopenharmony_ci        resultSet = result;
3485e41f4b71Sopenharmony_ci    }).catch((err) => {
3486e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + JSON.stringify(err));
3487e41f4b71Sopenharmony_ci    });
3488e41f4b71Sopenharmony_ci}catch(e) {
3489e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
3490e41f4b71Sopenharmony_ci}
3491e41f4b71Sopenharmony_ci```
3492e41f4b71Sopenharmony_ci
3493e41f4b71Sopenharmony_ci### closeResultSet<sup>8+</sup>
3494e41f4b71Sopenharmony_ci
3495e41f4b71Sopenharmony_cicloseResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void
3496e41f4b71Sopenharmony_ci
3497e41f4b71Sopenharmony_ciCloses the **KvStoreResultSet** object obtained by [SingleKvStore.getResultSet](#singlekvstore_getresultset). This API uses an asynchronous callback to return the result.
3498e41f4b71Sopenharmony_ci
3499e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3500e41f4b71Sopenharmony_ci
3501e41f4b71Sopenharmony_ci**Parameters**
3502e41f4b71Sopenharmony_ci
3503e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3504e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3505e41f4b71Sopenharmony_ci| resultSet  |[KvStoreResultSet](#kvstoreresultset8)   | Yes   |**KvStoreResultSet** object to close.            |
3506e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt;   | Yes   |Callback used to return the result.            |
3507e41f4b71Sopenharmony_ci
3508e41f4b71Sopenharmony_ci**Example**
3509e41f4b71Sopenharmony_ci
3510e41f4b71Sopenharmony_ci```js
3511e41f4b71Sopenharmony_cilet kvStore;
3512e41f4b71Sopenharmony_citry {
3513e41f4b71Sopenharmony_ci    let resultSet = null;
3514e41f4b71Sopenharmony_ci    kvStore.closeResultSet(resultSet, function (err, data) {
3515e41f4b71Sopenharmony_ci        if (err == undefined) {
3516e41f4b71Sopenharmony_ci            console.log('closeResultSet success');
3517e41f4b71Sopenharmony_ci        } else {
3518e41f4b71Sopenharmony_ci            console.log('closeResultSet fail');
3519e41f4b71Sopenharmony_ci        }
3520e41f4b71Sopenharmony_ci    });
3521e41f4b71Sopenharmony_ci}catch(e) {
3522e41f4b71Sopenharmony_ci    console.log('CloseResultSet e ' + e);
3523e41f4b71Sopenharmony_ci}
3524e41f4b71Sopenharmony_ci```
3525e41f4b71Sopenharmony_ci
3526e41f4b71Sopenharmony_ci
3527e41f4b71Sopenharmony_ci### closeResultSet<sup>8+</sup>
3528e41f4b71Sopenharmony_ci
3529e41f4b71Sopenharmony_cicloseResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
3530e41f4b71Sopenharmony_ci
3531e41f4b71Sopenharmony_ciCloses the **KvStoreResultSet** object obtained by [SingleKvStore.getResultSet](#singlekvstore_getresultset). This API uses a promise to return the result.
3532e41f4b71Sopenharmony_ci
3533e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3534e41f4b71Sopenharmony_ci
3535e41f4b71Sopenharmony_ci**Parameters**
3536e41f4b71Sopenharmony_ci
3537e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3538e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3539e41f4b71Sopenharmony_ci| resultSet  |[KvStoreResultSet](#kvstoreresultset8)   | Yes   |**KvStoreResultSet** object to close.            |
3540e41f4b71Sopenharmony_ci
3541e41f4b71Sopenharmony_ci**Return value**
3542e41f4b71Sopenharmony_ci
3543e41f4b71Sopenharmony_ci| Type   | Description      |
3544e41f4b71Sopenharmony_ci| ------  | -------   |
3545e41f4b71Sopenharmony_ci|Promise&lt;void&gt; |Promise that returns no value.|
3546e41f4b71Sopenharmony_ci
3547e41f4b71Sopenharmony_ci**Example**
3548e41f4b71Sopenharmony_ci
3549e41f4b71Sopenharmony_ci```js
3550e41f4b71Sopenharmony_cilet kvStore;
3551e41f4b71Sopenharmony_citry {
3552e41f4b71Sopenharmony_ci    let resultSet = null;
3553e41f4b71Sopenharmony_ci    kvStore.closeResultSet(resultSet).then(() => {
3554e41f4b71Sopenharmony_ci        console.log('closeResultSet success');
3555e41f4b71Sopenharmony_ci    }).catch((err) => {
3556e41f4b71Sopenharmony_ci        console.log('closeResultSet fail ' + JSON.stringify(err));
3557e41f4b71Sopenharmony_ci    });
3558e41f4b71Sopenharmony_ci}catch(e) {
3559e41f4b71Sopenharmony_ci    console.log('CloseResultSet e ' + e);
3560e41f4b71Sopenharmony_ci}
3561e41f4b71Sopenharmony_ci```
3562e41f4b71Sopenharmony_ci
3563e41f4b71Sopenharmony_ci
3564e41f4b71Sopenharmony_ci### getResultSize<sup>8+</sup>
3565e41f4b71Sopenharmony_ci
3566e41f4b71Sopenharmony_cigetResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
3567e41f4b71Sopenharmony_ci
3568e41f4b71Sopenharmony_ciObtains the number of results that match the specified **Query** object. This API uses an asynchronous callback to return the result.
3569e41f4b71Sopenharmony_ci
3570e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3571e41f4b71Sopenharmony_ci
3572e41f4b71Sopenharmony_ci**Parameters**
3573e41f4b71Sopenharmony_ci
3574e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3575e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3576e41f4b71Sopenharmony_ci| query  |[Query](#query8)   | Yes   |**Query** object to match.        |
3577e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;number&gt;   | Yes   |Callback used to return the number of results that match the specified **Query** object.        |
3578e41f4b71Sopenharmony_ci
3579e41f4b71Sopenharmony_ci**Example**
3580e41f4b71Sopenharmony_ci
3581e41f4b71Sopenharmony_ci```js
3582e41f4b71Sopenharmony_cilet kvStore;
3583e41f4b71Sopenharmony_citry {
3584e41f4b71Sopenharmony_ci    let entries = [];
3585e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3586e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
3587e41f4b71Sopenharmony_ci        var entry = {
3588e41f4b71Sopenharmony_ci            key : key + i,
3589e41f4b71Sopenharmony_ci            value : {
3590e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
3591e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
3592e41f4b71Sopenharmony_ci            }
3593e41f4b71Sopenharmony_ci        }
3594e41f4b71Sopenharmony_ci        entries.push(entry);
3595e41f4b71Sopenharmony_ci    }
3596e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err, data) {
3597e41f4b71Sopenharmony_ci        console.log('putBatch success');
3598e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
3599e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
3600e41f4b71Sopenharmony_ci        kvStore.getResultSize(query, async function (err, resultSize) {
3601e41f4b71Sopenharmony_ci            console.log('getResultSet succeed.');
3602e41f4b71Sopenharmony_ci        });
3603e41f4b71Sopenharmony_ci    });
3604e41f4b71Sopenharmony_ci} catch(e) {
3605e41f4b71Sopenharmony_ci    console.log('GetResultSize e ' + e);
3606e41f4b71Sopenharmony_ci}
3607e41f4b71Sopenharmony_ci```
3608e41f4b71Sopenharmony_ci
3609e41f4b71Sopenharmony_ci
3610e41f4b71Sopenharmony_ci### getResultSize<sup>8+</sup>
3611e41f4b71Sopenharmony_ci
3612e41f4b71Sopenharmony_cigetResultSize(query: Query): Promise&lt;number&gt;
3613e41f4b71Sopenharmony_ci
3614e41f4b71Sopenharmony_ciObtains the number of results that match the specified **Query** object. This API uses a promise to return the result.
3615e41f4b71Sopenharmony_ci
3616e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3617e41f4b71Sopenharmony_ci
3618e41f4b71Sopenharmony_ci**Parameters**
3619e41f4b71Sopenharmony_ci
3620e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3621e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3622e41f4b71Sopenharmony_ci| query  |[Query](#query8)   | Yes   |**Query** object to match.        |
3623e41f4b71Sopenharmony_ci
3624e41f4b71Sopenharmony_ci**Return value**
3625e41f4b71Sopenharmony_ci
3626e41f4b71Sopenharmony_ci| Type   | Description      |
3627e41f4b71Sopenharmony_ci| ------  | -------   |
3628e41f4b71Sopenharmony_ci|Promise&lt;number&gt; |Promise used to return the number of results obtained.|
3629e41f4b71Sopenharmony_ci
3630e41f4b71Sopenharmony_ci**Example**
3631e41f4b71Sopenharmony_ci
3632e41f4b71Sopenharmony_ci```js
3633e41f4b71Sopenharmony_cilet kvStore;
3634e41f4b71Sopenharmony_citry {
3635e41f4b71Sopenharmony_ci    let entries = [];
3636e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
3637e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
3638e41f4b71Sopenharmony_ci        var entry = {
3639e41f4b71Sopenharmony_ci            key : key + i,
3640e41f4b71Sopenharmony_ci            value : {
3641e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
3642e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
3643e41f4b71Sopenharmony_ci            }
3644e41f4b71Sopenharmony_ci        }
3645e41f4b71Sopenharmony_ci        entries.push(entry);
3646e41f4b71Sopenharmony_ci    }
3647e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
3648e41f4b71Sopenharmony_ci        console.log('putBatch success');
3649e41f4b71Sopenharmony_ci    }).catch((err) => {
3650e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
3651e41f4b71Sopenharmony_ci    });
3652e41f4b71Sopenharmony_ci    const query = new distributedData.Query();
3653e41f4b71Sopenharmony_ci    query.prefixKey("batch_test");
3654e41f4b71Sopenharmony_ci    kvStore.getResultSize(query).then((resultSize) => {
3655e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
3656e41f4b71Sopenharmony_ci    }).catch((err) => {
3657e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + JSON.stringify(err));
3658e41f4b71Sopenharmony_ci    });
3659e41f4b71Sopenharmony_ci}catch(e) {
3660e41f4b71Sopenharmony_ci    console.log('GetResultSize e ' + e);
3661e41f4b71Sopenharmony_ci}
3662e41f4b71Sopenharmony_ci```
3663e41f4b71Sopenharmony_ci
3664e41f4b71Sopenharmony_ci
3665e41f4b71Sopenharmony_ci### removeDeviceData<sup>8+</sup>
3666e41f4b71Sopenharmony_ci
3667e41f4b71Sopenharmony_ciremoveDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
3668e41f4b71Sopenharmony_ci
3669e41f4b71Sopenharmony_ciDeletes data of a device. This API uses an asynchronous callback to return the result.
3670e41f4b71Sopenharmony_ci> **NOTE**
3671e41f4b71Sopenharmony_ci>
3672e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
3673e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
3674e41f4b71Sopenharmony_ci
3675e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3676e41f4b71Sopenharmony_ci
3677e41f4b71Sopenharmony_ci**Parameters**
3678e41f4b71Sopenharmony_ci
3679e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3680e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3681e41f4b71Sopenharmony_ci| deviceId  |string   | Yes   |ID of the target device.      |
3682e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt;   | Yes   |Callback used to return the result.     |
3683e41f4b71Sopenharmony_ci
3684e41f4b71Sopenharmony_ci**Example**
3685e41f4b71Sopenharmony_ci
3686e41f4b71Sopenharmony_ci```js
3687e41f4b71Sopenharmony_cilet kvStore;
3688e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
3689e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-string-002';
3690e41f4b71Sopenharmony_citry {
3691e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
3692e41f4b71Sopenharmony_ci        console.log('put success');
3693e41f4b71Sopenharmony_ci        const deviceid = 'no_exist_device_id';
3694e41f4b71Sopenharmony_ci        kvStore.removeDeviceData(deviceid, async function (err,data) {
3695e41f4b71Sopenharmony_ci            if (err == undefined) {
3696e41f4b71Sopenharmony_ci                console.log('removeDeviceData success');
3697e41f4b71Sopenharmony_ci            } else {
3698e41f4b71Sopenharmony_ci                console.log('removeDeviceData fail');
3699e41f4b71Sopenharmony_ci                kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err,data) {
3700e41f4b71Sopenharmony_ci                    console.log('RemoveDeviceData get success');
3701e41f4b71Sopenharmony_ci                });
3702e41f4b71Sopenharmony_ci            }
3703e41f4b71Sopenharmony_ci        });
3704e41f4b71Sopenharmony_ci    });
3705e41f4b71Sopenharmony_ci}catch(e) {
3706e41f4b71Sopenharmony_ci    console.log('RemoveDeviceData e ' + e);
3707e41f4b71Sopenharmony_ci}
3708e41f4b71Sopenharmony_ci```
3709e41f4b71Sopenharmony_ci
3710e41f4b71Sopenharmony_ci
3711e41f4b71Sopenharmony_ci### removeDeviceData<sup>8+</sup>
3712e41f4b71Sopenharmony_ci
3713e41f4b71Sopenharmony_ciremoveDeviceData(deviceId: string): Promise&lt;void&gt;
3714e41f4b71Sopenharmony_ci
3715e41f4b71Sopenharmony_ciDeletes data of a device. This API uses a promise to return the result.
3716e41f4b71Sopenharmony_ci> **NOTE**
3717e41f4b71Sopenharmony_ci>
3718e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
3719e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
3720e41f4b71Sopenharmony_ci
3721e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3722e41f4b71Sopenharmony_ci
3723e41f4b71Sopenharmony_ci**Parameters**
3724e41f4b71Sopenharmony_ci
3725e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3726e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3727e41f4b71Sopenharmony_ci| deviceId  |string   | Yes   |ID of the target device.      |
3728e41f4b71Sopenharmony_ci
3729e41f4b71Sopenharmony_ci**Return value**
3730e41f4b71Sopenharmony_ci
3731e41f4b71Sopenharmony_ci| Type   | Description      |
3732e41f4b71Sopenharmony_ci| ------  | -------   |
3733e41f4b71Sopenharmony_ci|Promise&lt;void&gt; |Promise that returns no value.|
3734e41f4b71Sopenharmony_ci
3735e41f4b71Sopenharmony_ci**Example**
3736e41f4b71Sopenharmony_ci
3737e41f4b71Sopenharmony_ci```js
3738e41f4b71Sopenharmony_cilet kvStore;
3739e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
3740e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-string-001';
3741e41f4b71Sopenharmony_citry {
3742e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
3743e41f4b71Sopenharmony_ci        console.log('removeDeviceData put success');
3744e41f4b71Sopenharmony_ci    }).catch((err) => {
3745e41f4b71Sopenharmony_ci        console.log('put fail ' + JSON.stringify(err));
3746e41f4b71Sopenharmony_ci    });
3747e41f4b71Sopenharmony_ci    const deviceid = 'no_exist_device_id';
3748e41f4b71Sopenharmony_ci    kvStore.removeDeviceData(deviceid).then((err) => {
3749e41f4b71Sopenharmony_ci        console.log('removeDeviceData success');
3750e41f4b71Sopenharmony_ci    }).catch((err) => {
3751e41f4b71Sopenharmony_ci        console.log('removeDeviceData fail ' + JSON.stringify(err));
3752e41f4b71Sopenharmony_ci    });
3753e41f4b71Sopenharmony_ci    kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => {
3754e41f4b71Sopenharmony_ci        console.log('get success data:' + data);
3755e41f4b71Sopenharmony_ci    }).catch((err) => {
3756e41f4b71Sopenharmony_ci        console.log('RemoveDeviceData get fail ' + JSON.stringify(err));
3757e41f4b71Sopenharmony_ci    });
3758e41f4b71Sopenharmony_ci}catch(e) {
3759e41f4b71Sopenharmony_ci    console.log('RemoveDeviceData e ' + e);
3760e41f4b71Sopenharmony_ci}
3761e41f4b71Sopenharmony_ci```
3762e41f4b71Sopenharmony_ci
3763e41f4b71Sopenharmony_ci### sync
3764e41f4b71Sopenharmony_ci
3765e41f4b71Sopenharmony_ci
3766e41f4b71Sopenharmony_cisync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
3767e41f4b71Sopenharmony_ci
3768e41f4b71Sopenharmony_ciSynchronizes the KV store manually.
3769e41f4b71Sopenharmony_ci> **NOTE**
3770e41f4b71Sopenharmony_ci>
3771e41f4b71Sopenharmony_ci> **deviceIds** is **networkId** in <!--RP2-->[DeviceInfo](../apis-distributedservice-kit/js-apis-device-manager-sys.md#deviceinfo), which can be obtained by [deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP2End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
3772e41f4b71Sopenharmony_ci
3773e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
3774e41f4b71Sopenharmony_ci
3775e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3776e41f4b71Sopenharmony_ci
3777e41f4b71Sopenharmony_ci**Parameters**
3778e41f4b71Sopenharmony_ci
3779e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                          |
3780e41f4b71Sopenharmony_ci| --------- | --------------------- | ---- | ---------------------------------------------- |
3781e41f4b71Sopenharmony_ci| deviceIds | string[]              | Yes  | List of **networkId**s of the devices in the same networking environment to be synchronized.|
3782e41f4b71Sopenharmony_ci| mode      | [SyncMode](#syncmode) | Yes  | Sync mode.                                    |
3783e41f4b71Sopenharmony_ci| delayMs   | number                | No  | Delay time allowed, in milliseconds. The default value is **0**.    |
3784e41f4b71Sopenharmony_ci
3785e41f4b71Sopenharmony_ci**Example**
3786e41f4b71Sopenharmony_ci
3787e41f4b71Sopenharmony_ci```js
3788e41f4b71Sopenharmony_ciimport deviceManager from '@ohos.distributedHardware.deviceManager';
3789e41f4b71Sopenharmony_ci
3790e41f4b71Sopenharmony_cilet devManager;
3791e41f4b71Sopenharmony_cilet kvStore;
3792e41f4b71Sopenharmony_ciconst KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
3793e41f4b71Sopenharmony_ciconst VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
3794e41f4b71Sopenharmony_ci// create deviceManager
3795e41f4b71Sopenharmony_cideviceManager.createDeviceManager('bundleName', (err, value) => {
3796e41f4b71Sopenharmony_ci  if (!err) {
3797e41f4b71Sopenharmony_ci    devManager = value;
3798e41f4b71Sopenharmony_ci    let deviceIds = [];
3799e41f4b71Sopenharmony_ci    if (devManager != null) {
3800e41f4b71Sopenharmony_ci      var devices = devManager.getTrustedDeviceListSync();
3801e41f4b71Sopenharmony_ci      for (var i = 0; i < devices.length; i++) {
3802e41f4b71Sopenharmony_ci        deviceIds[i] = devices[i].networkId;
3803e41f4b71Sopenharmony_ci      }
3804e41f4b71Sopenharmony_ci    }
3805e41f4b71Sopenharmony_ci    try {
3806e41f4b71Sopenharmony_ci      kvStore.on('syncComplete', function (data) {
3807e41f4b71Sopenharmony_ci        console.log('Sync dataChange');
3808e41f4b71Sopenharmony_ci      });
3809e41f4b71Sopenharmony_ci      kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
3810e41f4b71Sopenharmony_ci        if (err != undefined) {
3811e41f4b71Sopenharmony_ci          console.log("put err: " + JSON.stringify(err));
3812e41f4b71Sopenharmony_ci          return;
3813e41f4b71Sopenharmony_ci        }
3814e41f4b71Sopenharmony_ci        console.log('Succeeded in putting data');
3815e41f4b71Sopenharmony_ci        const mode = distributedData.SyncMode.PULL_ONLY;
3816e41f4b71Sopenharmony_ci        kvStore.sync(deviceIds, mode, 1000);
3817e41f4b71Sopenharmony_ci      });
3818e41f4b71Sopenharmony_ci    } catch (e) {
3819e41f4b71Sopenharmony_ci      console.log('Sync e' + e);
3820e41f4b71Sopenharmony_ci    }
3821e41f4b71Sopenharmony_ci  }
3822e41f4b71Sopenharmony_ci});
3823e41f4b71Sopenharmony_ci```
3824e41f4b71Sopenharmony_ci
3825e41f4b71Sopenharmony_ci### on('dataChange')<sup>8+</sup>
3826e41f4b71Sopenharmony_ci
3827e41f4b71Sopenharmony_cion(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
3828e41f4b71Sopenharmony_ci
3829e41f4b71Sopenharmony_ciSubscribes to data changes of the specified type.
3830e41f4b71Sopenharmony_ci
3831e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3832e41f4b71Sopenharmony_ci
3833e41f4b71Sopenharmony_ci**Parameters**
3834e41f4b71Sopenharmony_ci
3835e41f4b71Sopenharmony_ci| Name  | Type                                                     | Mandatory| Description                                                |
3836e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------- |
3837e41f4b71Sopenharmony_ci| event    | string                                                    | Yes  | Event type. The value is **dataChange**, which indicates data changes.|
3838e41f4b71Sopenharmony_ci| type     | [SubscribeType](#subscribetype)                           | Yes  | Type of data change.                                    |
3839e41f4b71Sopenharmony_ci| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes  | Callback used to return the data change.                     |
3840e41f4b71Sopenharmony_ci
3841e41f4b71Sopenharmony_ci**Example**
3842e41f4b71Sopenharmony_ci
3843e41f4b71Sopenharmony_ci```js
3844e41f4b71Sopenharmony_cilet kvStore;
3845e41f4b71Sopenharmony_cikvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) {
3846e41f4b71Sopenharmony_ci    console.log("dataChange callback call data: " + JSON.stringify(data));
3847e41f4b71Sopenharmony_ci});
3848e41f4b71Sopenharmony_ci```
3849e41f4b71Sopenharmony_ci
3850e41f4b71Sopenharmony_ci### on('syncComplete')<sup>8+</sup>
3851e41f4b71Sopenharmony_ci
3852e41f4b71Sopenharmony_cion(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
3853e41f4b71Sopenharmony_ci
3854e41f4b71Sopenharmony_ciSubscribes to sync complete events.
3855e41f4b71Sopenharmony_ci
3856e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3857e41f4b71Sopenharmony_ci
3858e41f4b71Sopenharmony_ci**Parameters**
3859e41f4b71Sopenharmony_ci
3860e41f4b71Sopenharmony_ci| Name      | Type                                         | Mandatory| Description                                                  |
3861e41f4b71Sopenharmony_ci| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------ |
3862e41f4b71Sopenharmony_ci| event        | string                                        | Yes  | Event type. The value is **syncComplete**, which indicates a sync complete event.|
3863e41f4b71Sopenharmony_ci| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes  | Callback used to return a sync complete event.            |
3864e41f4b71Sopenharmony_ci
3865e41f4b71Sopenharmony_ci**Example**
3866e41f4b71Sopenharmony_ci
3867e41f4b71Sopenharmony_ci```js
3868e41f4b71Sopenharmony_cilet kvStore;
3869e41f4b71Sopenharmony_ciconst KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
3870e41f4b71Sopenharmony_ciconst VALUE_TEST_FLOAT_ELEMENT = 321.12;
3871e41f4b71Sopenharmony_citry {
3872e41f4b71Sopenharmony_ci    kvStore.on('syncComplete', function (data) {
3873e41f4b71Sopenharmony_ci        console.log('syncComplete ' + data)
3874e41f4b71Sopenharmony_ci    });
3875e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
3876e41f4b71Sopenharmony_ci        console.log('syncComplete put success');
3877e41f4b71Sopenharmony_ci    }).catch((error) => {
3878e41f4b71Sopenharmony_ci        console.log('syncComplete put fail ' + error);
3879e41f4b71Sopenharmony_ci    });
3880e41f4b71Sopenharmony_ci}catch(e) {
3881e41f4b71Sopenharmony_ci    console.log('syncComplete put e ' + e);
3882e41f4b71Sopenharmony_ci}
3883e41f4b71Sopenharmony_ci```
3884e41f4b71Sopenharmony_ci
3885e41f4b71Sopenharmony_ci### off('dataChange')<sup>8+</sup>
3886e41f4b71Sopenharmony_ci
3887e41f4b71Sopenharmony_cioff(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
3888e41f4b71Sopenharmony_ci
3889e41f4b71Sopenharmony_ciUnsubscribes from data changes.
3890e41f4b71Sopenharmony_ci
3891e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3892e41f4b71Sopenharmony_ci
3893e41f4b71Sopenharmony_ci**Parameters**
3894e41f4b71Sopenharmony_ci
3895e41f4b71Sopenharmony_ci| Name  | Type                                                     | Mandatory| Description                                                    |
3896e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- |
3897e41f4b71Sopenharmony_ci| event    | string                                                    | Yes  | Event type. The value is **dataChange**, which indicates data changes.|
3898e41f4b71Sopenharmony_ci| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | No  | Callback to unregister. If this parameter is not specified, all callbacks for data changes will be unregistered.|
3899e41f4b71Sopenharmony_ci
3900e41f4b71Sopenharmony_ci**Example**
3901e41f4b71Sopenharmony_ci
3902e41f4b71Sopenharmony_ci```js
3903e41f4b71Sopenharmony_cilet kvStore;
3904e41f4b71Sopenharmony_ciclass KvstoreModel {
3905e41f4b71Sopenharmony_ci    call(data) {
3906e41f4b71Sopenharmony_ci        console.log("dataChange: " + data);
3907e41f4b71Sopenharmony_ci    }
3908e41f4b71Sopenharmony_ci    subscribeDataChange() {
3909e41f4b71Sopenharmony_ci        if (kvStore != null) {
3910e41f4b71Sopenharmony_ci            kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
3911e41f4b71Sopenharmony_ci        }
3912e41f4b71Sopenharmony_ci    }
3913e41f4b71Sopenharmony_ci    unsubscribeDataChange() {
3914e41f4b71Sopenharmony_ci        if (kvStore != null) {
3915e41f4b71Sopenharmony_ci            kvStore.off('dataChange', this.call);
3916e41f4b71Sopenharmony_ci        }
3917e41f4b71Sopenharmony_ci    }
3918e41f4b71Sopenharmony_ci}
3919e41f4b71Sopenharmony_ci```
3920e41f4b71Sopenharmony_ci
3921e41f4b71Sopenharmony_ci### off('syncComplete')<sup>8+</sup>
3922e41f4b71Sopenharmony_ci
3923e41f4b71Sopenharmony_cioff(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
3924e41f4b71Sopenharmony_ci
3925e41f4b71Sopenharmony_ciUnsubscribes from sync complete events.
3926e41f4b71Sopenharmony_ci
3927e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3928e41f4b71Sopenharmony_ci
3929e41f4b71Sopenharmony_ci**Parameters**
3930e41f4b71Sopenharmony_ci
3931e41f4b71Sopenharmony_ci| Name      | Type                                         | Mandatory| Description                                                      |
3932e41f4b71Sopenharmony_ci| ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- |
3933e41f4b71Sopenharmony_ci| event        | string                                        | Yes  | Event type. The value is **syncComplete**, which indicates a sync complete event.|
3934e41f4b71Sopenharmony_ci| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | No  | Callback to unregister. If this parameter is not specified, all callbacks for the sync complete event will be unregistered. |
3935e41f4b71Sopenharmony_ci
3936e41f4b71Sopenharmony_ci**Example**
3937e41f4b71Sopenharmony_ci
3938e41f4b71Sopenharmony_ci```js
3939e41f4b71Sopenharmony_cilet kvStore;
3940e41f4b71Sopenharmony_ciclass KvstoreModel {
3941e41f4b71Sopenharmony_ci    call(data) {
3942e41f4b71Sopenharmony_ci        console.log("syncComplete: " + data);
3943e41f4b71Sopenharmony_ci    }
3944e41f4b71Sopenharmony_ci    subscribeSyncComplete() {
3945e41f4b71Sopenharmony_ci        if (kvStore != null) {
3946e41f4b71Sopenharmony_ci            kvStore.on('syncComplete', this.call);
3947e41f4b71Sopenharmony_ci        }
3948e41f4b71Sopenharmony_ci    }
3949e41f4b71Sopenharmony_ci    unsubscribeSyncComplete() {
3950e41f4b71Sopenharmony_ci        if (kvStore != null) {
3951e41f4b71Sopenharmony_ci            kvStore.off('syncComplete', this.call);
3952e41f4b71Sopenharmony_ci        }
3953e41f4b71Sopenharmony_ci    }
3954e41f4b71Sopenharmony_ci}
3955e41f4b71Sopenharmony_ci```
3956e41f4b71Sopenharmony_ci
3957e41f4b71Sopenharmony_ci### setSyncParam<sup>8+</sup>
3958e41f4b71Sopenharmony_ci
3959e41f4b71Sopenharmony_cisetSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback&lt;void&gt;): void
3960e41f4b71Sopenharmony_ci
3961e41f4b71Sopenharmony_ciSets the default delay allowed for KV store sync. This API uses an asynchronous callback to return the result.
3962e41f4b71Sopenharmony_ci
3963e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3964e41f4b71Sopenharmony_ci
3965e41f4b71Sopenharmony_ci**Parameters**
3966e41f4b71Sopenharmony_ci
3967e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3968e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3969e41f4b71Sopenharmony_ci| defaultAllowedDelayMs  |number  | Yes   |Default delay allowed for database sync, in ms.   |
3970e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt;  | Yes  |Callback used to return the result.  |
3971e41f4b71Sopenharmony_ci
3972e41f4b71Sopenharmony_ci**Example**
3973e41f4b71Sopenharmony_ci
3974e41f4b71Sopenharmony_ci```js
3975e41f4b71Sopenharmony_cilet kvStore;
3976e41f4b71Sopenharmony_citry {
3977e41f4b71Sopenharmony_ci    const defaultAllowedDelayMs = 500;
3978e41f4b71Sopenharmony_ci    kvStore.setSyncParam(defaultAllowedDelayMs, function (err,data) {
3979e41f4b71Sopenharmony_ci        console.log('SetSyncParam put success');
3980e41f4b71Sopenharmony_ci    });
3981e41f4b71Sopenharmony_ci}catch(e) {
3982e41f4b71Sopenharmony_ci    console.log('testSingleKvStoreSetSyncParam e ' + e);
3983e41f4b71Sopenharmony_ci}
3984e41f4b71Sopenharmony_ci```
3985e41f4b71Sopenharmony_ci
3986e41f4b71Sopenharmony_ci
3987e41f4b71Sopenharmony_ci### setSyncParam<sup>8+</sup>
3988e41f4b71Sopenharmony_ci
3989e41f4b71Sopenharmony_cisetSyncParam(defaultAllowedDelayMs: number): Promise&lt;void&gt;
3990e41f4b71Sopenharmony_ci
3991e41f4b71Sopenharmony_ciSets the default delay allowed for KV store sync. This API uses a promise to return the result.
3992e41f4b71Sopenharmony_ci
3993e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
3994e41f4b71Sopenharmony_ci
3995e41f4b71Sopenharmony_ci**Parameters**
3996e41f4b71Sopenharmony_ci
3997e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
3998e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
3999e41f4b71Sopenharmony_ci| defaultAllowedDelayMs  |number  | Yes   |Default delay allowed for database sync, in ms.   |
4000e41f4b71Sopenharmony_ci
4001e41f4b71Sopenharmony_ci
4002e41f4b71Sopenharmony_ci**Return value**
4003e41f4b71Sopenharmony_ci
4004e41f4b71Sopenharmony_ci| Type   | Description      |
4005e41f4b71Sopenharmony_ci| ------  | -------   |
4006e41f4b71Sopenharmony_ci|Promise&lt;void&gt; |Promise that returns no value.|
4007e41f4b71Sopenharmony_ci
4008e41f4b71Sopenharmony_ci**Example**
4009e41f4b71Sopenharmony_ci
4010e41f4b71Sopenharmony_ci```js
4011e41f4b71Sopenharmony_cilet kvStore;
4012e41f4b71Sopenharmony_citry {
4013e41f4b71Sopenharmony_ci    const defaultAllowedDelayMs = 500;
4014e41f4b71Sopenharmony_ci    kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => {
4015e41f4b71Sopenharmony_ci        console.log('SetSyncParam put success');
4016e41f4b71Sopenharmony_ci    }).catch((err) => {
4017e41f4b71Sopenharmony_ci        console.log('SetSyncParam put fail ' + JSON.stringify(err));
4018e41f4b71Sopenharmony_ci    });
4019e41f4b71Sopenharmony_ci}catch(e) {
4020e41f4b71Sopenharmony_ci    console.log('SetSyncParam e ' + e);
4021e41f4b71Sopenharmony_ci}
4022e41f4b71Sopenharmony_ci```
4023e41f4b71Sopenharmony_ci
4024e41f4b71Sopenharmony_ci
4025e41f4b71Sopenharmony_ci### getSecurityLevel<sup>8+</sup>
4026e41f4b71Sopenharmony_ci
4027e41f4b71Sopenharmony_cigetSecurityLevel(callback: AsyncCallback&lt;SecurityLevel&gt;): void
4028e41f4b71Sopenharmony_ci
4029e41f4b71Sopenharmony_ciObtains the security level of this KV store. This API uses an asynchronous callback to return the result.
4030e41f4b71Sopenharmony_ci
4031e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
4032e41f4b71Sopenharmony_ci
4033e41f4b71Sopenharmony_ci**Parameters**
4034e41f4b71Sopenharmony_ci
4035e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4036e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4037e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;[SecurityLevel](#securitylevel)&gt;  | Yes   |Callback used to return the security level of the KV store.   |
4038e41f4b71Sopenharmony_ci
4039e41f4b71Sopenharmony_ci**Example**
4040e41f4b71Sopenharmony_ci
4041e41f4b71Sopenharmony_ci```js
4042e41f4b71Sopenharmony_cilet kvStore;
4043e41f4b71Sopenharmony_citry {
4044e41f4b71Sopenharmony_ci    kvStore.getSecurityLevel(function (err,data) {
4045e41f4b71Sopenharmony_ci        console.log('getSecurityLevel success');
4046e41f4b71Sopenharmony_ci    });
4047e41f4b71Sopenharmony_ci}catch(e) {
4048e41f4b71Sopenharmony_ci    console.log('GetSecurityLevel e ' + e);
4049e41f4b71Sopenharmony_ci}
4050e41f4b71Sopenharmony_ci```
4051e41f4b71Sopenharmony_ci
4052e41f4b71Sopenharmony_ci
4053e41f4b71Sopenharmony_ci### getSecurityLevel<sup>8+</sup>
4054e41f4b71Sopenharmony_ci
4055e41f4b71Sopenharmony_cigetSecurityLevel(): Promise&lt;SecurityLevel&gt;
4056e41f4b71Sopenharmony_ci
4057e41f4b71Sopenharmony_ciObtains the security level of this KV store. This API uses a promise to return the result.
4058e41f4b71Sopenharmony_ci
4059e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
4060e41f4b71Sopenharmony_ci
4061e41f4b71Sopenharmony_ci**Return value**
4062e41f4b71Sopenharmony_ci
4063e41f4b71Sopenharmony_ci| Type   | Description      |
4064e41f4b71Sopenharmony_ci| ------  | -------   |
4065e41f4b71Sopenharmony_ci|Promise&lt;[SecurityLevel](#securitylevel)&gt; |Promise used to return the security level of the KV store.|
4066e41f4b71Sopenharmony_ci
4067e41f4b71Sopenharmony_ci**Example**
4068e41f4b71Sopenharmony_ci
4069e41f4b71Sopenharmony_ci```js
4070e41f4b71Sopenharmony_cilet kvStore;
4071e41f4b71Sopenharmony_citry {
4072e41f4b71Sopenharmony_ci    kvStore.getSecurityLevel().then((data) => {
4073e41f4b71Sopenharmony_ci        console.log(' getSecurityLevel success');
4074e41f4b71Sopenharmony_ci    }).catch((err) => {
4075e41f4b71Sopenharmony_ci        console.log('getSecurityLevel fail ' + JSON.stringify(err));
4076e41f4b71Sopenharmony_ci    });
4077e41f4b71Sopenharmony_ci}catch(e) {
4078e41f4b71Sopenharmony_ci    console.log('GetSecurityLevel e ' + e);
4079e41f4b71Sopenharmony_ci}
4080e41f4b71Sopenharmony_ci```
4081e41f4b71Sopenharmony_ci
4082e41f4b71Sopenharmony_ci
4083e41f4b71Sopenharmony_ci## DeviceKVStore<sup>8+</sup> 
4084e41f4b71Sopenharmony_ci
4085e41f4b71Sopenharmony_ciProvides APIs to query and synchronize data in a device KV store. This class inherits from [KVStore](#kvstore).
4086e41f4b71Sopenharmony_ci
4087e41f4b71Sopenharmony_ciData is distinguished by device in a device KV store. Each device can only write and modify its own data. Data of other devices is read-only and cannot be modified.
4088e41f4b71Sopenharmony_ci
4089e41f4b71Sopenharmony_ciFor example, a device KV store can be used to implement image sharing between devices. The images of other devices can be viewed, but not be modified or deleted.
4090e41f4b71Sopenharmony_ci
4091e41f4b71Sopenharmony_ciBefore calling any method in **DeviceKVStore**, you must use [getKVStore](#getkvstore) to obtain a **DeviceKVStore** object.
4092e41f4b71Sopenharmony_ci
4093e41f4b71Sopenharmony_ci### get<sup>8+</sup>
4094e41f4b71Sopenharmony_ci
4095e41f4b71Sopenharmony_ciget(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void
4096e41f4b71Sopenharmony_ci
4097e41f4b71Sopenharmony_ciObtains a string value that matches the specified device ID and key. This API uses an asynchronous callback to return the result.
4098e41f4b71Sopenharmony_ci> **NOTE**
4099e41f4b71Sopenharmony_ci>
4100e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4101e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4102e41f4b71Sopenharmony_ci
4103e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4104e41f4b71Sopenharmony_ci
4105e41f4b71Sopenharmony_ci**Parameters**
4106e41f4b71Sopenharmony_ci
4107e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4108e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4109e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4110e41f4b71Sopenharmony_ci| key       |string  | Yes   |Key to match.   |
4111e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;boolean\|string\|number\|Uint8Array&gt;  | Yes   |Callback used to return the value obtained.   |
4112e41f4b71Sopenharmony_ci
4113e41f4b71Sopenharmony_ci**Example**
4114e41f4b71Sopenharmony_ci
4115e41f4b71Sopenharmony_ci```js
4116e41f4b71Sopenharmony_cilet kvStore;
4117e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
4118e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-string-002';
4119e41f4b71Sopenharmony_citry{
4120e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
4121e41f4b71Sopenharmony_ci        console.log('put success');
4122e41f4b71Sopenharmony_ci        kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err,data) {
4123e41f4b71Sopenharmony_ci            console.log('get success');
4124e41f4b71Sopenharmony_ci        });
4125e41f4b71Sopenharmony_ci    })
4126e41f4b71Sopenharmony_ci}catch(e) {
4127e41f4b71Sopenharmony_ci    console.log('get e' + e);
4128e41f4b71Sopenharmony_ci}
4129e41f4b71Sopenharmony_ci```
4130e41f4b71Sopenharmony_ci
4131e41f4b71Sopenharmony_ci
4132e41f4b71Sopenharmony_ci### get<sup>8+</sup>
4133e41f4b71Sopenharmony_ci
4134e41f4b71Sopenharmony_ciget(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&gt;
4135e41f4b71Sopenharmony_ci
4136e41f4b71Sopenharmony_ciObtains a string value that matches the specified device ID and key. This API uses a promise to return the result.
4137e41f4b71Sopenharmony_ci> **NOTE**
4138e41f4b71Sopenharmony_ci>
4139e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4140e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4141e41f4b71Sopenharmony_ci
4142e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4143e41f4b71Sopenharmony_ci
4144e41f4b71Sopenharmony_ci**Parameters**
4145e41f4b71Sopenharmony_ci
4146e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4147e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4148e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4149e41f4b71Sopenharmony_ci| key       |string  | Yes   |Key to match.   |
4150e41f4b71Sopenharmony_ci
4151e41f4b71Sopenharmony_ci**Return value**
4152e41f4b71Sopenharmony_ci
4153e41f4b71Sopenharmony_ci| Type   | Description      |
4154e41f4b71Sopenharmony_ci| ------  | -------   |
4155e41f4b71Sopenharmony_ci|Promise&lt;boolean\|string\|number\|Uint8Array&gt; |Promise used to return the string value that matches the given condition.|
4156e41f4b71Sopenharmony_ci
4157e41f4b71Sopenharmony_ci**Example**
4158e41f4b71Sopenharmony_ci
4159e41f4b71Sopenharmony_ci```js
4160e41f4b71Sopenharmony_cilet kvStore;
4161e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string_2';
4162e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-string-002';
4163e41f4b71Sopenharmony_citry {
4164e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => {
4165e41f4b71Sopenharmony_ci        console.log(' put success');
4166e41f4b71Sopenharmony_ci        kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
4167e41f4b71Sopenharmony_ci            console.log('get success');
4168e41f4b71Sopenharmony_ci        }).catch((err) => {
4169e41f4b71Sopenharmony_ci            console.log('get fail ' + JSON.stringify(err));
4170e41f4b71Sopenharmony_ci        });
4171e41f4b71Sopenharmony_ci    }).catch((error) => {
4172e41f4b71Sopenharmony_ci        console.log('put error' + error);
4173e41f4b71Sopenharmony_ci    });
4174e41f4b71Sopenharmony_ci} catch (e) {
4175e41f4b71Sopenharmony_ci    console.log('Get e ' + e);
4176e41f4b71Sopenharmony_ci}
4177e41f4b71Sopenharmony_ci```
4178e41f4b71Sopenharmony_ci
4179e41f4b71Sopenharmony_ci
4180e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
4181e41f4b71Sopenharmony_ci
4182e41f4b71Sopenharmony_cigetEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
4183e41f4b71Sopenharmony_ci
4184e41f4b71Sopenharmony_ciObtains all KV pairs that match the specified device ID and key prefix. This API uses an asynchronous callback to return the result.
4185e41f4b71Sopenharmony_ci> **NOTE**
4186e41f4b71Sopenharmony_ci>
4187e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4188e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4189e41f4b71Sopenharmony_ci
4190e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4191e41f4b71Sopenharmony_ci
4192e41f4b71Sopenharmony_ci**Parameters**
4193e41f4b71Sopenharmony_ci
4194e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4195e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4196e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4197e41f4b71Sopenharmony_ci| keyPrefix |string  | Yes   |Key prefix to match.   |
4198e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;[Entry](#entry)[]&gt;  | Yes |Callback used to return the KV pairs obtained.   |
4199e41f4b71Sopenharmony_ci
4200e41f4b71Sopenharmony_ci**Example**
4201e41f4b71Sopenharmony_ci
4202e41f4b71Sopenharmony_ci```js
4203e41f4b71Sopenharmony_cilet kvStore;
4204e41f4b71Sopenharmony_citry {
4205e41f4b71Sopenharmony_ci    let entries = [];
4206e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4207e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
4208e41f4b71Sopenharmony_ci        var entry = {
4209e41f4b71Sopenharmony_ci            key : key + i,
4210e41f4b71Sopenharmony_ci            value : {
4211e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
4212e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
4213e41f4b71Sopenharmony_ci            }
4214e41f4b71Sopenharmony_ci        }
4215e41f4b71Sopenharmony_ci        entries.push(entry);
4216e41f4b71Sopenharmony_ci    }
4217e41f4b71Sopenharmony_ci    console.log('entries: ' + entries);
4218e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err,data) {
4219e41f4b71Sopenharmony_ci        console.log('putBatch success');
4220e41f4b71Sopenharmony_ci        kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err,entries) {
4221e41f4b71Sopenharmony_ci            console.log('getEntries success');
4222e41f4b71Sopenharmony_ci            console.log('entries.length: ' + entries.length);
4223e41f4b71Sopenharmony_ci            console.log('entries[0]: ' + JSON.stringify(entries[0]));
4224e41f4b71Sopenharmony_ci        });
4225e41f4b71Sopenharmony_ci    });
4226e41f4b71Sopenharmony_ci}catch(e) {
4227e41f4b71Sopenharmony_ci    console.log('PutBatch e ' + e);
4228e41f4b71Sopenharmony_ci}
4229e41f4b71Sopenharmony_ci```
4230e41f4b71Sopenharmony_ci
4231e41f4b71Sopenharmony_ci
4232e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
4233e41f4b71Sopenharmony_ci
4234e41f4b71Sopenharmony_cigetEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt;
4235e41f4b71Sopenharmony_ci
4236e41f4b71Sopenharmony_ciObtains all KV pairs that match the specified device ID and key prefix. This API uses a promise to return the result.
4237e41f4b71Sopenharmony_ci> **NOTE**
4238e41f4b71Sopenharmony_ci>
4239e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4240e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4241e41f4b71Sopenharmony_ci
4242e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4243e41f4b71Sopenharmony_ci
4244e41f4b71Sopenharmony_ci**Parameters**
4245e41f4b71Sopenharmony_ci
4246e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4247e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4248e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4249e41f4b71Sopenharmony_ci| keyPrefix |string  | Yes   |Key prefix to match.   |
4250e41f4b71Sopenharmony_ci
4251e41f4b71Sopenharmony_ci**Return value**
4252e41f4b71Sopenharmony_ci
4253e41f4b71Sopenharmony_ci| Type   | Description      |
4254e41f4b71Sopenharmony_ci| ------  | -------   |
4255e41f4b71Sopenharmony_ci|Promise&lt;[Entry](#entry)[]&gt; |Promise used to return all the KV pairs that match the given condition.|
4256e41f4b71Sopenharmony_ci
4257e41f4b71Sopenharmony_ci**Example**
4258e41f4b71Sopenharmony_ci
4259e41f4b71Sopenharmony_ci```js
4260e41f4b71Sopenharmony_cilet kvStore;
4261e41f4b71Sopenharmony_citry {
4262e41f4b71Sopenharmony_ci    let entries = [];
4263e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4264e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
4265e41f4b71Sopenharmony_ci        var entry = {
4266e41f4b71Sopenharmony_ci            key : key + i,
4267e41f4b71Sopenharmony_ci            value : {
4268e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
4269e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
4270e41f4b71Sopenharmony_ci            }
4271e41f4b71Sopenharmony_ci        }
4272e41f4b71Sopenharmony_ci        entries.push(entry);
4273e41f4b71Sopenharmony_ci    }
4274e41f4b71Sopenharmony_ci    console.log('entries: ' + entries);
4275e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
4276e41f4b71Sopenharmony_ci        console.log('putBatch success');
4277e41f4b71Sopenharmony_ci        kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entries) => {
4278e41f4b71Sopenharmony_ci            console.log('getEntries success');
4279e41f4b71Sopenharmony_ci            console.log('entries.length: ' + entries.length);
4280e41f4b71Sopenharmony_ci            console.log('entries[0]: ' + JSON.stringify(entries[0]));
4281e41f4b71Sopenharmony_ci            console.log('entries[0].value: ' + JSON.stringify(entries[0].value));
4282e41f4b71Sopenharmony_ci            console.log('entries[0].value.value: ' + entries[0].value.value);
4283e41f4b71Sopenharmony_ci        }).catch((err) => {
4284e41f4b71Sopenharmony_ci            console.log('getEntries fail ' + JSON.stringify(err));
4285e41f4b71Sopenharmony_ci        });
4286e41f4b71Sopenharmony_ci    }).catch((err) => {
4287e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
4288e41f4b71Sopenharmony_ci    });
4289e41f4b71Sopenharmony_ci}catch(e) {
4290e41f4b71Sopenharmony_ci    console.log('PutBatch e ' + e);
4291e41f4b71Sopenharmony_ci}
4292e41f4b71Sopenharmony_ci```
4293e41f4b71Sopenharmony_ci
4294e41f4b71Sopenharmony_ci
4295e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
4296e41f4b71Sopenharmony_ci
4297e41f4b71Sopenharmony_cigetEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
4298e41f4b71Sopenharmony_ci
4299e41f4b71Sopenharmony_ciObtains the KV pairs that match the specified **Query** object. This API uses an asynchronous callback to return the result.
4300e41f4b71Sopenharmony_ci
4301e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4302e41f4b71Sopenharmony_ci
4303e41f4b71Sopenharmony_ci**Parameters**
4304e41f4b71Sopenharmony_ci
4305e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4306e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4307e41f4b71Sopenharmony_ci| query  |[Query](#query8)  | Yes   |**Query** object to match.   |
4308e41f4b71Sopenharmony_ci| callback |AsyncCallback&lt;[Entry](#entry)[]&gt;  | Yes   |Callback used to return the KV pairs obtained.   |
4309e41f4b71Sopenharmony_ci
4310e41f4b71Sopenharmony_ci**Example**
4311e41f4b71Sopenharmony_ci
4312e41f4b71Sopenharmony_ci```js
4313e41f4b71Sopenharmony_cilet kvStore;
4314e41f4b71Sopenharmony_citry {
4315e41f4b71Sopenharmony_ci    var arr = new Uint8Array([21,31]);
4316e41f4b71Sopenharmony_ci    let entries = [];
4317e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4318e41f4b71Sopenharmony_ci        var key = 'batch_test_bool_key';
4319e41f4b71Sopenharmony_ci        var entry = {
4320e41f4b71Sopenharmony_ci            key : key + i,
4321e41f4b71Sopenharmony_ci            value : {
4322e41f4b71Sopenharmony_ci                type : distributedData.ValueType.BYTE_ARRAY,
4323e41f4b71Sopenharmony_ci                value : arr
4324e41f4b71Sopenharmony_ci            }
4325e41f4b71Sopenharmony_ci        }
4326e41f4b71Sopenharmony_ci        entries.push(entry);
4327e41f4b71Sopenharmony_ci    }
4328e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
4329e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err,data) {
4330e41f4b71Sopenharmony_ci        console.log('putBatch success');
4331e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
4332e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
4333e41f4b71Sopenharmony_ci        query.deviceId('localDeviceId');
4334e41f4b71Sopenharmony_ci        kvStore.getEntries(query, function (err,entries) {
4335e41f4b71Sopenharmony_ci            console.log('getEntries success');
4336e41f4b71Sopenharmony_ci            console.log('entries.length: ' + entries.length);
4337e41f4b71Sopenharmony_ci            console.log('entries[0]: ' + JSON.stringify(entries[0]));
4338e41f4b71Sopenharmony_ci        });
4339e41f4b71Sopenharmony_ci    });
4340e41f4b71Sopenharmony_ci    console.log('GetEntries success');
4341e41f4b71Sopenharmony_ci}catch(e) {
4342e41f4b71Sopenharmony_ci    console.log('GetEntries e ' + e);
4343e41f4b71Sopenharmony_ci}
4344e41f4b71Sopenharmony_ci```
4345e41f4b71Sopenharmony_ci
4346e41f4b71Sopenharmony_ci
4347e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
4348e41f4b71Sopenharmony_ci
4349e41f4b71Sopenharmony_cigetEntries(query: Query): Promise&lt;Entry[]&gt;
4350e41f4b71Sopenharmony_ci
4351e41f4b71Sopenharmony_ciObtains the KV pairs that match the specified **Query** object. This API uses a promise to return the result.
4352e41f4b71Sopenharmony_ci
4353e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4354e41f4b71Sopenharmony_ci
4355e41f4b71Sopenharmony_ci**Parameters**
4356e41f4b71Sopenharmony_ci
4357e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4358e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4359e41f4b71Sopenharmony_ci| query  |[Query](#query8)  | Yes   |**Query** object to match.   |
4360e41f4b71Sopenharmony_ci
4361e41f4b71Sopenharmony_ci**Return value**
4362e41f4b71Sopenharmony_ci
4363e41f4b71Sopenharmony_ci| Type   | Description      |
4364e41f4b71Sopenharmony_ci| ------  | -------   |
4365e41f4b71Sopenharmony_ci|Promise&lt;[Entry](#entry)[]&gt; |Promise used to return the KV pairs that match the specified **Query** object.|
4366e41f4b71Sopenharmony_ci
4367e41f4b71Sopenharmony_ci**Example**
4368e41f4b71Sopenharmony_ci
4369e41f4b71Sopenharmony_ci```js
4370e41f4b71Sopenharmony_cilet kvStore;
4371e41f4b71Sopenharmony_citry {
4372e41f4b71Sopenharmony_ci    var arr = new Uint8Array([21,31]);
4373e41f4b71Sopenharmony_ci    let entries = [];
4374e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4375e41f4b71Sopenharmony_ci        var key = 'batch_test_bool_key';
4376e41f4b71Sopenharmony_ci        var entry = {
4377e41f4b71Sopenharmony_ci            key : key + i,
4378e41f4b71Sopenharmony_ci            value : {
4379e41f4b71Sopenharmony_ci                type : distributedData.ValueType.BYTE_ARRAY,
4380e41f4b71Sopenharmony_ci                value : arr
4381e41f4b71Sopenharmony_ci            }
4382e41f4b71Sopenharmony_ci        }
4383e41f4b71Sopenharmony_ci        entries.push(entry);
4384e41f4b71Sopenharmony_ci    }
4385e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
4386e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
4387e41f4b71Sopenharmony_ci        console.log('putBatch success');
4388e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
4389e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
4390e41f4b71Sopenharmony_ci        kvStore.getEntries(query).then((entries) => {
4391e41f4b71Sopenharmony_ci            console.log('getEntries success');
4392e41f4b71Sopenharmony_ci        }).catch((err) => {
4393e41f4b71Sopenharmony_ci            console.log('getEntries fail ' + JSON.stringify(err));
4394e41f4b71Sopenharmony_ci        });
4395e41f4b71Sopenharmony_ci    }).catch((err) => {
4396e41f4b71Sopenharmony_ci        console.log('GetEntries putBatch fail ' + JSON.stringify(err))
4397e41f4b71Sopenharmony_ci    });
4398e41f4b71Sopenharmony_ci    console.log('GetEntries success');
4399e41f4b71Sopenharmony_ci}catch(e) {
4400e41f4b71Sopenharmony_ci    console.log('GetEntries e ' + e);
4401e41f4b71Sopenharmony_ci}
4402e41f4b71Sopenharmony_ci```
4403e41f4b71Sopenharmony_ci
4404e41f4b71Sopenharmony_ci
4405e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
4406e41f4b71Sopenharmony_ci
4407e41f4b71Sopenharmony_cigetEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
4408e41f4b71Sopenharmony_ci
4409e41f4b71Sopenharmony_ciObtains the KV pairs that match the specified device ID and **Query** object. This API uses an asynchronous callback to return the result.
4410e41f4b71Sopenharmony_ci> **NOTE**
4411e41f4b71Sopenharmony_ci>
4412e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4413e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4414e41f4b71Sopenharmony_ci
4415e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4416e41f4b71Sopenharmony_ci
4417e41f4b71Sopenharmony_ci**Parameters**
4418e41f4b71Sopenharmony_ci
4419e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4420e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4421e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4422e41f4b71Sopenharmony_ci| query  |[Query](#query8)  | Yes   |**Query** object to match.   |
4423e41f4b71Sopenharmony_ci| callback |AsyncCallback&lt;[Entry](#entry)[]&gt;  | Yes   |Callback used to return the KV pairs that match the specified device ID and **Query** object.   |
4424e41f4b71Sopenharmony_ci
4425e41f4b71Sopenharmony_ci**Example**
4426e41f4b71Sopenharmony_ci
4427e41f4b71Sopenharmony_ci```js
4428e41f4b71Sopenharmony_cilet kvStore;
4429e41f4b71Sopenharmony_citry {
4430e41f4b71Sopenharmony_ci    var arr = new Uint8Array([21,31]);
4431e41f4b71Sopenharmony_ci    let entries = [];
4432e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4433e41f4b71Sopenharmony_ci        var key = 'batch_test_bool_key';
4434e41f4b71Sopenharmony_ci        var entry = {
4435e41f4b71Sopenharmony_ci            key : key + i,
4436e41f4b71Sopenharmony_ci            value : {
4437e41f4b71Sopenharmony_ci                type : distributedData.ValueType.BYTE_ARRAY,
4438e41f4b71Sopenharmony_ci                value : arr
4439e41f4b71Sopenharmony_ci            }
4440e41f4b71Sopenharmony_ci        }
4441e41f4b71Sopenharmony_ci        entries.push(entry);
4442e41f4b71Sopenharmony_ci    }
4443e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
4444e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err,data) {
4445e41f4b71Sopenharmony_ci        console.log('putBatch success');
4446e41f4b71Sopenharmony_ci        var query = new distributedData.Query();
4447e41f4b71Sopenharmony_ci        query.deviceId('localDeviceId');
4448e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
4449e41f4b71Sopenharmony_ci        kvStore.getEntries('localDeviceId', query, function (err,entries) {
4450e41f4b71Sopenharmony_ci            console.log('getEntries success');
4451e41f4b71Sopenharmony_ci            console.log('entries.length: ' + entries.length);
4452e41f4b71Sopenharmony_ci            console.log('entries[0]: ' + JSON.stringify(entries[0]));
4453e41f4b71Sopenharmony_ci        })
4454e41f4b71Sopenharmony_ci    });
4455e41f4b71Sopenharmony_ci    console.log('GetEntries success');
4456e41f4b71Sopenharmony_ci}catch(e) {
4457e41f4b71Sopenharmony_ci    console.log('GetEntries e ' + e);
4458e41f4b71Sopenharmony_ci}
4459e41f4b71Sopenharmony_ci```
4460e41f4b71Sopenharmony_ci
4461e41f4b71Sopenharmony_ci
4462e41f4b71Sopenharmony_ci### getEntries<sup>8+</sup>
4463e41f4b71Sopenharmony_ci
4464e41f4b71Sopenharmony_cigetEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt;
4465e41f4b71Sopenharmony_ci
4466e41f4b71Sopenharmony_ciObtains the KV pairs that match the specified device ID and **Query** object. This API uses a promise to return the result.
4467e41f4b71Sopenharmony_ci> **NOTE**
4468e41f4b71Sopenharmony_ci>
4469e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4470e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4471e41f4b71Sopenharmony_ci
4472e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4473e41f4b71Sopenharmony_ci
4474e41f4b71Sopenharmony_ci**Parameters**
4475e41f4b71Sopenharmony_ci
4476e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4477e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4478e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4479e41f4b71Sopenharmony_ci| query  |[Query](#query8)  | Yes   |**Query** object to match.   |
4480e41f4b71Sopenharmony_ci
4481e41f4b71Sopenharmony_ci**Return value**
4482e41f4b71Sopenharmony_ci
4483e41f4b71Sopenharmony_ci| Type   | Description      |
4484e41f4b71Sopenharmony_ci| ------  | -------   |
4485e41f4b71Sopenharmony_ci|Promise&lt;[Entry](#entry)[]&gt; |Promise used to return the KV pairs that match the specified device ID and **Query** object.|
4486e41f4b71Sopenharmony_ci
4487e41f4b71Sopenharmony_ci**Example**
4488e41f4b71Sopenharmony_ci
4489e41f4b71Sopenharmony_ci```js
4490e41f4b71Sopenharmony_cilet kvStore;
4491e41f4b71Sopenharmony_citry {
4492e41f4b71Sopenharmony_ci    var arr = new Uint8Array([21,31]);
4493e41f4b71Sopenharmony_ci    let entries = [];
4494e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4495e41f4b71Sopenharmony_ci        var key = 'batch_test_bool_key';
4496e41f4b71Sopenharmony_ci        var entry = {
4497e41f4b71Sopenharmony_ci            key : key + i,
4498e41f4b71Sopenharmony_ci            value : {
4499e41f4b71Sopenharmony_ci                type : distributedData.ValueType.BYTE_ARRAY,
4500e41f4b71Sopenharmony_ci                value : arr
4501e41f4b71Sopenharmony_ci            }
4502e41f4b71Sopenharmony_ci        }
4503e41f4b71Sopenharmony_ci        entries.push(entry);
4504e41f4b71Sopenharmony_ci    }
4505e41f4b71Sopenharmony_ci    console.log('entries: ' + JSON.stringify(entries));
4506e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
4507e41f4b71Sopenharmony_ci        console.log('putBatch success');
4508e41f4b71Sopenharmony_ci        var query = new distributedData.Query();
4509e41f4b71Sopenharmony_ci        query.deviceId('localDeviceId');
4510e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
4511e41f4b71Sopenharmony_ci        kvStore.getEntries('localDeviceId', query).then((entries) => {
4512e41f4b71Sopenharmony_ci            console.log('getEntries success');
4513e41f4b71Sopenharmony_ci        }).catch((err) => {
4514e41f4b71Sopenharmony_ci            console.log('getEntries fail ' + JSON.stringify(err));
4515e41f4b71Sopenharmony_ci        });
4516e41f4b71Sopenharmony_ci    }).catch((err) => {
4517e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
4518e41f4b71Sopenharmony_ci    });
4519e41f4b71Sopenharmony_ci    console.log('GetEntries success');
4520e41f4b71Sopenharmony_ci}catch(e) {
4521e41f4b71Sopenharmony_ci    console.log('GetEntries e ' + e);
4522e41f4b71Sopenharmony_ci}
4523e41f4b71Sopenharmony_ci```
4524e41f4b71Sopenharmony_ci
4525e41f4b71Sopenharmony_ci
4526e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup><a name="devicekvstore_getresultset"></a>
4527e41f4b71Sopenharmony_ci
4528e41f4b71Sopenharmony_cigetResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
4529e41f4b71Sopenharmony_ci
4530e41f4b71Sopenharmony_ciObtains a **KvStoreResultSet** object that matches the specified device ID and key prefix. This API uses an asynchronous callback to return the result.
4531e41f4b71Sopenharmony_ci> **NOTE**
4532e41f4b71Sopenharmony_ci>
4533e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4534e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4535e41f4b71Sopenharmony_ci
4536e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4537e41f4b71Sopenharmony_ci
4538e41f4b71Sopenharmony_ci**Parameters**
4539e41f4b71Sopenharmony_ci
4540e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4541e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4542e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4543e41f4b71Sopenharmony_ci| keyPrefix |string  | Yes   |Key prefix to match.   |
4544e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt;  | Yes |Callback used to return the **KvStoreResultSet** object that matches the specified device ID and key prefix.   |
4545e41f4b71Sopenharmony_ci
4546e41f4b71Sopenharmony_ci**Example**
4547e41f4b71Sopenharmony_ci
4548e41f4b71Sopenharmony_ci```js
4549e41f4b71Sopenharmony_cilet kvStore;
4550e41f4b71Sopenharmony_citry {
4551e41f4b71Sopenharmony_ci    let resultSet;
4552e41f4b71Sopenharmony_ci    kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
4553e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
4554e41f4b71Sopenharmony_ci        resultSet = result;
4555e41f4b71Sopenharmony_ci        kvStore.closeResultSet(resultSet, function (err, data) {
4556e41f4b71Sopenharmony_ci            console.log('closeResultSet success');
4557e41f4b71Sopenharmony_ci        })
4558e41f4b71Sopenharmony_ci    });
4559e41f4b71Sopenharmony_ci}catch(e) {
4560e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
4561e41f4b71Sopenharmony_ci}
4562e41f4b71Sopenharmony_ci```
4563e41f4b71Sopenharmony_ci
4564e41f4b71Sopenharmony_ci
4565e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup>
4566e41f4b71Sopenharmony_ci
4567e41f4b71Sopenharmony_cigetResultSet(deviceId: string, keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
4568e41f4b71Sopenharmony_ci
4569e41f4b71Sopenharmony_ciObtains a **KvStoreResultSet** object that matches the specified device ID and key prefix. This API uses a promise to return the result.
4570e41f4b71Sopenharmony_ci> **NOTE**
4571e41f4b71Sopenharmony_ci>
4572e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4573e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4574e41f4b71Sopenharmony_ci
4575e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4576e41f4b71Sopenharmony_ci
4577e41f4b71Sopenharmony_ci**Parameters**
4578e41f4b71Sopenharmony_ci
4579e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4580e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4581e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4582e41f4b71Sopenharmony_ci| keyPrefix |string  | Yes   |Key prefix to match.   |
4583e41f4b71Sopenharmony_ci
4584e41f4b71Sopenharmony_ci**Return value**
4585e41f4b71Sopenharmony_ci
4586e41f4b71Sopenharmony_ci| Type   | Description      |
4587e41f4b71Sopenharmony_ci| ------  | -------   |
4588e41f4b71Sopenharmony_ci|Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise used to return the **KvStoreResultSet** object that matches the specified device ID and key prefix.|
4589e41f4b71Sopenharmony_ci
4590e41f4b71Sopenharmony_ci**Example**
4591e41f4b71Sopenharmony_ci
4592e41f4b71Sopenharmony_ci```js
4593e41f4b71Sopenharmony_cilet kvStore;
4594e41f4b71Sopenharmony_citry {
4595e41f4b71Sopenharmony_ci    let resultSet;
4596e41f4b71Sopenharmony_ci    kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
4597e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
4598e41f4b71Sopenharmony_ci        resultSet = result;
4599e41f4b71Sopenharmony_ci    }).catch((err) => {
4600e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + JSON.stringify(err));
4601e41f4b71Sopenharmony_ci    });
4602e41f4b71Sopenharmony_ci    kvStore.closeResultSet(resultSet).then((err) => {
4603e41f4b71Sopenharmony_ci        console.log('closeResultSet success');
4604e41f4b71Sopenharmony_ci    }).catch((err) => {
4605e41f4b71Sopenharmony_ci        console.log('closeResultSet fail ' + JSON.stringify(err));
4606e41f4b71Sopenharmony_ci    });
4607e41f4b71Sopenharmony_ci}catch(e) {
4608e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
4609e41f4b71Sopenharmony_ci}
4610e41f4b71Sopenharmony_ci```
4611e41f4b71Sopenharmony_ci
4612e41f4b71Sopenharmony_ci
4613e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup>
4614e41f4b71Sopenharmony_ci
4615e41f4b71Sopenharmony_cigetResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
4616e41f4b71Sopenharmony_ci
4617e41f4b71Sopenharmony_ciObtains a **KvStoreResultSet** object that matches the specified **Query** object. This API uses an asynchronous callback to return the result.
4618e41f4b71Sopenharmony_ci
4619e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4620e41f4b71Sopenharmony_ci
4621e41f4b71Sopenharmony_ci**Parameters**
4622e41f4b71Sopenharmony_ci
4623e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4624e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4625e41f4b71Sopenharmony_ci| query  |[Query](#query8)  | Yes   |**Query** object to match.   |
4626e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt;  | Yes |Callback used to return the **KvStoreResultSet** object obtained.   |
4627e41f4b71Sopenharmony_ci
4628e41f4b71Sopenharmony_ci**Example**
4629e41f4b71Sopenharmony_ci
4630e41f4b71Sopenharmony_ci```js
4631e41f4b71Sopenharmony_cilet kvStore;
4632e41f4b71Sopenharmony_citry {
4633e41f4b71Sopenharmony_ci    let resultSet;
4634e41f4b71Sopenharmony_ci    let entries = [];
4635e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4636e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
4637e41f4b71Sopenharmony_ci        var entry = {
4638e41f4b71Sopenharmony_ci            key : key + i,
4639e41f4b71Sopenharmony_ci            value : {
4640e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
4641e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
4642e41f4b71Sopenharmony_ci            }
4643e41f4b71Sopenharmony_ci        }
4644e41f4b71Sopenharmony_ci        entries.push(entry);
4645e41f4b71Sopenharmony_ci    }
4646e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err, data) {
4647e41f4b71Sopenharmony_ci        console.log('putBatch success');
4648e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
4649e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
4650e41f4b71Sopenharmony_ci        query.deviceId('localDeviceId');
4651e41f4b71Sopenharmony_ci        kvStore.getResultSet(query, async function (err, result) {
4652e41f4b71Sopenharmony_ci            console.log('getResultSet succeed.');
4653e41f4b71Sopenharmony_ci            resultSet = result;
4654e41f4b71Sopenharmony_ci            kvStore.closeResultSet(resultSet, function (err, data) {
4655e41f4b71Sopenharmony_ci                console.log('closeResultSet success');
4656e41f4b71Sopenharmony_ci            })
4657e41f4b71Sopenharmony_ci        });
4658e41f4b71Sopenharmony_ci    });
4659e41f4b71Sopenharmony_ci} catch(e) {
4660e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
4661e41f4b71Sopenharmony_ci}
4662e41f4b71Sopenharmony_ci```
4663e41f4b71Sopenharmony_ci
4664e41f4b71Sopenharmony_ci
4665e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup>
4666e41f4b71Sopenharmony_ci
4667e41f4b71Sopenharmony_cigetResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
4668e41f4b71Sopenharmony_ci
4669e41f4b71Sopenharmony_ciObtains a **KvStoreResultSet** object that matches the specified **Query** object. This API uses a promise to return the result.
4670e41f4b71Sopenharmony_ci
4671e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4672e41f4b71Sopenharmony_ci
4673e41f4b71Sopenharmony_ci**Parameters**
4674e41f4b71Sopenharmony_ci
4675e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4676e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4677e41f4b71Sopenharmony_ci| query  |[Query](#query8)  | Yes   |**Query** object to match.   |
4678e41f4b71Sopenharmony_ci
4679e41f4b71Sopenharmony_ci**Return value**
4680e41f4b71Sopenharmony_ci
4681e41f4b71Sopenharmony_ci| Type   | Description      |
4682e41f4b71Sopenharmony_ci| ------  | -------   |
4683e41f4b71Sopenharmony_ci|Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise used to return the **KvStoreResultSet** object that matches the specified **Query** object.|
4684e41f4b71Sopenharmony_ci
4685e41f4b71Sopenharmony_ci**Example**
4686e41f4b71Sopenharmony_ci
4687e41f4b71Sopenharmony_ci```js
4688e41f4b71Sopenharmony_cilet kvStore;
4689e41f4b71Sopenharmony_citry {
4690e41f4b71Sopenharmony_ci    let resultSet;
4691e41f4b71Sopenharmony_ci    let entries = [];
4692e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4693e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
4694e41f4b71Sopenharmony_ci        var entry = {
4695e41f4b71Sopenharmony_ci            key : key + i,
4696e41f4b71Sopenharmony_ci            value : {
4697e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
4698e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
4699e41f4b71Sopenharmony_ci            }
4700e41f4b71Sopenharmony_ci        }
4701e41f4b71Sopenharmony_ci        entries.push(entry);
4702e41f4b71Sopenharmony_ci    }
4703e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
4704e41f4b71Sopenharmony_ci        console.log('putBatch success');
4705e41f4b71Sopenharmony_ci    }).catch((err) => {
4706e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + err);
4707e41f4b71Sopenharmony_ci    });
4708e41f4b71Sopenharmony_ci    const query = new distributedData.Query();
4709e41f4b71Sopenharmony_ci    query.deviceId('localDeviceId');
4710e41f4b71Sopenharmony_ci    query.prefixKey("batch_test");
4711e41f4b71Sopenharmony_ci    console.log("GetResultSet " + query.getSqlLike());
4712e41f4b71Sopenharmony_ci    kvStore.getResultSet(query).then((result) => {
4713e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
4714e41f4b71Sopenharmony_ci        resultSet = result;
4715e41f4b71Sopenharmony_ci    }).catch((err) => {
4716e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + JSON.stringify(err));
4717e41f4b71Sopenharmony_ci    });
4718e41f4b71Sopenharmony_ci    kvStore.closeResultSet(resultSet).then((err) => {
4719e41f4b71Sopenharmony_ci        console.log('closeResultSet success');
4720e41f4b71Sopenharmony_ci    }).catch((err) => {
4721e41f4b71Sopenharmony_ci        console.log('closeResultSet fail ' + JSON.stringify(err));
4722e41f4b71Sopenharmony_ci    });
4723e41f4b71Sopenharmony_ci}catch(e) {
4724e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
4725e41f4b71Sopenharmony_ci}
4726e41f4b71Sopenharmony_ci```
4727e41f4b71Sopenharmony_ci
4728e41f4b71Sopenharmony_ci
4729e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup>
4730e41f4b71Sopenharmony_ci
4731e41f4b71Sopenharmony_cigetResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
4732e41f4b71Sopenharmony_ci
4733e41f4b71Sopenharmony_ciObtains a **KvStoreResultSet** object that matches the specified device ID and **Query** object. This API uses an asynchronous callback to return the result.
4734e41f4b71Sopenharmony_ci> **NOTE**
4735e41f4b71Sopenharmony_ci>
4736e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4737e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4738e41f4b71Sopenharmony_ci
4739e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4740e41f4b71Sopenharmony_ci
4741e41f4b71Sopenharmony_ci**Parameters**
4742e41f4b71Sopenharmony_ci
4743e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4744e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4745e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4746e41f4b71Sopenharmony_ci| query  |[Query](#query8)  | Yes   |**Query** object to match.   |
4747e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;[KvStoreResultSet](#kvstoreresultset8)&gt;  | Yes |Callback used to return the **KvStoreResultSet** object that matches the specified device ID and **Query** object.   |
4748e41f4b71Sopenharmony_ci
4749e41f4b71Sopenharmony_ci**Example**
4750e41f4b71Sopenharmony_ci
4751e41f4b71Sopenharmony_ci```js
4752e41f4b71Sopenharmony_cilet kvStore;
4753e41f4b71Sopenharmony_citry {
4754e41f4b71Sopenharmony_ci    let resultSet;
4755e41f4b71Sopenharmony_ci    let entries = [];
4756e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4757e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
4758e41f4b71Sopenharmony_ci        var entry = {
4759e41f4b71Sopenharmony_ci            key : key + i,
4760e41f4b71Sopenharmony_ci            value : {
4761e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
4762e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
4763e41f4b71Sopenharmony_ci            }
4764e41f4b71Sopenharmony_ci        }
4765e41f4b71Sopenharmony_ci        entries.push(entry);
4766e41f4b71Sopenharmony_ci    }
4767e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err, data) {
4768e41f4b71Sopenharmony_ci        console.log('putBatch success');
4769e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
4770e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
4771e41f4b71Sopenharmony_ci        kvStore.getResultSet('localDeviceId', query, async function (err, result) {
4772e41f4b71Sopenharmony_ci            console.log('getResultSet succeed.');
4773e41f4b71Sopenharmony_ci            resultSet = result;
4774e41f4b71Sopenharmony_ci            kvStore.closeResultSet(resultSet, function (err, data) {
4775e41f4b71Sopenharmony_ci                console.log('closeResultSet success');
4776e41f4b71Sopenharmony_ci            })
4777e41f4b71Sopenharmony_ci        });
4778e41f4b71Sopenharmony_ci    });
4779e41f4b71Sopenharmony_ci} catch(e) {
4780e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
4781e41f4b71Sopenharmony_ci}
4782e41f4b71Sopenharmony_ci```
4783e41f4b71Sopenharmony_ci
4784e41f4b71Sopenharmony_ci
4785e41f4b71Sopenharmony_ci### getResultSet<sup>8+</sup>
4786e41f4b71Sopenharmony_ci
4787e41f4b71Sopenharmony_cigetResultSet(deviceId: string, query: Query): Promise&lt;KvStoreResultSet&gt;
4788e41f4b71Sopenharmony_ci
4789e41f4b71Sopenharmony_ciObtains a **KvStoreResultSet** object that matches the specified device ID and **Query** object. This API uses a promise to return the result.
4790e41f4b71Sopenharmony_ci> **NOTE**
4791e41f4b71Sopenharmony_ci>
4792e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
4793e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
4794e41f4b71Sopenharmony_ci
4795e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4796e41f4b71Sopenharmony_ci
4797e41f4b71Sopenharmony_ci**Parameters**
4798e41f4b71Sopenharmony_ci
4799e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4800e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4801e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device.   |
4802e41f4b71Sopenharmony_ci| query  |[Query](#query8)  | Yes   |**Query** object to match.   |
4803e41f4b71Sopenharmony_ci
4804e41f4b71Sopenharmony_ci**Return value**
4805e41f4b71Sopenharmony_ci
4806e41f4b71Sopenharmony_ci| Type   | Description      |
4807e41f4b71Sopenharmony_ci| ------  | -------   |
4808e41f4b71Sopenharmony_ci|Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise used to return the **KvStoreResultSet** object that matches the specified device ID and **Query** object.|
4809e41f4b71Sopenharmony_ci
4810e41f4b71Sopenharmony_ci**Example**
4811e41f4b71Sopenharmony_ci
4812e41f4b71Sopenharmony_ci```js
4813e41f4b71Sopenharmony_cilet kvStore;
4814e41f4b71Sopenharmony_citry {
4815e41f4b71Sopenharmony_ci    let resultSet;
4816e41f4b71Sopenharmony_ci    let entries = [];
4817e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4818e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
4819e41f4b71Sopenharmony_ci        var entry = {
4820e41f4b71Sopenharmony_ci            key : key + i,
4821e41f4b71Sopenharmony_ci            value : {
4822e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
4823e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
4824e41f4b71Sopenharmony_ci            }
4825e41f4b71Sopenharmony_ci        }
4826e41f4b71Sopenharmony_ci        entries.push(entry);
4827e41f4b71Sopenharmony_ci    }
4828e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
4829e41f4b71Sopenharmony_ci        console.log('GetResultSet putBatch success');
4830e41f4b71Sopenharmony_ci    }).catch((err) => {
4831e41f4b71Sopenharmony_ci        console.log('PutBatch putBatch fail ' + JSON.stringify(err));
4832e41f4b71Sopenharmony_ci    });
4833e41f4b71Sopenharmony_ci    const query = new distributedData.Query();
4834e41f4b71Sopenharmony_ci    query.prefixKey("batch_test");
4835e41f4b71Sopenharmony_ci    kvStore.getResultSet('localDeviceId', query).then((result) => {
4836e41f4b71Sopenharmony_ci        console.log('GetResultSet getResultSet succeed.');
4837e41f4b71Sopenharmony_ci        resultSet = result;
4838e41f4b71Sopenharmony_ci    }).catch((err) => {
4839e41f4b71Sopenharmony_ci        console.log('GetResultSet getResultSet failed: ' + JSON.stringify(err));
4840e41f4b71Sopenharmony_ci    });
4841e41f4b71Sopenharmony_ci    query.deviceId('localDeviceId');
4842e41f4b71Sopenharmony_ci    console.log("GetResultSet " + query.getSqlLike());
4843e41f4b71Sopenharmony_ci    kvStore.closeResultSet(resultSet).then((err) => {
4844e41f4b71Sopenharmony_ci        console.log('GetResultSet closeResultSet success');
4845e41f4b71Sopenharmony_ci    }).catch((err) => {
4846e41f4b71Sopenharmony_ci        console.log('GetResultSet closeResultSet fail ' + JSON.stringify(err));
4847e41f4b71Sopenharmony_ci    });
4848e41f4b71Sopenharmony_ci
4849e41f4b71Sopenharmony_ci}catch(e) {
4850e41f4b71Sopenharmony_ci    console.log('GetResultSet e ' + e);
4851e41f4b71Sopenharmony_ci}
4852e41f4b71Sopenharmony_ci```
4853e41f4b71Sopenharmony_ci
4854e41f4b71Sopenharmony_ci
4855e41f4b71Sopenharmony_ci### closeResultSet<sup>8+</sup>
4856e41f4b71Sopenharmony_ci
4857e41f4b71Sopenharmony_cicloseResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void
4858e41f4b71Sopenharmony_ci
4859e41f4b71Sopenharmony_ciCloses the **KvStoreResultSet** object obtained by [DeviceKVStore.getResultSet](#devicekvstore_getresultset). This API uses an asynchronous callback to return the result.
4860e41f4b71Sopenharmony_ci
4861e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4862e41f4b71Sopenharmony_ci
4863e41f4b71Sopenharmony_ci**Parameters**
4864e41f4b71Sopenharmony_ci
4865e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4866e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4867e41f4b71Sopenharmony_ci| resultSet  |[KvStoreResultSet](#getresultset8)  | Yes   |**KvStoreResultSet** object to close.  |
4868e41f4b71Sopenharmony_ci| callback   |AsyncCallback&lt;void&gt;                 | Yes   |Callback used to return the result.   |
4869e41f4b71Sopenharmony_ci
4870e41f4b71Sopenharmony_ci**Example**
4871e41f4b71Sopenharmony_ci
4872e41f4b71Sopenharmony_ci```js
4873e41f4b71Sopenharmony_cilet kvStore;
4874e41f4b71Sopenharmony_citry {
4875e41f4b71Sopenharmony_ci    console.log('CloseResultSet success');
4876e41f4b71Sopenharmony_ci    let resultSet = null;
4877e41f4b71Sopenharmony_ci    kvStore.closeResultSet(resultSet, function (err, data) {
4878e41f4b71Sopenharmony_ci        if (err == undefined) {
4879e41f4b71Sopenharmony_ci            console.log('closeResultSet success');
4880e41f4b71Sopenharmony_ci        } else {
4881e41f4b71Sopenharmony_ci            console.log('closeResultSet fail');
4882e41f4b71Sopenharmony_ci        }
4883e41f4b71Sopenharmony_ci    });
4884e41f4b71Sopenharmony_ci}catch(e) {
4885e41f4b71Sopenharmony_ci    console.log('CloseResultSet e ' + e);
4886e41f4b71Sopenharmony_ci}
4887e41f4b71Sopenharmony_ci```
4888e41f4b71Sopenharmony_ci
4889e41f4b71Sopenharmony_ci
4890e41f4b71Sopenharmony_ci### closeResultSet<sup>8+</sup>
4891e41f4b71Sopenharmony_ci
4892e41f4b71Sopenharmony_cicloseResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
4893e41f4b71Sopenharmony_ci
4894e41f4b71Sopenharmony_ciCloses the **KvStoreResultSet** object obtained by [DeviceKVStore.getResultSet](#devicekvstore_getresultset). This API uses a promise to return the result.
4895e41f4b71Sopenharmony_ci
4896e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4897e41f4b71Sopenharmony_ci
4898e41f4b71Sopenharmony_ci**Parameters**
4899e41f4b71Sopenharmony_ci
4900e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4901e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4902e41f4b71Sopenharmony_ci| resultSet  |[KvStoreResultSet](#getresultset8)  | Yes   |**KvStoreResultSet** object to close.  |
4903e41f4b71Sopenharmony_ci
4904e41f4b71Sopenharmony_ci**Return value**
4905e41f4b71Sopenharmony_ci
4906e41f4b71Sopenharmony_ci| Type   | Description      |
4907e41f4b71Sopenharmony_ci| ------  | -------   |
4908e41f4b71Sopenharmony_ci|Promise&lt;void&gt; |Promise that returns no value.|
4909e41f4b71Sopenharmony_ci
4910e41f4b71Sopenharmony_ci**Example**
4911e41f4b71Sopenharmony_ci
4912e41f4b71Sopenharmony_ci```js
4913e41f4b71Sopenharmony_cilet kvStore;
4914e41f4b71Sopenharmony_citry {
4915e41f4b71Sopenharmony_ci    console.log('CloseResultSet success');
4916e41f4b71Sopenharmony_ci    let resultSet = null;
4917e41f4b71Sopenharmony_ci    kvStore.closeResultSet(resultSet).then(() => {
4918e41f4b71Sopenharmony_ci        console.log('closeResultSet success');
4919e41f4b71Sopenharmony_ci    }).catch((err) => {
4920e41f4b71Sopenharmony_ci        console.log('closeResultSet fail ' + JSON.stringify(err));
4921e41f4b71Sopenharmony_ci    });
4922e41f4b71Sopenharmony_ci}catch(e) {
4923e41f4b71Sopenharmony_ci    console.log('CloseResultSet e ' + e);
4924e41f4b71Sopenharmony_ci}
4925e41f4b71Sopenharmony_ci```
4926e41f4b71Sopenharmony_ci
4927e41f4b71Sopenharmony_ci
4928e41f4b71Sopenharmony_ci### getResultSize<sup>8+</sup>
4929e41f4b71Sopenharmony_ci
4930e41f4b71Sopenharmony_cigetResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
4931e41f4b71Sopenharmony_ci
4932e41f4b71Sopenharmony_ciObtains the number of results that match the specified **Query** object. This API uses an asynchronous callback to return the result.
4933e41f4b71Sopenharmony_ci
4934e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4935e41f4b71Sopenharmony_ci
4936e41f4b71Sopenharmony_ci**Parameters**
4937e41f4b71Sopenharmony_ci
4938e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4939e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4940e41f4b71Sopenharmony_ci| query     |[Query](#query8)       | Yes   |**Query** object to match.   |
4941e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;number&gt;  | Yes   |Callback used to return the number of results obtained.   |
4942e41f4b71Sopenharmony_ci
4943e41f4b71Sopenharmony_ci**Example**
4944e41f4b71Sopenharmony_ci
4945e41f4b71Sopenharmony_ci```js
4946e41f4b71Sopenharmony_cilet kvStore;
4947e41f4b71Sopenharmony_citry {
4948e41f4b71Sopenharmony_ci    let entries = [];
4949e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
4950e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
4951e41f4b71Sopenharmony_ci        var entry = {
4952e41f4b71Sopenharmony_ci            key : key + i,
4953e41f4b71Sopenharmony_ci            value : {
4954e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
4955e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
4956e41f4b71Sopenharmony_ci            }
4957e41f4b71Sopenharmony_ci        }
4958e41f4b71Sopenharmony_ci        entries.push(entry);
4959e41f4b71Sopenharmony_ci    }
4960e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err, data) {
4961e41f4b71Sopenharmony_ci        console.log('putBatch success');
4962e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
4963e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
4964e41f4b71Sopenharmony_ci        query.deviceId('localDeviceId');
4965e41f4b71Sopenharmony_ci        kvStore.getResultSize(query, async function (err, resultSize) {
4966e41f4b71Sopenharmony_ci            console.log('getResultSet succeed.');
4967e41f4b71Sopenharmony_ci        });
4968e41f4b71Sopenharmony_ci    });
4969e41f4b71Sopenharmony_ci} catch(e) {
4970e41f4b71Sopenharmony_ci    console.log('GetResultSize e ' + e);
4971e41f4b71Sopenharmony_ci}
4972e41f4b71Sopenharmony_ci```
4973e41f4b71Sopenharmony_ci
4974e41f4b71Sopenharmony_ci
4975e41f4b71Sopenharmony_ci### getResultSize<sup>8+</sup>
4976e41f4b71Sopenharmony_ci
4977e41f4b71Sopenharmony_cigetResultSize(query: Query): Promise&lt;number&gt;
4978e41f4b71Sopenharmony_ci
4979e41f4b71Sopenharmony_ciObtains the number of results that match the specified **Query** object. This API uses a promise to return the result.
4980e41f4b71Sopenharmony_ci
4981e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
4982e41f4b71Sopenharmony_ci
4983e41f4b71Sopenharmony_ci**Parameters**
4984e41f4b71Sopenharmony_ci
4985e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
4986e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
4987e41f4b71Sopenharmony_ci| query     |[Query](#query8)       | Yes   |**Query** object to match.   |
4988e41f4b71Sopenharmony_ci
4989e41f4b71Sopenharmony_ci**Return value**
4990e41f4b71Sopenharmony_ci
4991e41f4b71Sopenharmony_ci| Type   | Description      |
4992e41f4b71Sopenharmony_ci| ------  | -------   |
4993e41f4b71Sopenharmony_ci|Promise&lt;number&gt; |Promise used to return the number of results obtained.|
4994e41f4b71Sopenharmony_ci
4995e41f4b71Sopenharmony_ci**Example**
4996e41f4b71Sopenharmony_ci
4997e41f4b71Sopenharmony_ci```js
4998e41f4b71Sopenharmony_cilet kvStore;
4999e41f4b71Sopenharmony_citry {
5000e41f4b71Sopenharmony_ci    let entries = [];
5001e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
5002e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
5003e41f4b71Sopenharmony_ci        var entry = {
5004e41f4b71Sopenharmony_ci            key : key + i,
5005e41f4b71Sopenharmony_ci            value : {
5006e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
5007e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
5008e41f4b71Sopenharmony_ci            }
5009e41f4b71Sopenharmony_ci        }
5010e41f4b71Sopenharmony_ci        entries.push(entry);
5011e41f4b71Sopenharmony_ci    }
5012e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
5013e41f4b71Sopenharmony_ci        console.log('putBatch success');
5014e41f4b71Sopenharmony_ci    }).catch((err) => {
5015e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
5016e41f4b71Sopenharmony_ci    });
5017e41f4b71Sopenharmony_ci    const query = new distributedData.Query();
5018e41f4b71Sopenharmony_ci    query.prefixKey("batch_test");
5019e41f4b71Sopenharmony_ci    query.deviceId('localDeviceId');
5020e41f4b71Sopenharmony_ci    kvStore.getResultSize(query).then((resultSize) => {
5021e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
5022e41f4b71Sopenharmony_ci    }).catch((err) => {
5023e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + JSON.stringify(err));
5024e41f4b71Sopenharmony_ci    });
5025e41f4b71Sopenharmony_ci}catch(e) {
5026e41f4b71Sopenharmony_ci    console.log('GetResultSize e ' + e);
5027e41f4b71Sopenharmony_ci}
5028e41f4b71Sopenharmony_ci```
5029e41f4b71Sopenharmony_ci
5030e41f4b71Sopenharmony_ci
5031e41f4b71Sopenharmony_ci### getResultSize<sup>8+</sup>
5032e41f4b71Sopenharmony_ci
5033e41f4b71Sopenharmony_cigetResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&gt;): void;
5034e41f4b71Sopenharmony_ci
5035e41f4b71Sopenharmony_ciObtains the number of results that match the specified device ID and **Query** object. This API uses an asynchronous callback to return the result.
5036e41f4b71Sopenharmony_ci> **NOTE**
5037e41f4b71Sopenharmony_ci>
5038e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
5039e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
5040e41f4b71Sopenharmony_ci
5041e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
5042e41f4b71Sopenharmony_ci
5043e41f4b71Sopenharmony_ci**Parameters**
5044e41f4b71Sopenharmony_ci
5045e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
5046e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
5047e41f4b71Sopenharmony_ci| deviceId  |string                       | Yes   |ID of the target device.   |
5048e41f4b71Sopenharmony_ci| query     |[Query](#query8)       | Yes   |**Query** object to match.   |
5049e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;number&gt;  | Yes   |Callback used to return the number of results obtained.   |
5050e41f4b71Sopenharmony_ci
5051e41f4b71Sopenharmony_ci**Example**
5052e41f4b71Sopenharmony_ci
5053e41f4b71Sopenharmony_ci```js
5054e41f4b71Sopenharmony_cilet kvStore;
5055e41f4b71Sopenharmony_citry {
5056e41f4b71Sopenharmony_ci    let entries = [];
5057e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
5058e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
5059e41f4b71Sopenharmony_ci        var entry = {
5060e41f4b71Sopenharmony_ci            key : key + i,
5061e41f4b71Sopenharmony_ci            value : {
5062e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
5063e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
5064e41f4b71Sopenharmony_ci            }
5065e41f4b71Sopenharmony_ci        }
5066e41f4b71Sopenharmony_ci        entries.push(entry);
5067e41f4b71Sopenharmony_ci    }
5068e41f4b71Sopenharmony_ci    kvStore.putBatch(entries, async function (err, data) {
5069e41f4b71Sopenharmony_ci        console.log('putBatch success');
5070e41f4b71Sopenharmony_ci        const query = new distributedData.Query();
5071e41f4b71Sopenharmony_ci        query.prefixKey("batch_test");
5072e41f4b71Sopenharmony_ci        kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
5073e41f4b71Sopenharmony_ci            console.log('getResultSet succeed.');
5074e41f4b71Sopenharmony_ci        });
5075e41f4b71Sopenharmony_ci    });
5076e41f4b71Sopenharmony_ci} catch(e) {
5077e41f4b71Sopenharmony_ci    console.log('GetResultSize e ' + e);
5078e41f4b71Sopenharmony_ci}
5079e41f4b71Sopenharmony_ci```
5080e41f4b71Sopenharmony_ci
5081e41f4b71Sopenharmony_ci
5082e41f4b71Sopenharmony_ci### getResultSize<sup>8+</sup>
5083e41f4b71Sopenharmony_ci
5084e41f4b71Sopenharmony_cigetResultSize(deviceId: string, query: Query): Promise&lt;number&gt;
5085e41f4b71Sopenharmony_ci
5086e41f4b71Sopenharmony_ciObtains the number of results that match the specified device ID and **Query** object. This API uses a promise to return the result.
5087e41f4b71Sopenharmony_ci> **NOTE**
5088e41f4b71Sopenharmony_ci>
5089e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
5090e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
5091e41f4b71Sopenharmony_ci
5092e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
5093e41f4b71Sopenharmony_ci
5094e41f4b71Sopenharmony_ci**Parameters**
5095e41f4b71Sopenharmony_ci
5096e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
5097e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
5098e41f4b71Sopenharmony_ci| deviceId  |string                       | Yes   |ID of the target device.   |
5099e41f4b71Sopenharmony_ci| query     |[Query](#query8)       | Yes   |**Query** object to match.   |
5100e41f4b71Sopenharmony_ci
5101e41f4b71Sopenharmony_ci**Return value**
5102e41f4b71Sopenharmony_ci
5103e41f4b71Sopenharmony_ci| Type   | Description      |
5104e41f4b71Sopenharmony_ci| ------  | -------   |
5105e41f4b71Sopenharmony_ci|Promise&lt;number&gt; |Promise used to return the number of results obtained.|
5106e41f4b71Sopenharmony_ci
5107e41f4b71Sopenharmony_ci**Example**
5108e41f4b71Sopenharmony_ci
5109e41f4b71Sopenharmony_ci```js
5110e41f4b71Sopenharmony_cilet kvStore;
5111e41f4b71Sopenharmony_citry {
5112e41f4b71Sopenharmony_ci    let entries = [];
5113e41f4b71Sopenharmony_ci    for (var i = 0; i < 10; i++) {
5114e41f4b71Sopenharmony_ci        var key = 'batch_test_string_key';
5115e41f4b71Sopenharmony_ci        var entry = {
5116e41f4b71Sopenharmony_ci            key : key + i,
5117e41f4b71Sopenharmony_ci            value : {
5118e41f4b71Sopenharmony_ci                type : distributedData.ValueType.STRING,
5119e41f4b71Sopenharmony_ci                value : 'batch_test_string_value'
5120e41f4b71Sopenharmony_ci            }
5121e41f4b71Sopenharmony_ci        }
5122e41f4b71Sopenharmony_ci        entries.push(entry);
5123e41f4b71Sopenharmony_ci    }
5124e41f4b71Sopenharmony_ci    kvStore.putBatch(entries).then(async (err) => {
5125e41f4b71Sopenharmony_ci        console.log('putBatch success');
5126e41f4b71Sopenharmony_ci    }).catch((err) => {
5127e41f4b71Sopenharmony_ci        console.log('putBatch fail ' + JSON.stringify(err));
5128e41f4b71Sopenharmony_ci    });
5129e41f4b71Sopenharmony_ci    var query = new distributedData.Query();
5130e41f4b71Sopenharmony_ci    query.prefixKey("batch_test");
5131e41f4b71Sopenharmony_ci    kvStore.getResultSize('localDeviceId', query).then((resultSize) => {
5132e41f4b71Sopenharmony_ci        console.log('getResultSet succeed.');
5133e41f4b71Sopenharmony_ci    }).catch((err) => {
5134e41f4b71Sopenharmony_ci        console.log('getResultSet failed: ' + JSON.stringify(err));
5135e41f4b71Sopenharmony_ci    });
5136e41f4b71Sopenharmony_ci}catch(e) {
5137e41f4b71Sopenharmony_ci    console.log('GetResultSize e ' + e);
5138e41f4b71Sopenharmony_ci}
5139e41f4b71Sopenharmony_ci```
5140e41f4b71Sopenharmony_ci
5141e41f4b71Sopenharmony_ci
5142e41f4b71Sopenharmony_ci### removeDeviceData<sup>8+</sup>
5143e41f4b71Sopenharmony_ci
5144e41f4b71Sopenharmony_ciremoveDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
5145e41f4b71Sopenharmony_ci
5146e41f4b71Sopenharmony_ciDeletes data of the specified device from this KV store. This API uses an asynchronous callback to return the result.
5147e41f4b71Sopenharmony_ci> **NOTE**
5148e41f4b71Sopenharmony_ci>
5149e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
5150e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
5151e41f4b71Sopenharmony_ci
5152e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
5153e41f4b71Sopenharmony_ci
5154e41f4b71Sopenharmony_ci**Parameters**
5155e41f4b71Sopenharmony_ci
5156e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
5157e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
5158e41f4b71Sopenharmony_ci| deviceId  |string                       | Yes   |ID of the target device. |
5159e41f4b71Sopenharmony_ci| callback  |AsyncCallback&lt;void&gt;    | Yes   |Callback used to return the result.   |
5160e41f4b71Sopenharmony_ci
5161e41f4b71Sopenharmony_ci**Example**
5162e41f4b71Sopenharmony_ci
5163e41f4b71Sopenharmony_ci```js
5164e41f4b71Sopenharmony_cilet kvStore;
5165e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string';
5166e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-string-001';
5167e41f4b71Sopenharmony_citry {
5168e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) {
5169e41f4b71Sopenharmony_ci        console.log('RemoveDeviceData  put success');
5170e41f4b71Sopenharmony_ci        const deviceid = 'no_exist_device_id';
5171e41f4b71Sopenharmony_ci        kvStore.removeDeviceData(deviceid, async function (err,data) {
5172e41f4b71Sopenharmony_ci            if (err == undefined) {
5173e41f4b71Sopenharmony_ci                console.log('removeDeviceData success');
5174e41f4b71Sopenharmony_ci            } else {
5175e41f4b71Sopenharmony_ci                console.log('removeDeviceData fail');
5176e41f4b71Sopenharmony_ci                kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, async function (err,data) {
5177e41f4b71Sopenharmony_ci                    console.log('RemoveDeviceData get success');
5178e41f4b71Sopenharmony_ci                });
5179e41f4b71Sopenharmony_ci            }
5180e41f4b71Sopenharmony_ci        });
5181e41f4b71Sopenharmony_ci    });
5182e41f4b71Sopenharmony_ci}catch(e) {
5183e41f4b71Sopenharmony_ci    console.log('RemoveDeviceData e ' + e);
5184e41f4b71Sopenharmony_ci}
5185e41f4b71Sopenharmony_ci```
5186e41f4b71Sopenharmony_ci
5187e41f4b71Sopenharmony_ci
5188e41f4b71Sopenharmony_ci### removeDeviceData<sup>8+</sup>
5189e41f4b71Sopenharmony_ci
5190e41f4b71Sopenharmony_ciremoveDeviceData(deviceId: string): Promise&lt;void&gt;
5191e41f4b71Sopenharmony_ci
5192e41f4b71Sopenharmony_ciDeletes data of the specified device from this KV store. This API uses a promise to return the result.
5193e41f4b71Sopenharmony_ci> **NOTE**
5194e41f4b71Sopenharmony_ci>
5195e41f4b71Sopenharmony_ci> The value of **deviceId** can be obtained by <!--RP1-->[deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP1End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
5196e41f4b71Sopenharmony_ci> For details about how to obtain **deviceId**, see [sync()](#sync).
5197e41f4b71Sopenharmony_ci
5198e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
5199e41f4b71Sopenharmony_ci
5200e41f4b71Sopenharmony_ci**Parameters**
5201e41f4b71Sopenharmony_ci
5202e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
5203e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
5204e41f4b71Sopenharmony_ci| deviceId  |string  | Yes   |ID of the target device. |
5205e41f4b71Sopenharmony_ci
5206e41f4b71Sopenharmony_ci**Return value**
5207e41f4b71Sopenharmony_ci
5208e41f4b71Sopenharmony_ci| Type   | Description      |
5209e41f4b71Sopenharmony_ci| ------  | -------   |
5210e41f4b71Sopenharmony_ci|Promise&lt;void&gt; |Promise that returns no value.|
5211e41f4b71Sopenharmony_ci
5212e41f4b71Sopenharmony_ci**Example**
5213e41f4b71Sopenharmony_ci
5214e41f4b71Sopenharmony_ci```js
5215e41f4b71Sopenharmony_cilet kvStore;
5216e41f4b71Sopenharmony_ciconst KEY_TEST_STRING_ELEMENT = 'key_test_string';
5217e41f4b71Sopenharmony_ciconst VALUE_TEST_STRING_ELEMENT = 'value-string-001';
5218e41f4b71Sopenharmony_citry {
5219e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => {
5220e41f4b71Sopenharmony_ci        console.log('RemoveDeviceData put success');
5221e41f4b71Sopenharmony_ci    }).catch((err) => {
5222e41f4b71Sopenharmony_ci        console.log('RemoveDeviceData put fail ' + JSON.stringify(err));
5223e41f4b71Sopenharmony_ci    });
5224e41f4b71Sopenharmony_ci    const deviceid = 'no_exist_device_id';
5225e41f4b71Sopenharmony_ci    kvStore.removeDeviceData(deviceid).then((err) => {
5226e41f4b71Sopenharmony_ci        console.log('removeDeviceData success');
5227e41f4b71Sopenharmony_ci    }).catch((err) => {
5228e41f4b71Sopenharmony_ci        console.log('removeDeviceData fail ' + JSON.stringify(err));
5229e41f4b71Sopenharmony_ci    });
5230e41f4b71Sopenharmony_ci    kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => {
5231e41f4b71Sopenharmony_ci        console.log('RemoveDeviceData get success data:' + data);
5232e41f4b71Sopenharmony_ci    }).catch((err) => {
5233e41f4b71Sopenharmony_ci        console.log('RemoveDeviceData get fail ' + JSON.stringify(err));
5234e41f4b71Sopenharmony_ci    });
5235e41f4b71Sopenharmony_ci}catch(e) {
5236e41f4b71Sopenharmony_ci    console.log('RemoveDeviceData e ' + e);
5237e41f4b71Sopenharmony_ci}
5238e41f4b71Sopenharmony_ci```
5239e41f4b71Sopenharmony_ci
5240e41f4b71Sopenharmony_ci
5241e41f4b71Sopenharmony_ci### sync<sup>8+</sup>
5242e41f4b71Sopenharmony_ci
5243e41f4b71Sopenharmony_cisync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
5244e41f4b71Sopenharmony_ci
5245e41f4b71Sopenharmony_ciSynchronizes the KV store manually.
5246e41f4b71Sopenharmony_ci
5247e41f4b71Sopenharmony_ci> **NOTE**
5248e41f4b71Sopenharmony_ci>
5249e41f4b71Sopenharmony_ci> **deviceIds** is **networkId** in <!--RP2-->[DeviceInfo](../apis-distributedservice-kit/js-apis-device-manager-sys.md#deviceinfo), which can be obtained by [deviceManager.getTrustedDeviceListSync](../apis-distributedservice-kit/js-apis-device-manager-sys.md#gettrusteddevicelistsync). <!--RP2End-->The APIs of the **deviceManager** module are system interfaces and available only to system applications.
5250e41f4b71Sopenharmony_ci
5251e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
5252e41f4b71Sopenharmony_ci
5253e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
5254e41f4b71Sopenharmony_ci
5255e41f4b71Sopenharmony_ci**Parameters**
5256e41f4b71Sopenharmony_ci
5257e41f4b71Sopenharmony_ci| Name | Type| Mandatory | Description                   |
5258e41f4b71Sopenharmony_ci| -----  | ------   | ----  | ----------------------- |
5259e41f4b71Sopenharmony_ci| deviceIds    |string[]               | Yes   |**networkId**s of the devices to be synchronized.|
5260e41f4b71Sopenharmony_ci| mode            |[SyncMode](#syncmode)  | Yes   |Sync mode. |
5261e41f4b71Sopenharmony_ci| delayMs  |number                 | No   |Delay time allowed, in ms. The default value is **0**. |
5262e41f4b71Sopenharmony_ci
5263e41f4b71Sopenharmony_ci**Example**
5264e41f4b71Sopenharmony_ci
5265e41f4b71Sopenharmony_ci```js
5266e41f4b71Sopenharmony_ciimport deviceManager from '@ohos.distributedHardware.deviceManager';
5267e41f4b71Sopenharmony_ci
5268e41f4b71Sopenharmony_cilet devManager;
5269e41f4b71Sopenharmony_cilet kvStore;
5270e41f4b71Sopenharmony_ciconst KEY_TEST_SYNC_ELEMENT = 'key_test_sync';
5271e41f4b71Sopenharmony_ciconst VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
5272e41f4b71Sopenharmony_ci// create deviceManager
5273e41f4b71Sopenharmony_cideviceManager.createDeviceManager('bundleName', (err, value) => {
5274e41f4b71Sopenharmony_ci  if (!err) {
5275e41f4b71Sopenharmony_ci    devManager = value;
5276e41f4b71Sopenharmony_ci    let deviceIds = [];
5277e41f4b71Sopenharmony_ci    if (devManager != null) {
5278e41f4b71Sopenharmony_ci      var devices = devManager.getTrustedDeviceListSync();
5279e41f4b71Sopenharmony_ci      for (var i = 0; i < devices.length; i++) {
5280e41f4b71Sopenharmony_ci        deviceIds[i] = devices[i].networkId;
5281e41f4b71Sopenharmony_ci      }
5282e41f4b71Sopenharmony_ci    }
5283e41f4b71Sopenharmony_ci    try {
5284e41f4b71Sopenharmony_ci      kvStore.on('syncComplete', function (data) {
5285e41f4b71Sopenharmony_ci        console.log('Sync dataChange');
5286e41f4b71Sopenharmony_ci      });
5287e41f4b71Sopenharmony_ci      kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) {
5288e41f4b71Sopenharmony_ci        if (err != undefined) {
5289e41f4b71Sopenharmony_ci          console.log("put err: " + JSON.stringify(err));
5290e41f4b71Sopenharmony_ci          return;
5291e41f4b71Sopenharmony_ci        }
5292e41f4b71Sopenharmony_ci        console.log('Succeeded in putting data');
5293e41f4b71Sopenharmony_ci        const mode = distributedData.SyncMode.PULL_ONLY;
5294e41f4b71Sopenharmony_ci        kvStore.sync(deviceIds, mode, 1000);
5295e41f4b71Sopenharmony_ci      });
5296e41f4b71Sopenharmony_ci    } catch (e) {
5297e41f4b71Sopenharmony_ci      console.log('Sync e' + e);
5298e41f4b71Sopenharmony_ci    }
5299e41f4b71Sopenharmony_ci  }
5300e41f4b71Sopenharmony_ci});
5301e41f4b71Sopenharmony_ci```
5302e41f4b71Sopenharmony_ci
5303e41f4b71Sopenharmony_ci### on('dataChange')<sup>8+</sup>
5304e41f4b71Sopenharmony_ci
5305e41f4b71Sopenharmony_cion(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
5306e41f4b71Sopenharmony_ci
5307e41f4b71Sopenharmony_ciSubscribes to data changes of the specified type.
5308e41f4b71Sopenharmony_ci
5309e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
5310e41f4b71Sopenharmony_ci
5311e41f4b71Sopenharmony_ci**Parameters**
5312e41f4b71Sopenharmony_ci
5313e41f4b71Sopenharmony_ci| Name  | Type                                                     | Mandatory| Description                                                |
5314e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- | ---- | ---------------------------------------------------- |
5315e41f4b71Sopenharmony_ci| event    | string                                                    | Yes  | Event type. The value is **dataChange**, which indicates data changes.|
5316e41f4b71Sopenharmony_ci| type     | [SubscribeType](#subscribetype)                           | Yes  | Type of data change.                                    |
5317e41f4b71Sopenharmony_ci| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes  | Callback used to return the data change.                   |
5318e41f4b71Sopenharmony_ci
5319e41f4b71Sopenharmony_ci**Example**
5320e41f4b71Sopenharmony_ci
5321e41f4b71Sopenharmony_ci```js
5322e41f4b71Sopenharmony_cilet kvStore;
5323e41f4b71Sopenharmony_cikvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) {
5324e41f4b71Sopenharmony_ci    console.log("dataChange callback call data: " + JSON.stringify(data));
5325e41f4b71Sopenharmony_ci});
5326e41f4b71Sopenharmony_ci```
5327e41f4b71Sopenharmony_ci
5328e41f4b71Sopenharmony_ci### on('syncComplete')<sup>8+</sup>
5329e41f4b71Sopenharmony_ci
5330e41f4b71Sopenharmony_cion(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
5331e41f4b71Sopenharmony_ci
5332e41f4b71Sopenharmony_ciSubscribes to sync complete events.
5333e41f4b71Sopenharmony_ci
5334e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
5335e41f4b71Sopenharmony_ci
5336e41f4b71Sopenharmony_ci**Parameters**
5337e41f4b71Sopenharmony_ci
5338e41f4b71Sopenharmony_ci| Name      | Type                                         | Mandatory| Description                                                  |
5339e41f4b71Sopenharmony_ci| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------ |
5340e41f4b71Sopenharmony_ci| event        | string                                        | Yes  | Event type. The value is **syncComplete**, which indicates a sync complete event.|
5341e41f4b71Sopenharmony_ci| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes  | Callback used to return a sync complete event.            |
5342e41f4b71Sopenharmony_ci
5343e41f4b71Sopenharmony_ci**Example**
5344e41f4b71Sopenharmony_ci
5345e41f4b71Sopenharmony_ci```js
5346e41f4b71Sopenharmony_cilet kvStore;
5347e41f4b71Sopenharmony_ciconst KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
5348e41f4b71Sopenharmony_ciconst VALUE_TEST_FLOAT_ELEMENT = 321.12;
5349e41f4b71Sopenharmony_citry {
5350e41f4b71Sopenharmony_ci    kvStore.on('syncComplete', function (data) {
5351e41f4b71Sopenharmony_ci        console.log('syncComplete ' + data)
5352e41f4b71Sopenharmony_ci    });
5353e41f4b71Sopenharmony_ci    kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
5354e41f4b71Sopenharmony_ci        console.log('syncComplete put success');
5355e41f4b71Sopenharmony_ci    }).catch((error) => {
5356e41f4b71Sopenharmony_ci        console.log('syncComplete put fail ' + error);
5357e41f4b71Sopenharmony_ci    });
5358e41f4b71Sopenharmony_ci}catch(e) {
5359e41f4b71Sopenharmony_ci    console.log('syncComplete put e ' + e);
5360e41f4b71Sopenharmony_ci}
5361e41f4b71Sopenharmony_ci```
5362e41f4b71Sopenharmony_ci
5363e41f4b71Sopenharmony_ci### off('dataChange')<sup>8+</sup>
5364e41f4b71Sopenharmony_ci
5365e41f4b71Sopenharmony_cioff(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
5366e41f4b71Sopenharmony_ci
5367e41f4b71Sopenharmony_ciUnsubscribes from data changes.
5368e41f4b71Sopenharmony_ci
5369e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
5370e41f4b71Sopenharmony_ci
5371e41f4b71Sopenharmony_ci**Parameters**
5372e41f4b71Sopenharmony_ci
5373e41f4b71Sopenharmony_ci| Name  | Type                                                     | Mandatory| Description                                                    |
5374e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- | ---- | -------------------------------------------------------- |
5375e41f4b71Sopenharmony_ci| event    | string                                                    | Yes  | Event type. The value is **dataChange**, which indicates data changes.|
5376e41f4b71Sopenharmony_ci| listener | Callback&lt;[ChangeNotification](#changenotification)&gt; | No  | Callback to unregister. If this parameter is not specified, all callbacks for data changes will be unregistered.|
5377e41f4b71Sopenharmony_ci
5378e41f4b71Sopenharmony_ci**Example**
5379e41f4b71Sopenharmony_ci
5380e41f4b71Sopenharmony_ci```js
5381e41f4b71Sopenharmony_cilet kvStore;
5382e41f4b71Sopenharmony_ciclass KvstoreModel {
5383e41f4b71Sopenharmony_ci    call(data) {
5384e41f4b71Sopenharmony_ci        console.log("dataChange: " + data);
5385e41f4b71Sopenharmony_ci    }
5386e41f4b71Sopenharmony_ci    subscribeDataChange() {
5387e41f4b71Sopenharmony_ci        if (kvStore != null) {
5388e41f4b71Sopenharmony_ci            kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
5389e41f4b71Sopenharmony_ci        }
5390e41f4b71Sopenharmony_ci    }
5391e41f4b71Sopenharmony_ci    unsubscribeDataChange() {
5392e41f4b71Sopenharmony_ci        if (kvStore != null) {
5393e41f4b71Sopenharmony_ci            kvStore.off('dataChange', this.call);
5394e41f4b71Sopenharmony_ci        }
5395e41f4b71Sopenharmony_ci    }
5396e41f4b71Sopenharmony_ci}
5397e41f4b71Sopenharmony_ci```
5398e41f4b71Sopenharmony_ci
5399e41f4b71Sopenharmony_ci### off('syncComplete')<sup>8+</sup>
5400e41f4b71Sopenharmony_ci
5401e41f4b71Sopenharmony_cioff(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
5402e41f4b71Sopenharmony_ci
5403e41f4b71Sopenharmony_ciUnsubscribes from sync complete events.
5404e41f4b71Sopenharmony_ci
5405e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
5406e41f4b71Sopenharmony_ci
5407e41f4b71Sopenharmony_ci**Parameters**
5408e41f4b71Sopenharmony_ci
5409e41f4b71Sopenharmony_ci| Name      | Type                                         | Mandatory| Description                                                      |
5410e41f4b71Sopenharmony_ci| ------------ | --------------------------------------------- | ---- | ---------------------------------------------------------- |
5411e41f4b71Sopenharmony_ci| event        | string                                        | Yes  | Event type. The value is **syncComplete**, which indicates a sync complete event.|
5412e41f4b71Sopenharmony_ci| syncCallback | Callback&lt;Array&lt;[string, number]&gt;&gt; | No  | Callback to unregister. If this parameter is not specified, all callbacks for the sync complete event will be unregistered. |
5413e41f4b71Sopenharmony_ci
5414e41f4b71Sopenharmony_ci**Example**
5415e41f4b71Sopenharmony_ci
5416e41f4b71Sopenharmony_ci```js
5417e41f4b71Sopenharmony_cilet kvStore;
5418e41f4b71Sopenharmony_ciclass KvstoreModel {
5419e41f4b71Sopenharmony_ci    call(data) {
5420e41f4b71Sopenharmony_ci        console.log("syncComplete: " + data);
5421e41f4b71Sopenharmony_ci    }
5422e41f4b71Sopenharmony_ci    subscribeSyncComplete() {
5423e41f4b71Sopenharmony_ci        if (kvStore != null) {
5424e41f4b71Sopenharmony_ci            kvStore.on('syncComplete', this.call);
5425e41f4b71Sopenharmony_ci        }
5426e41f4b71Sopenharmony_ci    }
5427e41f4b71Sopenharmony_ci    unsubscribeSyncComplete() {
5428e41f4b71Sopenharmony_ci        if (kvStore != null) {
5429e41f4b71Sopenharmony_ci            kvStore.off('syncComplete', this.call);
5430e41f4b71Sopenharmony_ci        }
5431e41f4b71Sopenharmony_ci    }
5432e41f4b71Sopenharmony_ci}
5433e41f4b71Sopenharmony_ci```
5434e41f4b71Sopenharmony_ci
5435e41f4b71Sopenharmony_ci## SyncMode
5436e41f4b71Sopenharmony_ci
5437e41f4b71Sopenharmony_ciEnumerates the sync modes.
5438e41f4b71Sopenharmony_ci
5439e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
5440e41f4b71Sopenharmony_ci
5441e41f4b71Sopenharmony_ci| Name      | Value    | Description                   |
5442e41f4b71Sopenharmony_ci| -----      | ------    | ----------------------- |
5443e41f4b71Sopenharmony_ci| PULL_ONLY  |0          |Pull data from the peer end to the local end only.|
5444e41f4b71Sopenharmony_ci| PUSH_ONLY  |1          |Push data from the local end to the peer end only.|
5445e41f4b71Sopenharmony_ci| PUSH_PULL  |2          |Push data from the local end to the peer end and then pull data from the peer end to the local end.|
5446