diff --git a/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md b/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md index d2a9c901ca3fe2b2471c0696f14bdf255d48d454..a7a8b4022dc7b7b3d0214dfa63eb56d07b8af958 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md +++ b/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md @@ -16,6 +16,8 @@ >- 从API Version 9开始,该接口不再维护,推荐使用新接口[`@ohos.data.distributedKVStore`](js-apis-distributedKVStore.md)。 > >- 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> +>- 本模块中所有需要获取deviceId的接口,都仅系统应用可用。 ## 导入模块 @@ -88,25 +90,22 @@ createKVManager(config: KVManagerConfig): Promise<KVManager> **示例:** ```js -let kvManager; try { - const kvManagerConfig = { - bundleName : 'com.example.datamanagertest', - userInfo : { - userId : '0', - userType : distributedData.UserType.SAME_USER_ID - } + const kvManagerConfig = { + bundleName: 'com.example.datamanagertest', + userInfo: { + userId: '0', + userType: distributedData.UserType.SAME_USER_ID } - distributedData.createKVManager(kvManagerConfig, function (err, manager) { - if (err) { - console.log("Failed to create KVManager: " + JSON.stringify(err)); - return; - } - console.log("Succeeded in creating KVManager"); - kvManager = manager; - }); + } + distributedData.createKVManager(kvManagerConfig).then((manager) => { + console.log("Succeeded in creating KVManager"); + kvManager = manager; + }).catch((err) => { + console.error("Failed to create KVManager: " + JSON.stringify(err)); + }); } catch (e) { - console.log("An unexpected error occurred. Error:" + e); + console.log("An unexpected error occurred. Error:" + e); } ``` @@ -2012,6 +2011,10 @@ try { deviceId(deviceId:string):Query 添加设备ID作为key的前缀。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -3664,6 +3667,10 @@ try { removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void 删除指定设备的数据,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -3706,6 +3713,10 @@ try { removeDeviceData(deviceId: string): Promise<void> 删除指定设备的数据,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -4084,6 +4095,10 @@ try { get(deviceId: string, key: string, callback: AsyncCallback<boolean|string|number|Uint8Array>): void 获取与指定设备ID和key匹配的string值,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4119,6 +4134,10 @@ try{ get(deviceId: string, key: string): Promise<boolean|string|number|Uint8Array> 获取与指定设备ID和key匹配的string值,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4163,6 +4182,10 @@ try { getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback<Entry[]>): void 获取与指定设备ID和key前缀匹配的所有键值对,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4211,6 +4234,10 @@ try { getEntries(deviceId: string, keyPrefix: string): Promise<Entry[]> 获取与指定设备ID和key前缀匹配的所有键值对,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4380,6 +4407,10 @@ try { getEntries(deviceId: string, query: Query, callback: AsyncCallback<Entry[]>): void 获取与指定设备ID和Query对象匹配的键值对列表,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4433,6 +4464,10 @@ try { getEntries(deviceId: string, query: Query): Promise<Entry[]> 获取与指定设备ID和Query对象匹配的键值对列表,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4493,6 +4528,10 @@ try { getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void 获取与指定设备ID和key前缀匹配的KvStoreResultSet对象,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4528,6 +4567,10 @@ try { getResultSet(deviceId: string, keyPrefix: string): Promise<KvStoreResultSet> 获取与指定设备ID和key前缀匹配的KvStoreResultSet对象,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4688,6 +4731,10 @@ try { getResultSet(deviceId: string, query: Query, callback: AsyncCallback<KvStoreResultSet>): void 获取与指定设备ID和Query对象匹配的KvStoreResultSet对象,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4740,6 +4787,10 @@ try { getResultSet(deviceId: string, query: Query): Promise<KvStoreResultSet> 获取与指定设备ID和Query对象匹配的KvStoreResultSet对象,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -4982,6 +5033,10 @@ try { getResultSize(deviceId: string, query: Query, callback: AsyncCallback<number>): void; 获取与指定设备ID和Query对象匹配的结果数,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5029,6 +5084,10 @@ try { getResultSize(deviceId: string, query: Query): Promise<number> 获取与指定设备ID和Query对象匹配的结果数,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5085,6 +5144,10 @@ try { removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void 从当前数据库中删除指定设备的数据,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5127,6 +5190,10 @@ try { removeDeviceData(deviceId: string): Promise<void> 从当前数据库中删除指定设备的数据,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore diff --git a/zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md b/zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md index ccf2915c953c2a8fca6f5978cd60d8b4235d332e..6f22a81e047fac925f76a4a07719950e07410d64 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md +++ b/zh-cn/application-dev/reference/apis/js-apis-distributedKVStore.md @@ -13,6 +13,7 @@ > **说明:** > > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +>
本模块中所有需要获取deviceId的接口,都仅系统应用可用。 ## 导入模块 @@ -28,7 +29,7 @@ import distributedKVStore from '@ohos.data.distributedKVStore'; | 名称 | 类型 | 必填 | 说明 | | ---------- | --------------------- | ---- | ------------------------------------------------------------ | -| context | Context | 是 |应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 | +| context | Context | 是 |应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。
从API version 10开始,context的参数类型为[BaseContext](js-apis-inner-application-baseContext.md)。 | | bundleName | string | 是 | 调用方的包名。 | ## Constants @@ -41,7 +42,7 @@ import distributedKVStore from '@ohos.data.distributedKVStore'; | --------------------- | ------- | --------------------------------------- | | MAX_KEY_LENGTH | 1024 | 数据库中Key允许的最大长度,单位字节。 | | MAX_VALUE_LENGTH | 4194303 | 数据库中Value允许的最大长度,单位字节。 | -| MAX_KEY_LENGTH_DEVICE | 896 | 最大设备密钥长度,单位字节。 | +| MAX_KEY_LENGTH_DEVICE | 896 | 设备协同数据库中key允许的最大长度,单位字节。 | | MAX_STORE_ID_LENGTH | 128 | 数据库标识符允许的最大长度,单位字节。 | | MAX_QUERY_LENGTH | 512000 | 最大查询长度,单位字节。 | | MAX_BATCH_SIZE | 128 | 最大批处理操作数量。 | @@ -137,10 +138,10 @@ import distributedKVStore from '@ohos.data.distributedKVStore'; | 名称 | 说明 | | -------: | ------------------------------------------------------------ | -| S1 | 表示数据库的安全级别为低级别,当数据泄露时会产生较低影响。例如,包含壁纸等系统数据的数据库。 | -| S2 | 表示数据库的安全级别为中级别,当数据泄露时会产生较大影响。例如,包含录音、视频等用户生成数据或通话记录等信息的数据库。 | -| S3 | 表示数据库的安全级别为高级别,当数据泄露时会产生重大影响。例如,包含用户运动、健康、位置等信息的数据库。 | -| S4 | 表示数据库的安全级别为关键级别,当数据泄露时会产生严重影响。例如,包含认证凭据、财务数据等信息的数据库。 | +| S1 | 表示数据库的安全级别为低级别,数据的泄露、篡改、破坏、销毁可能会给个人或组织导致有限的不利影响。
例如,性别、国籍,用户申请记录等。 | +| S2 | 表示数据库的安全级别为中级别,数据的泄露、篡改、破坏、销毁可能会给个人或组织导致严重的不利影响。
例如,个人详细通信地址,姓名昵称等。 | +| S3 | 表示数据库的安全级别为高级别,数据的泄露、篡改、破坏、销毁可能会给个人或组织导致严峻的不利影响。
例如,个人实时精确定位信息、运动轨迹等。 | +| S4 | 表示数据库的安全级别为关键级别,业界法律法规中定义的特殊数据类型,涉及个人的最私密领域的信息或者一旦泄露、篡改、破坏、销毁可能会给个人或组织造成重大的不利影响数据。
例如,政治观点、宗教、和哲学信仰、工会成员资格、基因数据、生物信息、健康和性生活状况、性取向等或设备认证鉴权、个人的信用卡等财务信息。 | ## Options @@ -226,23 +227,22 @@ appendChild(child: FieldNode): boolean **示例:** ```js -import ddm from '@ohos.data.distributedKVStore'; try { - let node = new ddm.FieldNode("root"); - let child1 = new ddm.FieldNode("child1"); - let child2 = new ddm.FieldNode("child2"); - let child3 = new ddm.FieldNode("child3"); + let node = new distributedKVStore.FieldNode("root"); + let child1 = new distributedKVStore.FieldNode("child1"); + let child2 = new distributedKVStore.FieldNode("child2"); + let child3 = new distributedKVStore.FieldNode("child3"); node.appendChild(child1); node.appendChild(child2); node.appendChild(child3); - console.log("appendNode " + JSON.stringify(node)); + console.info("appendNode " + JSON.stringify(node)); child1 = null; child2 = null; child3 = null; node = null; } catch (e) { - console.log("AppendChild " + e); + console.error("AppendChild " + e); } ``` @@ -276,7 +276,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; let kvManager; export default class EntryAbility extends UIAbility { onCreate() { - console.log("MyAbilityStage onCreate") + console.info("MyAbilityStage onCreate") let context = this.context const kvManagerConfig = { context: context, @@ -284,7 +284,7 @@ export default class EntryAbility extends UIAbility { } try { kvManager = distributedKVStore.createKVManager(kvManagerConfig); - console.log("Succeeded in creating KVManager"); + console.info("Succeeded in creating KVManager"); } catch (e) { console.error(`Failed to create KVManager.code is ${e.code},message is ${e.message}`); } @@ -304,7 +304,7 @@ const kvManagerConfig = { } try { kvManager = distributedKVStore.createKVManager(kvManagerConfig); - console.log("Succeeded in creating KVManager"); + console.info("Succeeded in creating KVManager"); } catch (e) { console.error(`Failed to create KVManager.code is ${e.code},message is ${e.message}`); } @@ -316,7 +316,7 @@ try { ### getKVStore -getKVStore<T >(storeId: string, options: Options, callback: AsyncCallback<T>): void +getKVStore<T>(storeId: string, options: Options, callback: AsyncCallback<T>): void 通过指定Options和storeId,创建并获取分布式键值数据库,使用callback异步回调。 @@ -343,7 +343,6 @@ getKVStore<T >(storeId: string, options: Options, callback: AsyncCallback& ```js let kvStore; -let kvManager; try { const options = { createIfMissing: true, @@ -355,20 +354,20 @@ try { }; kvManager.getKVStore('storeId', options, function (err, store) { if (err) { - console.error(`Fail to get KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); return; } - console.log("Succeeded in getting KVStore"); + console.info("Succeeded in getting KVStore"); kvStore = store; }); } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` ### getKVStore -getKVStore<T >(storeId: string, options: Options): Promise<T> +getKVStore<T>(storeId: string, options: Options): Promise<T> 通过指定Options和storeId,创建并获取分布式键值数据库,使用Promise异步回调。 @@ -400,7 +399,6 @@ getKVStore<T >(storeId: string, options: Options): Promise<T> ```js let kvStore; -let kvManager; try { const options = { createIfMissing: true, @@ -411,13 +409,13 @@ try { securityLevel: distributedKVStore.SecurityLevel.S2, }; kvManager.getKVStore('storeId', options).then((store) => { - console.log("Succeeded in getting KVStore"); + console.info("Succeeded in getting KVStore"); kvStore = store; }).catch((err) => { - console.error(`Fail to get KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` @@ -440,8 +438,6 @@ closeKVStore(appId: string, storeId: string, callback: AsyncCallback<void> **示例:** ```js -let kvStore; -let kvManager; const options = { createIfMissing: true, encrypt: false, @@ -453,14 +449,20 @@ const options = { } try { kvManager.getKVStore('storeId', options, async function (err, store) { - console.log('Succeeded in getting KVStore'); + if (err != undefined) { + console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); + return; + } + console.info('Succeeded in getting KVStore'); kvStore = store; + kvStore = null; + store = null; kvManager.closeKVStore('appId', 'storeId', function (err, data) { if (err != undefined) { - console.error(`Fail to close KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close KVStore.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing KVStore'); + console.info('Succeeded in closing KVStore'); }); }); } catch (e) { @@ -492,8 +494,6 @@ closeKVStore(appId: string, storeId: string): Promise<void> **示例:** ```js -let kvManager; -let kvStore; const options = { createIfMissing: true, encrypt: false, @@ -505,18 +505,20 @@ const options = { } try { kvManager.getKVStore('storeId', options).then(async (store) => { - console.log('Succeeded in getting KVStore'); + console.info('Succeeded in getting KVStore'); kvStore = store; + kvStore = null; + store = null; kvManager.closeKVStore('appId', 'storeId').then(() => { - console.log('Succeeded in closing KVStore'); + console.info('Succeeded in closing KVStore'); }).catch((err) => { - console.error(`Fail to close KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close KVStore.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to get KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to close KVStore.code is ${e.code},message is ${e.message}`); + console.error(`Failed to close KVStore.code is ${e.code},message is ${e.message}`); } ``` @@ -547,8 +549,6 @@ deleteKVStore(appId: string, storeId: string, callback: AsyncCallback<void> **示例:** ```js -let kvManager; -let kvStore; const options = { createIfMissing: true, encrypt: false, @@ -561,21 +561,23 @@ const options = { try { kvManager.getKVStore('store', options, async function (err, store) { if (err != undefined) { - console.error(`Fail to get KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting KVStore'); + console.info('Succeeded in getting KVStore'); kvStore = store; + kvStore = null; + store = null; kvManager.deleteKVStore('appId', 'storeId', function (err, data) { if (err != undefined) { - console.error(`Fail to delete KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete KVStore.code is ${err.code},message is ${err.message}`); return; } - console.log(`Succeeded in deleting KVStore`); + console.info(`Succeeded in deleting KVStore`); }); }); } catch (e) { - console.error(`Fail to delete KVStore.code is ${e.code},message is ${e.message}`); + console.error(`Failed to delete KVStore.code is ${e.code},message is ${e.message}`); } ``` @@ -611,8 +613,6 @@ deleteKVStore(appId: string, storeId: string): Promise<void> **示例:** ```js -let kvManager; -let kvStore; const options = { createIfMissing: true, encrypt: false, @@ -624,18 +624,20 @@ const options = { } try { kvManager.getKVStore('storeId', options).then(async (store) => { - console.log('Succeeded in getting KVStore'); + console.info('Succeeded in getting KVStore'); kvStore = store; + kvStore = null; + store = null; kvManager.deleteKVStore('appId', 'storeId').then(() => { - console.log('Succeeded in deleting KVStore'); + console.info('Succeeded in deleting KVStore'); }).catch((err) => { - console.error(`Fail to delete KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete KVStore.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to get KVStore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get KVStore.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to delete KVStore.code is ${e.code},message is ${e.message}`); + console.error(`Failed to delete KVStore.code is ${e.code},message is ${e.message}`); } ``` @@ -657,18 +659,17 @@ getAllKVStoreId(appId: string, callback: AsyncCallback<string[]>): void **示例:** ```js -let kvManager; try { kvManager.getAllKVStoreId('appId', function (err, data) { if (err != undefined) { - console.error(`Fail to get AllKVStoreId.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get AllKVStoreId.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting AllKVStoreId'); - console.log(`GetAllKVStoreId size = ${data.length}`); + console.info('Succeeded in getting AllKVStoreId'); + console.info(`GetAllKVStoreId size = ${data.length}`); }); } catch (e) { - console.error(`Fail to get AllKVStoreId.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get AllKVStoreId.code is ${e.code},message is ${e.message}`); } ``` @@ -695,17 +696,16 @@ getAllKVStoreId(appId: string): Promise<string[]> **示例:** ```js -let kvManager; try { - console.log('GetAllKVStoreId'); + console.info('GetAllKVStoreId'); kvManager.getAllKVStoreId('appId').then((data) => { - console.log('Succeeded in getting AllKVStoreId'); - console.log(`GetAllKVStoreId size = ${data.length}`); + console.info('Succeeded in getting AllKVStoreId'); + console.info(`GetAllKVStoreId size = ${data.length}`); }).catch((err) => { - console.error(`Fail to get AllKVStoreId.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get AllKVStoreId.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to get AllKVStoreId.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get AllKVStoreId.code is ${e.code},message is ${e.message}`); } ``` @@ -713,7 +713,7 @@ try { on(event: 'distributedDataServiceDie', deathCallback: Callback<void>): void -订阅服务状态变更通知。 +订阅服务状态变更通知。如果服务终止,需要重新注册数据变更通知和同步完成事件回调通知,并且同步操作会返回失败。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -727,15 +727,14 @@ on(event: 'distributedDataServiceDie', deathCallback: Callback<void>): voi **示例:** ```js -let kvManager; try { - console.log('KVManagerOn'); + console.info('KVManagerOn'); const deathCallback = function () { - console.log('death callback call'); + console.info('death callback call'); } kvManager.on('distributedDataServiceDie', deathCallback); } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` @@ -743,7 +742,7 @@ try { off(event: 'distributedDataServiceDie', deathCallback?: Callback<void>): void -取消订阅服务状态变更通知。 +取消订阅服务状态变更通知。参数中的deathCallback必须是已经订阅过的deathCallback,否则会取消订阅失败。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -752,26 +751,25 @@ off(event: 'distributedDataServiceDie', deathCallback?: Callback<void>): v | 参数名 | 类型 | 必填 | 说明 | | ------------- | -------------------- | ---- | ------------------------------------------------------------ | | event | string | 是 | 取消订阅的事件名,固定为'distributedDataServiceDie',即服务状态变更事件。 | -| deathCallback | Callback<void> | 否 | 回调函数。 | +| deathCallback | Callback<void> | 否 | 回调函数。如果该参数不填,那么会将之前订阅过的所有的deathCallback取消订阅。 | **示例:** ```js -let kvManager; try { - console.log('KVManagerOff'); + console.info('KVManagerOff'); const deathCallback = function () { - console.log('death callback call'); + console.info('death callback call'); } kvManager.off('distributedDataServiceDie', deathCallback); } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` ## KVStoreResultSet -提供获取数据库结果集的相关方法,包括查询和移动数据读取位置等。 +提供获取数据库结果集的相关方法,包括查询和移动数据读取位置等。同时允许打开的结果集的最大数量为8个。 在调用KVStoreResultSet的方法前,需要先通过[getKVStore](#getkvstore)构建一个SingleKVStore或者DeviceKVStore实例。 @@ -792,19 +790,19 @@ getCount(): number **示例:** ```js -let kvStore; try { let resultSet; + let count; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + count = resultSet.getCount(); + console.info("getCount succeed:" + count); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const count = resultSet.getCount(); - console.log("getCount succeed:" + count); } catch (e) { - console.log("getCount failed: " + e); + console.error("getCount failed: " + e); } ``` @@ -812,7 +810,7 @@ try { getPosition(): number -获取结果集中当前的读取位置。 +获取结果集中当前的读取位置。读取位置会因[moveToFirst](#movetofirst)、[moveToLast](#movetolast)等操作而发生变化。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -820,24 +818,24 @@ getPosition(): number | 类型 | 说明 | | ------ | ------------------ | -| number | 返回当前读取位置。 | +| number | 返回当前读取位置。取值范围>= -1,值为 -1 时表示还未开始读取,值为 0 时表示第一行。 | **示例:** ```js -let kvStore; try { let resultSet; + let position; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeeded.'); + console.info('getResultSet succeeded.'); resultSet = result; + position = resultSet.getPosition(); + console.info("getPosition succeed:" + position); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const position = resultSet.getPosition(); - console.log("getPosition succeed:" + position); } catch (e) { - console.log("getPosition failed: " + e); + console.error("getPosition failed: " + e); } ``` @@ -858,19 +856,19 @@ moveToFirst(): boolean **示例:** ```js -let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + moved = resultSet.moveToFirst(); + console.info("moveToFirst succeed: " + moved); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const moved1 = resultSet.moveToFirst(); - console.log("moveToFirst succeed: " + moved1); } catch (e) { - console.log("moveToFirst failed " + e); + console.error("moveToFirst failed " + e); } ``` @@ -891,19 +889,19 @@ moveToLast(): boolean **示例:** ```js -let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + moved = resultSet.moveToLast(); + console.info("moveToLast succeed:" + moved); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const moved2 = resultSet.moveToLast(); - console.log("moveToLast succeed:" + moved2); } catch (e) { - console.log("moveToLast failed: " + e); + console.error("moveToLast failed: " + e); } ``` @@ -911,7 +909,7 @@ try { moveToNext(): boolean -将读取位置移动到下一行。如果结果集为空,则返回false。 +将读取位置移动到下一行。如果结果集为空,则返回false。适用于全量获取数据库结果集的场景。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -924,19 +922,22 @@ moveToNext(): boolean **示例:** ```js -let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + do { + moved = resultSet.moveToNext(); + const entry = resultSet.getEntry(); + console.info("moveToNext succeed: " + moved); + } while (moved) }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const moved3 = resultSet.moveToNext(); - console.log("moveToNext succeed: " + moved3); } catch (e) { - console.log("moveToNext failed: " + e); + console.error("moveToNext failed: " + e); } ``` @@ -944,7 +945,7 @@ try { moveToPrevious(): boolean -将读取位置移动到上一行。如果结果集为空,则返回false。 +将读取位置移动到上一行。如果结果集为空,则返回false。适用于全量获取数据库结果集的场景。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -957,19 +958,20 @@ moveToPrevious(): boolean **示例:** ```js -let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + moved = resultSet.moveToLast(); + moved = resultSet.moveToPrevious(); + console.info("moveToPrevious succeed:" + moved); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const moved4 = resultSet.moveToPrevious(); - console.log("moveToPrevious succeed:" + moved4); } catch (e) { - console.log("moveToPrevious failed: " + e); + console.error("moveToPrevious failed: " + e); } ``` @@ -977,7 +979,7 @@ try { move(offset: number): boolean -将读取位置移动到当前位置的相对偏移量。 +将读取位置移动到当前位置的相对偏移量。即当前游标位置向下偏移 offset 行。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -996,19 +998,19 @@ move(offset: number): boolean **示例:** ```js -let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; + moved = resultSet.move(2); //若当前位置为0,将读取位置从绝对位置为0的位置移动2行,即移动到绝对位置为2,行数为3的位置 + console.info(`Succeeded in moving.moved = ${moved}`); }).catch((err) => { - console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); }); - const moved5 = resultSet.move(1); - console.log(`Succeeded in moving.moved5 = ${moved5}`); } catch (e) { - console.log(`Fail to move.code is ${e.code},message is ${e.message}`); + console.error(`Failed to move.code is ${e.code},message is ${e.message}`); } ``` @@ -1035,19 +1037,19 @@ moveToPosition(position: number): boolean **示例** ```js -let kvStore; try { let resultSet; + let moved; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; + moved = resultSet.moveToPosition(1); + console.info(`Succeeded in moving to position.moved=${moved}`); }).catch((err) => { - console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); }); - const moved6 = resultSet.moveToPosition(1); - console.log(`Succeeded in moving to position.moved6=${moved6}`); } catch (e) { - console.error(`Fail to move to position.code is ${e.code},message is ${e.message}`); + console.error(`Failed to move to position.code is ${e.code},message is ${e.message}`); } ``` @@ -1068,19 +1070,19 @@ isFirst(): boolean **示例:** ```js -let kvStore; try { let resultSet; + let isfirst; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + isfirst = resultSet.isFirst(); + console.info("Check isFirst succeed:" + isfirst); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const isfirst = resultSet.isFirst(); - console.log("Check isFirst succeed:" + isfirst); } catch (e) { - console.log("Check isFirst failed: " + e); + console.error("Check isFirst failed: " + e); } ``` @@ -1101,19 +1103,19 @@ isLast(): boolean **示例:** ```js -let kvStore; try { let resultSet; + let islast; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + islast = resultSet.isLast(); + console.info("Check isLast succeed: " + islast); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const islast = resultSet.isLast(); - console.log("Check isLast succeed: " + islast); } catch (e) { - console.log("Check isLast failed: " + e); + console.error("Check isLast failed: " + e); } ``` @@ -1134,19 +1136,18 @@ isBeforeFirst(): boolean **示例:** ```js -let kvStore; try { let resultSet; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + const isbeforefirst = resultSet.isBeforeFirst(); + console.info("Check isBeforeFirst succeed: " + isbeforefirst); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const isbeforefirst = resultSet.isBeforeFirst(); - console.log("Check isBeforeFirst succeed: " + isbeforefirst); } catch (e) { - console.log("Check isBeforeFirst failed: " + e); + console.error("Check isBeforeFirst failed: " + e); } ``` @@ -1167,19 +1168,18 @@ isAfterLast(): boolean **示例:** ```js -let kvStore; try { let resultSet; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + const isafterlast = resultSet.isAfterLast(); + console.info("Check isAfterLast succeed:" + isafterlast); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const isafterlast = resultSet.isAfterLast(); - console.log("Check isAfterLast succeed:" + isafterlast); } catch (e) { - console.log("Check isAfterLast failed: " + e); + console.error("Check isAfterLast failed: " + e); } ``` @@ -1200,25 +1200,24 @@ getEntry(): Entry **示例:** ```js -let kvStore; try { let resultSet; kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet succeed.'); + console.info('getResultSet succeed.'); resultSet = result; + const entry = resultSet.getEntry(); + console.info("getEntry succeed:" + JSON.stringify(entry)); }).catch((err) => { - console.log('getResultSet failed: ' + err); + console.error('getResultSet failed: ' + err); }); - const entry = resultSet.getEntry(); - console.log("getEntry succeed:" + JSON.stringify(entry)); } catch (e) { - console.log("getEntry failed: " + e); + console.error("getEntry failed: " + e); } ``` ## Query -使用谓词表示数据库查询,提供创建Query实例、查询数据库中的数据和添加谓词的方法。 +使用谓词表示数据库查询,提供创建Query实例、查询数据库中的数据和添加谓词的方法。一个Query对象中谓词数量上限为256个。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -1250,12 +1249,12 @@ reset(): Query try { let query = new distributedKVStore.Query(); query.equalTo("key", "value"); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query.reset(); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("simply calls should be ok :" + e); + console.error("simply calls should be ok :" + e); } ``` @@ -1286,7 +1285,7 @@ equalTo(field: string, value: number|string|boolean): Query try { let query = new distributedKVStore.Query(); query.equalTo("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.ode is ${e.code},message is ${e.message}`); @@ -1320,7 +1319,7 @@ notEqualTo(field: string, value: number|string|boolean): Query try { let query = new distributedKVStore.Query(); query.notEqualTo("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1353,7 +1352,7 @@ greaterThan(field: string, value: number|string|boolean): Query try { let query = new distributedKVStore.Query(); query.greaterThan("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1388,7 +1387,7 @@ lessThan(field: string, value: number|string): Query try { let query = new distributedKVStore.Query(); query.lessThan("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1423,7 +1422,7 @@ greaterThanOrEqualTo(field: string, value: number|string): Query try { let query = new distributedKVStore.Query(); query.greaterThanOrEqualTo("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1458,7 +1457,7 @@ lessThanOrEqualTo(field: string, value: number|string): Query try { let query = new distributedKVStore.Query(); query.lessThanOrEqualTo("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1491,7 +1490,7 @@ isNull(field: string): Query try { let query = new distributedKVStore.Query(); query.isNull("field"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1525,7 +1524,7 @@ inNumber(field: string, valueList: number[]): Query try { let query = new distributedKVStore.Query(); query.inNumber("field", [0, 1]); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1559,7 +1558,7 @@ inString(field: string, valueList: string[]): Query try { let query = new distributedKVStore.Query(); query.inString("field", ['test1', 'test2']); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1593,7 +1592,7 @@ notInNumber(field: string, valueList: number[]): Query try { let query = new distributedKVStore.Query(); query.notInNumber("field", [0, 1]); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1627,7 +1626,7 @@ notInString(field: string, valueList: string[]): Query try { let query = new distributedKVStore.Query(); query.notInString("field", ['test1', 'test2']); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1661,7 +1660,7 @@ like(field: string, value: string): Query try { let query = new distributedKVStore.Query(); query.like("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1695,7 +1694,7 @@ unlike(field: string, value: string): Query try { let query = new distributedKVStore.Query(); query.unlike("field", "value"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1724,10 +1723,10 @@ try { query.notEqualTo("field", "value1"); query.and(); query.notEqualTo("field", "value2"); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("duplicated calls should be ok :" + e); + console.error("duplicated calls should be ok :" + e); } ``` @@ -1753,10 +1752,10 @@ try { query.notEqualTo("field", "value1"); query.or(); query.notEqualTo("field", "value2"); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("duplicated calls should be ok :" + e); + console.error("duplicated calls should be ok :" + e); } ``` @@ -1787,7 +1786,7 @@ try { let query = new distributedKVStore.Query(); query.notEqualTo("field", "value"); query.orderByAsc("field"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1821,7 +1820,7 @@ try { let query = new distributedKVStore.Query(); query.notEqualTo("field", "value"); query.orderByDesc("field"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1832,7 +1831,7 @@ try { limit(total: number, offset: number): Query -构造一个Query对象来指定结果的数量和开始位置。 +构造一个Query对象来指定结果的数量和开始位置。该接口必须要在Query对象查询和升降序等操作之后调用,调用limit接口后,不可再对Query对象进行查询和升降序等操作。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -1858,7 +1857,7 @@ try { let query = new distributedKVStore.Query(); query.notEqualTo("field", "value"); query.limit(total, offset); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1891,7 +1890,7 @@ isNotNull(field: string): Query try { let query = new distributedKVStore.Query(); query.isNotNull("field"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -1920,10 +1919,10 @@ try { query.beginGroup(); query.isNotNull("field"); query.endGroup(); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("duplicated calls should be ok :" + e); + console.error("duplicated calls should be ok :" + e); } ``` @@ -1949,10 +1948,10 @@ try { query.beginGroup(); query.isNotNull("field"); query.endGroup(); - console.log("query is " + query.getSqlLike()); + console.info("query is " + query.getSqlLike()); query = null; } catch (e) { - console.log("duplicated calls should be ok :" + e); + console.error("duplicated calls should be ok :" + e); } ``` @@ -1983,7 +1982,7 @@ try { let query = new distributedKVStore.Query(); query.prefixKey("$.name"); query.prefixKey("0"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -2017,7 +2016,7 @@ try { let query = new distributedKVStore.Query(); query.setSuggestIndex("$.name"); query.setSuggestIndex("0"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); query = null; } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); @@ -2029,6 +2028,10 @@ try { deviceId(deviceId:string):Query 添加设备ID作为key的前缀。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync) **系统能力:** SystemCapability.DistributedDataManager.KVStore.Core @@ -2050,7 +2053,7 @@ deviceId(deviceId:string):Query try { let query = new distributedKVStore.Query(); query.deviceId("deviceId"); - console.log(`query is ${query.getSqlLike()}`); + console.info(`query is ${query.getSqlLike()}`); } catch (e) { console.error(`duplicated calls should be ok.code is ${e.code},message is ${e.message}`); } @@ -2076,9 +2079,9 @@ getSqlLike():string try { let query = new distributedKVStore.Query(); let sql1 = query.getSqlLike(); - console.log(`GetSqlLike sql= ${sql1}`); + console.info(`GetSqlLike sql= ${sql1}`); } catch (e) { - console.log("duplicated calls should be ok : " + e); + console.error("duplicated calls should be ok : " + e); } ``` @@ -2122,16 +2125,15 @@ put(key: string, value: Uint8Array | string | number | boolean, callback: AsyncC **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log("Succeeded in putting"); + console.info("Succeeded in putting"); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -2177,14 +2179,13 @@ put(key: string, value: Uint8Array | string | number | boolean): Promise<void **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in putting.data=${data}`); + console.info(`Succeeded in putting.data=${data}`); }).catch((err) => { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -2203,7 +2204,7 @@ putBatch(entries: Entry[], callback: AsyncCallback<void>): void | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------ | -| entries | [Entry](#entry)[] | 是 | 表示要批量插入的键值对。 | +| entries | [Entry](#entry)[] | 是 | 表示要批量插入的键值对。一个entries对象中允许的最大条目个数为128个。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** @@ -2224,7 +2225,6 @@ putBatch(entries: Entry[], callback: AsyncCallback<void>): void **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -2238,20 +2238,20 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key', function (err, entries) { if (err != undefined) { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -2271,7 +2271,7 @@ putBatch(entries: Entry[]): Promise<void> | 参数名 | 类型 | 必填 | 说明 | | ------- | ----------------- | ---- | ------------------------ | -| entries | [Entry](#entry)[] | 是 | 表示要批量插入的键值对。 | +| entries | [Entry](#entry)[] | 是 | 表示要批量插入的键值对。一个entries对象中允许的最大条目个数为128个。 | **返回值:** @@ -2297,7 +2297,6 @@ putBatch(entries: Entry[]): Promise<void> **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -2311,17 +2310,17 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries).then(async (entries) => { - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key').then((entries) => { - console.log('Succeeded in getting Entries'); - console.log(`PutBatch ${entries}`); + console.info('Succeeded in getting Entries'); + console.info(`PutBatch ${entries}`); }).catch((err) => { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message} `); @@ -2363,7 +2362,6 @@ putBatch(value: Array<ValuesBucket>, callback: AsyncCallback<void>): **示例:** ```js -let kvStore; try { let v8Arr = []; let arr = new Uint8Array([4, 5, 6, 7]); @@ -2376,13 +2374,13 @@ try { v8Arr.push(vb3); kvStore.putBatch(v8Arr, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }) } catch (e) { - console.error(`Fail to put batch.code is ${e.code},message is ${e.message}`); + console.error(`Failed to put batch.code is ${e.code},message is ${e.message}`); } ``` @@ -2426,7 +2424,6 @@ putBatch(value: Array<ValuesBucket>): Promise<void> **示例:** ```js -let kvStore; try { let v8Arr = []; let arr = new Uint8Array([4, 5, 6, 7]); @@ -2438,7 +2435,7 @@ try { v8Arr.push(vb2); v8Arr.push(vb3); kvStore.putBatch(v8Arr).then(async (data) => { - console.log(`Succeeded in putting patch`); + console.info(`Succeeded in putting patch`); }).catch((err) => { console.error(`putBatch fail.code is ${err.code},message is ${err.message}`); }); @@ -2480,22 +2477,21 @@ delete(key: string, callback: AsyncCallback<void>): void **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting'); + console.info('Succeeded in putting'); kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to delete.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in deleting'); + console.info('Succeeded in deleting'); }); }); } catch (e) { @@ -2541,19 +2537,18 @@ delete(key: string): Promise<void> **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in putting: ${data}`); + console.info(`Succeeded in putting: ${data}`); kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('Succeeded in deleting'); + console.info('Succeeded in deleting'); }).catch((err) => { - console.error(`Fail to delete.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -2574,7 +2569,7 @@ delete(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallb | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- | -| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | 指示筛选条件,当此参数为null时,应定义处理逻辑。 | +| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | 指示筛选条件,当此参数为null时,应定义处理逻辑。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** @@ -2596,15 +2591,23 @@ delete(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallb ```js import dataSharePredicates from '@ohos.data.dataSharePredicates'; -let kvStore; try { let predicates = new dataSharePredicates.DataSharePredicates(); - kvStore.delete(predicates, function (err, data) { - if (err == undefined) { - console.log('Succeeded in deleting'); - } else { - console.error(`Fail to delete.code is ${err.code},message is ${err.message}`); + let arr = ["name"]; + predicates.inKeys(arr); + kvStore.put("name", "bob", function (err, data) { + if (err != undefined) { + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); + return; } + console.info("Succeeded in putting"); + kvStore.delete(predicates, function (err, data) { + if (err == undefined) { + console.info('Succeeded in deleting'); + } else { + console.error(`Failed to delete.code is ${err.code},message is ${err.message}`); + } + }); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -2653,20 +2656,19 @@ delete(predicates: dataSharePredicates.DataSharePredicates): Promise<void> ```js import dataSharePredicates from '@ohos.data.dataSharePredicates'; -let kvStore; try { let predicates = new dataSharePredicates.DataSharePredicates(); let arr = ["name"]; predicates.inKeys(arr); kvStore.put("name", "bob").then((data) => { - console.log(`Succeeded in putting: ${data}`); + console.info(`Succeeded in putting: ${data}`); kvStore.delete(predicates).then((data) => { - console.log('Succeeded in deleting'); + console.info('Succeeded in deleting'); }).catch((err) => { - console.error(`Fail to delete.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -2706,7 +2708,6 @@ deleteBatch(keys: string[], callback: AsyncCallback<void>): void **示例:** ```js -let kvStore; try { let entries = []; let keys = []; @@ -2722,19 +2723,19 @@ try { entries.push(entry); keys.push(key + i); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.deleteBatch(keys, async function (err, data) { if (err != undefined) { - console.error(`Fail to delete Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in deleting Batch'); + console.info('Succeeded in deleting Batch'); }); }); } catch (e) { @@ -2780,7 +2781,6 @@ deleteBatch(keys: string[]): Promise<void> **示例:** ```js -let kvStore; try { let entries = []; let keys = []; @@ -2796,16 +2796,16 @@ try { entries.push(entry); keys.push(key + i); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries).then(async (data) => { - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.deleteBatch(keys).then((err) => { - console.log('Succeeded in deleting Batch'); + console.info('Succeeded in deleting Batch'); }).catch((err) => { - console.error(`Fail to delete Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete Batch.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -2817,6 +2817,10 @@ try { removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void 删除指定设备的数据,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync) **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -2838,20 +2842,19 @@ removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err, data) { - console.log('Succeeded in putting data'); + console.info('Succeeded in putting data'); const deviceid = 'no_exist_device_id'; kvStore.removeDeviceData(deviceid, async function (err, data) { if (err == undefined) { - console.log('succeeded in removing device data'); + console.info('succeeded in removing device data'); } else { - console.error(`Fail to remove device data.code is ${err.code},message is ${err.message} `); + console.error(`Failed to remove device data.code is ${err.code},message is ${err.message} `); kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err, data) { - console.log('Succeeded in getting data'); + console.info('Succeeded in getting data'); }); } }); @@ -2866,6 +2869,10 @@ try { removeDeviceData(deviceId: string): Promise<void> 删除指定设备的数据,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync) **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -2892,25 +2899,24 @@ removeDeviceData(deviceId: string): Promise<void> **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => { - console.log('Succeeded in putting data'); + console.info('Succeeded in putting data'); }).catch((err) => { - console.error(`Fail to put data.code is ${err.code},message is ${err.message} `); + console.error(`Failed to put data.code is ${err.code},message is ${err.message} `); }); const deviceid = 'no_exist_device_id'; kvStore.removeDeviceData(deviceid).then((err) => { - console.log('succeeded in removing device data'); + console.info('succeeded in removing device data'); }).catch((err) => { - console.error(`Fail to remove device data.code is ${err.code},message is ${err.message} `); + console.error(`Failed to remove device data.code is ${err.code},message is ${err.message} `); }); kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('Succeeded in getting data'); + console.info('Succeeded in getting data'); }).catch((err) => { - console.error(`Fail to get data.code is ${err.code},message is ${err.message} `); + console.error(`Failed to get data.code is ${err.code},message is ${err.message} `); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`) @@ -2945,26 +2951,25 @@ get(key: string, callback: AsyncCallback<boolean | string | number | Uint8Arr **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log("Succeeded in putting"); + console.info("Succeeded in putting"); kvStore.get(KEY_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to get.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get.code is ${err.code},message is ${err.message}`); return; } - console.log(`Succeeded in getting data.data=${data}`); + console.info(`Succeeded in getting data.data=${data}`); }); }); } catch (e) { - console.error(`Fail to get.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get.code is ${e.code},message is ${e.message}`); } ``` @@ -3001,22 +3006,21 @@ get(key: string): Promise<boolean | string | number | Uint8Array> **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in putting data.data=${data}`); + console.info(`Succeeded in putting data.data=${data}`); kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in getting data.data=${data}`); + console.info(`Succeeded in getting data.data=${data}`); }).catch((err) => { - console.error(`Fail to get.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to get.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get.code is ${e.code},message is ${e.message}`); } ``` @@ -3047,7 +3051,6 @@ getEntries(keyPrefix: string, callback: AsyncCallback<Entry[]>): void **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -3061,21 +3064,21 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key', function (err, entries) { if (err != undefined) { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -3115,7 +3118,6 @@ getEntries(keyPrefix: string): Promise<Entry[]> **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -3129,17 +3131,17 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries).then(async (entries) => { - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key').then((entries) => { - console.log('Succeeded in getting Entries'); - console.log(`PutBatch ${entries}`); + console.info('Succeeded in getting Entries'); + console.info(`PutBatch ${entries}`); }).catch((err) => { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message} `); @@ -3173,7 +3175,6 @@ getEntries(query: Query, callback: AsyncCallback<Entry[]>): void **示例:** ```js -let kvStore; try { var arr = new Uint8Array([21, 31]); let entries = []; @@ -3188,23 +3189,23 @@ try { } entries.push(entry); } - console.log(`entries: {entries}`); + console.info(`entries: {entries}`); kvStore.putBatch(entries, async function (err, data) { - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getEntries(query, function (err, entries) { if (err != undefined) { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { - console.error(`Fail to get Entries.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get Entries.code is ${e.code},message is ${e.message}`); } ``` @@ -3240,7 +3241,6 @@ getEntries(query: Query): Promise<Entry[]> **示例:** ```js -let kvStore; try { var arr = new Uint8Array([21, 31]); let entries = []; @@ -3255,22 +3255,22 @@ try { } entries.push(entry); } - console.log(`entries: {entries}`); + console.info(`entries: {entries}`); kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getEntries(query).then((entries) => { - console.log('Succeeded in getting Entries'); + console.info('Succeeded in getting Entries'); }).catch((err) => { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`) + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`) }); - console.log('Succeeded in getting Entries'); + console.info('Succeeded in getting Entries'); } catch (e) { - console.error(`Fail to get Entries.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get Entries.code is ${e.code},message is ${e.message}`); } ``` @@ -3303,7 +3303,6 @@ getResultSet(keyPrefix: string, callback: AsyncCallback<KVStoreResultSet>) **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -3320,23 +3319,23 @@ try { } kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); kvStore.getResultSet('batch_test_string_key', async function (err, result) { if (err != undefined) { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; kvStore.closeResultSet(resultSet, function (err, data) { if (err != undefined) { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); }); @@ -3378,7 +3377,6 @@ getResultSet(keyPrefix: string): Promise<KVStoreResultSet> **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -3394,20 +3392,20 @@ try { entries.push(entry); } kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }).catch((err) => { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -3442,7 +3440,6 @@ getResultSet(query: Query, callback: AsyncCallback<KVStoreResultSet>): voi **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -3459,18 +3456,18 @@ try { } kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet(query, async function (err, result) { if (err != undefined) { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); }); }); } catch (e) { @@ -3511,7 +3508,6 @@ getResultSet(query: Query): Promise<KVStoreResultSet> **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -3527,17 +3523,17 @@ try { entries.push(entry); } kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet(query).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -3576,24 +3572,23 @@ getResultSet(predicates: dataSharePredicates.DataSharePredicates, callback: Asyn ```js import dataSharePredicates from '@ohos.data.dataSharePredicates'; -let kvStore; try { let resultSet; let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet(predicates, async function (err, result) { if (err != undefined) { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; kvStore.closeResultSet(resultSet, function (err, data) { if (err != undefined) { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); } catch (e) { @@ -3638,21 +3633,20 @@ getResultSet(predicates: dataSharePredicates.DataSharePredicates): Promise<KV ```js import dataSharePredicates from '@ohos.data.dataSharePredicates'; -let kvStore; try { let resultSet; let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet(predicates).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }).catch((err) => { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -3677,14 +3671,13 @@ closeResultSet(resultSet: KVStoreResultSet, callback: AsyncCallback<void>) **示例:** ```js -let kvStore; try { let resultSet = null; kvStore.closeResultSet(resultSet, function (err, data) { if (err == undefined) { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); } else { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); } }); } catch (e) { @@ -3715,13 +3708,12 @@ closeResultSet(resultSet: KVStoreResultSet): Promise<void> **示例:** ```js -let kvStore; try { let resultSet = null; kvStore.closeResultSet(resultSet).then(() => { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }).catch((err) => { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -3755,7 +3747,6 @@ getResultSize(query: Query, callback: AsyncCallback<number>): void **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -3770,15 +3761,15 @@ try { entries.push(entry); } kvStore.putBatch(entries, async function (err, data) { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize(query, async function (err, resultSize) { if (err != undefined) { - console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get result size.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set size'); + console.info('Succeeded in getting result set size'); }); }); } catch (e) { @@ -3818,7 +3809,6 @@ getResultSize(query: Query): Promise<number> **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -3833,16 +3823,16 @@ try { entries.push(entry); } kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize(query).then((resultSize) => { - console.log('Succeeded in getting result set size'); + console.info('Succeeded in getting result set size'); }).catch((err) => { - console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get result size.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -3875,12 +3865,11 @@ backup(file:string, callback: AsyncCallback<void>):void **示例:** ```js -let kvStore; let file = "BK001"; try { kvStore.backup(file, (err, data) => { if (err) { - console.error(`Fail to backup.code is ${err.code},message is ${err.message} `); + console.error(`Failed to backup.code is ${err.code},message is ${err.message} `); } else { console.info(`Succeeded in backupping data.data=${data}`); } @@ -3921,13 +3910,12 @@ backup(file:string): Promise<void> **示例:** ```js -let kvStore; let file = "BK001"; try { kvStore.backup(file).then((data) => { console.info(`Succeeded in backupping data.data=${data}`); }).catch((err) => { - console.error(`Fail to backup.code is ${err.code},message is ${err.message}`); + console.error(`Failed to backup.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -3960,12 +3948,11 @@ restore(file:string, callback: AsyncCallback<void>):void **示例:** ```js -let kvStore; let file = "BK001"; try { kvStore.restore(file, (err, data) => { if (err) { - console.error(`Fail to restore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to restore.code is ${err.code},message is ${err.message}`); } else { console.info(`Succeeded in restoring data.data=${data}`); } @@ -4006,13 +3993,12 @@ restore(file:string): Promise<void> **示例:** ```js -let kvStore; let file = "BK001"; try { kvStore.restore(file).then((data) => { console.info(`Succeeded in restoring data.data=${data}`); }).catch((err) => { - console.error(`Fail to restore.code is ${err.code},message is ${err.message}`); + console.error(`Failed to restore.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4037,12 +4023,11 @@ deleteBackup(files:Array<string>, callback: AsyncCallback<Array<[str **示例:** ```js -let kvStore; let files = ["BK001", "BK002"]; try { kvStore.deleteBackup(files, (err, data) => { if (err) { - console.error(`Fail to delete Backup.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete Backup.code is ${err.code},message is ${err.message}`); } else { console.info(`Succeed in deleting Backup.data=${data}`); } @@ -4075,16 +4060,15 @@ deleteBackup(files:Array<string>): Promise<Array<[string, number]> **示例:** ```js -let kvStore; let files = ["BK001", "BK002"]; try { kvStore.deleteBackup(files).then((data) => { console.info(`Succeed in deleting Backup.data=${data}`); }).catch((err) => { - console.error(`Fail to delete Backup.code is ${err.code},message is ${err.message}`); + console.error(`Failed to delete Backup.code is ${err.code},message is ${err.message}`); }) } catch (e) { - console.log(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); + console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); } ``` @@ -4119,7 +4103,6 @@ startTransaction(callback: AsyncCallback<void>): void **示例:** ```js -let kvStore; function putBatchString(len, prefix) { let entries = []; for (var i = 0; i < len; i++) { @@ -4138,27 +4121,27 @@ function putBatchString(len, prefix) { try { var count = 0; kvStore.on('dataChange', 0, function (data) { - console.log(`startTransaction 0 ${data}`); + console.info(`startTransaction 0 ${data}`); count++; }); kvStore.startTransaction(async function (err, data) { if (err != undefined) { - console.error(`Fail to start Transaction.code is ${err.code},message is ${err.message}`); + console.error(`Failed to start Transaction.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in starting Transaction'); + console.info('Succeeded in starting Transaction'); let entries = putBatchString(10, 'batch_test_string_key'); - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); }); }); } catch (e) { - console.error(`Fail to start Transaction.code is ${e.code},message is ${e.message}`); + console.error(`Failed to start Transaction.code is ${e.code},message is ${e.message}`); } ``` @@ -4193,20 +4176,19 @@ startTransaction(): Promise<void> **示例:** ```js -let kvStore; try { var count = 0; kvStore.on('dataChange', distributedKVStore.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) { - console.log(`startTransaction 0 ${data}`); + console.info(`startTransaction 0 ${data}`); count++; }); kvStore.startTransaction().then(async (err) => { - console.log('Succeeded in starting Transaction'); + console.info('Succeeded in starting Transaction'); }).catch((err) => { - console.error(`Fail to start Transaction.code is ${err.code},message is ${err.message}`); + console.error(`Failed to start Transaction.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to start Transaction.code is ${e.code},message is ${e.message}`); + console.error(`Failed to start Transaction.code is ${e.code},message is ${e.message}`); } ``` @@ -4235,13 +4217,12 @@ commit(callback: AsyncCallback<void>): void **示例:** ```js -let kvStore; try { kvStore.commit(function (err, data) { if (err == undefined) { - console.log('Succeeded in committing'); + console.info('Succeeded in committing'); } else { - console.error(`Fail to commit.code is ${err.code},message is ${err.message}`); + console.error(`Failed to commit.code is ${err.code},message is ${err.message}`); } }); } catch (e) { @@ -4274,12 +4255,11 @@ commit(): Promise<void> **示例:** ```js -let kvStore; try { kvStore.commit().then(async (err) => { - console.log('Succeeded in committing'); + console.info('Succeeded in committing'); }).catch((err) => { - console.error(`Fail to commit.code is ${err.code},message is ${err.message}`); + console.error(`Failed to commit.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.ode is ${e.code},message is ${e.message}`); @@ -4311,13 +4291,12 @@ rollback(callback: AsyncCallback<void>): void **示例:** ```js -let kvStore; try { kvStore.rollback(function (err,data) { if (err == undefined) { - console.log('Succeeded in rolling back'); + console.info('Succeeded in rolling back'); } else { - console.error(`Fail to rollback.code is ${err.code},message is ${err.message}`); + console.error(`Failed to rollback.code is ${err.code},message is ${err.message}`); } }); }catch(e) { @@ -4350,12 +4329,11 @@ rollback(): Promise<void> **示例:** ```js -let kvStore; try { kvStore.rollback().then(async (err) => { - console.log('Succeeded in rolling back'); + console.info('Succeeded in rolling back'); }).catch((err) => { - console.error(`Fail to rollback.code is ${err.code},message is ${err.message}`); + console.error(`Failed to rollback.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4380,13 +4358,12 @@ enableSync(enabled: boolean, callback: AsyncCallback<void>): void **示例:** ```js -let kvStore; try { kvStore.enableSync(true, function (err, data) { if (err == undefined) { - console.log('Succeeded in enabling sync'); + console.info('Succeeded in enabling sync'); } else { - console.error(`Fail to enable sync.code is ${err.code},message is ${err.message}`); + console.error(`Failed to enable sync.code is ${err.code},message is ${err.message}`); } }); } catch (e) { @@ -4417,12 +4394,11 @@ enableSync(enabled: boolean): Promise<void> **示例:** ```js -let kvStore; try { kvStore.enableSync(true).then((err) => { - console.log('Succeeded in enabling sync'); + console.info('Succeeded in enabling sync'); }).catch((err) => { - console.error(`Fail to enable sync.code is ${err.code},message is ${err.message}`); + console.error(`Failed to enable sync.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4448,16 +4424,15 @@ setSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: Asy **示例:** ```js -let kvStore; try { const localLabels = ['A', 'B']; const remoteSupportLabels = ['C', 'D']; kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err, data) { if (err != undefined) { - console.error(`Fail to set syncRange.code is ${err.code},message is ${err.message}`); + console.error(`Failed to set syncRange.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in setting syncRange'); + console.info('Succeeded in setting syncRange'); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4488,14 +4463,13 @@ setSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise<v **示例:** ```js -let kvStore; try { const localLabels = ['A', 'B']; const remoteSupportLabels = ['C', 'D']; kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => { - console.log('Succeeded in setting syncRange'); + console.info('Succeeded in setting syncRange'); }).catch((err) => { - console.error(`Fail to set syncRange.code is ${err.code},message is ${err.message}`); + console.error(`Failed to set syncRange.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4520,15 +4494,14 @@ setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback<void>) **示例:** ```js -let kvStore; try { const defaultAllowedDelayMs = 500; kvStore.setSyncParam(defaultAllowedDelayMs, function (err, data) { if (err != undefined) { - console.error(`Fail to set syncParam.code is ${err.code},message is ${err.message}`); + console.error(`Failed to set syncParam.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in setting syncParam'); + console.info('Succeeded in setting syncParam'); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4558,13 +4531,12 @@ setSyncParam(defaultAllowedDelayMs: number): Promise<void> **示例:** ```js -let kvStore; try { const defaultAllowedDelayMs = 500; kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => { - console.log('Succeeded in setting syncParam'); + console.info('Succeeded in setting syncParam'); }).catch((err) => { - console.error(`Fail to set syncParam.code is ${err.code},message is ${err.message}`); + console.error(`Failed to set syncParam.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4607,7 +4579,6 @@ sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void import deviceManager from '@ohos.distributedHardware.deviceManager'; let devManager; -let kvStore; const KEY_TEST_SYNC_ELEMENT = 'key_test_sync'; const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; // create deviceManager @@ -4623,19 +4594,19 @@ deviceManager.createDeviceManager('bundleName', (err, value) => { } try { kvStore.on('syncComplete', function (data) { - console.log('Sync dataChange'); + console.info('Sync dataChange'); }); kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to sync.code is ${err.code},message is ${err.message}`); + console.error(`Failed to sync.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting data'); + console.info('Succeeded in putting data'); const mode = distributedKVStore.SyncMode.PULL_ONLY; kvStore.sync(deviceIds, mode, 1000); }); } catch (e) { - console.error(`Fail to sync.code is ${e.code},message is ${e.message}`); + console.error(`Failed to sync.code is ${e.code},message is ${e.message}`); } } }); @@ -4678,7 +4649,6 @@ sync(deviceIds: string[], query: Query, mode: SyncMode, delayMs?: number): void import deviceManager from '@ohos.distributedHardware.deviceManager'; let devManager; -let kvStore; const KEY_TEST_SYNC_ELEMENT = 'key_test_sync'; const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; // create deviceManager @@ -4694,14 +4664,14 @@ deviceManager.createDeviceManager('bundleName', (err, value) => { } try { kvStore.on('syncComplete', function (data) { - console.log('Sync dataChange'); + console.info('Sync dataChange'); }); kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to sync.code is ${err.code},message is ${err.message}`); + console.error(`Failed to sync.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting data'); + console.info('Succeeded in putting data'); const mode = distributedKVStore.SyncMode.PULL_ONLY; const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); @@ -4709,7 +4679,7 @@ deviceManager.createDeviceManager('bundleName', (err, value) => { kvStore.sync(deviceIds, query, mode, 1000); }); } catch (e) { - console.error(`Fail to sync.code is ${e.code},message is ${e.message}`); + console.error(`Failed to sync.code is ${e.code},message is ${e.message}`); } } }); @@ -4743,10 +4713,9 @@ on(event: 'dataChange', type: SubscribeType, listener: Callback<ChangeNotific **示例:** ```js -let kvStore; try { kvStore.on('dataChange', distributedKVStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) { - console.log(`dataChange callback call data: ${data}`); + console.info(`dataChange callback call data: ${data}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4771,20 +4740,19 @@ on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]> **示例:** ```js -let kvStore; const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; const VALUE_TEST_FLOAT_ELEMENT = 321.12; try { kvStore.on('syncComplete', function (data) { - console.log(`syncComplete ${data}`); + console.info(`syncComplete ${data}`); }); kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => { - console.log('succeeded in putting'); + console.info('succeeded in putting'); }).catch((err) => { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to subscribe syncComplete.code is ${e.code},message is ${e.message}`); + console.error(`Failed to subscribe syncComplete.code is ${e.code},message is ${e.message}`); } ``` @@ -4814,10 +4782,9 @@ off(event:'dataChange', listener?: Callback<ChangeNotification>): void **示例:** ```js -let kvStore; class KvstoreModel { call(data) { - console.log(`dataChange : ${data}`); + console.info(`dataChange : ${data}`); } subscribeDataChange() { @@ -4826,7 +4793,7 @@ class KvstoreModel { kvStore.on('dataChange', distributedKVStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call); } } catch (err) { - console.error(`Fail to subscribeDataChange.code is ${err.code},message is ${err.message}`); + console.error(`Failed to subscribeDataChange.code is ${err.code},message is ${err.message}`); } } @@ -4836,7 +4803,7 @@ class KvstoreModel { kvStore.off('dataChange', this.call); } } catch (err) { - console.error(`Fail to unsubscribeDataChange.code is ${err.code},message is ${err.message}`); + console.error(`Failed to unsubscribeDataChange.code is ${err.code},message is ${err.message}`); } } } @@ -4860,10 +4827,9 @@ off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]& **示例:** ```js -let kvStore; class KvstoreModel { call(data) { - console.log(`syncComplete : ${data}`); + console.info(`syncComplete : ${data}`); } subscribeDataChange() { @@ -4872,7 +4838,7 @@ class KvstoreModel { kvStore.on('syncComplete', distributedKVStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call); } } catch (err) { - console.error(`Fail to subscribeDataChange.code is ${err.code},message is ${err.message}`); + console.error(`Failed to subscribeDataChange.code is ${err.code},message is ${err.message}`); } } @@ -4882,7 +4848,7 @@ class KvstoreModel { kvStore.off('dsyncComplete', this.call); } } catch (err) { - console.error(`Fail to unsubscribeDataChange.code is ${err.code},message is ${err.message}`); + console.error(`Failed to unsubscribeDataChange.code is ${err.code},message is ${err.message}`); } } } @@ -4913,14 +4879,13 @@ getSecurityLevel(callback: AsyncCallback<SecurityLevel>): void **示例:** ```js -let kvStore; try { kvStore.getSecurityLevel(function (err, data) { if (err != undefined) { - console.error(`Fail to get SecurityLevel.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get SecurityLevel.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting securityLevel'); + console.info('Succeeded in getting securityLevel'); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -4952,12 +4917,11 @@ getSecurityLevel(): Promise<SecurityLevel> **示例:** ```js -let kvStore; try { kvStore.getSecurityLevel().then((data) => { - console.log('Succeeded in getting securityLevel'); + console.info('Succeeded in getting securityLevel'); }).catch((err) => { - console.error(`Fail to get SecurityLevel.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get SecurityLevel.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message}`); @@ -5002,26 +4966,25 @@ get(key: string, callback: AsyncCallback<boolean | string | number | Uint8Arr **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log("Succeeded in putting"); + console.info("Succeeded in putting"); kvStore.get(KEY_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to get.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get.code is ${err.code},message is ${err.message}`); return; } - console.log(`Succeeded in getting data.data=${data}`); + console.info(`Succeeded in getting data.data=${data}`); }); }); } catch (e) { - console.error(`Fail to get.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get.code is ${e.code},message is ${e.message}`); } ``` @@ -5058,22 +5021,21 @@ get(key: string): Promise<boolean | string | number | Uint8Array> **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string'; const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in putting data.data=${data}`); + console.info(`Succeeded in putting data.data=${data}`); kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log(`Succeeded in getting data.data=${data}`); + console.info(`Succeeded in getting data.data=${data}`); }).catch((err) => { - console.error(`Fail to get.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to get.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get.code is ${e.code},message is ${e.message}`); } ``` @@ -5082,6 +5044,10 @@ try { get(deviceId: string, key: string, callback: AsyncCallback<boolean | string | number | Uint8Array>): void 获取与指定设备ID和key匹配的string值,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5106,26 +5072,25 @@ get(deviceId: string, key: string, callback: AsyncCallback<boolean | string | **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err, data) { if (err != undefined) { - console.error(`Fail to put.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting'); + console.info('Succeeded in putting'); kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err, data) { if (err != undefined) { - console.error(`Fail to get.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting'); + console.info('Succeeded in getting'); }); }) } catch (e) { - console.error(`Fail to get.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get.code is ${e.code},message is ${e.message}`); } ``` @@ -5134,6 +5099,10 @@ try { get(deviceId: string, key: string): Promise<boolean | string | number | Uint8Array> 获取与指定设备ID和key匹配的string值,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5163,22 +5132,21 @@ get(deviceId: string, key: string): Promise<boolean | string | number | Uint8 **示例:** ```js -let kvStore; const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; try { kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => { - console.log('Succeeded in putting'); + console.info('Succeeded in putting'); kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('Succeeded in getting'); + console.info('Succeeded in getting'); }).catch((err) => { - console.error(`Fail to get.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get.code is ${err.code},message is ${err.message}`); }); }).catch((error) => { - console.error(`Fail to put.code is ${error.code},message is ${error.message}`); + console.error(`Failed to put.code is ${error.code},message is ${error.message}`); }); } catch (e) { - console.error(`Fail to get.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get.code is ${e.code},message is ${e.message}`); } ``` @@ -5209,7 +5177,6 @@ getEntries(keyPrefix: string, callback: AsyncCallback<Entry[]>): void **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -5223,21 +5190,21 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key', function (err, entries) { if (err != undefined) { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { @@ -5277,7 +5244,6 @@ getEntries(keyPrefix: string): Promise<Entry[]> **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -5291,17 +5257,17 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries).then(async (entries) => { - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); kvStore.getEntries('batch_test_string_key').then((entries) => { - console.log('Succeeded in getting Entries'); - console.log(`PutBatch ${entries}`); + console.info('Succeeded in getting Entries'); + console.info(`PutBatch ${entries}`); }).catch((err) => { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put Batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put Batch.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.message} `); @@ -5313,6 +5279,10 @@ try { getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback<Entry[]>): void 获取与指定设备ID和key前缀匹配的所有键值对,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5336,7 +5306,6 @@ getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback<Entry **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -5350,25 +5319,25 @@ try { } entries.push(entry); } - console.log(`entries : ${entries}`); + console.info(`entries : ${entries}`); kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err, entries) { if (err != undefined) { - console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { - console.error(`Fail to put batch.code is ${e.code},message is ${e.message}`); + console.error(`Failed to put batch.code is ${e.code},message is ${e.message}`); } ``` @@ -5377,6 +5346,10 @@ try { getEntries(deviceId: string, keyPrefix: string): Promise<Entry[]> 获取与指定设备ID和key前缀匹配的所有键值对,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5405,7 +5378,6 @@ getEntries(deviceId: string, keyPrefix: string): Promise<Entry[]> **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -5419,23 +5391,23 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entries) => { - console.log('Succeeded in getting entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); - console.log(`entries[0].value: ${entries[0].value}`); - console.log(`entries[0].value.value: ${entries[0].value.value}`); + console.info('Succeeded in getting entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); + console.info(`entries[0].value: ${entries[0].value}`); + console.info(`entries[0].value.value: ${entries[0].value.value}`); }).catch((err) => { - console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to put batch.code is ${e.code},message is ${e.message}`); + console.error(`Failed to put batch.code is ${e.code},message is ${e.message}`); } ``` @@ -5466,7 +5438,6 @@ getEntries(query: Query, callback: AsyncCallback<Entry[]>): void **示例:** ```js -let kvStore; try { var arr = new Uint8Array([21, 31]); let entries = []; @@ -5481,23 +5452,23 @@ try { } entries.push(entry); } - console.log(`entries: {entries}`); + console.info(`entries: {entries}`); kvStore.putBatch(entries, async function (err, data) { - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getEntries(query, function (err, entries) { if (err != undefined) { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting Entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting Entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }); }); } catch (e) { - console.error(`Fail to get Entries.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get Entries.code is ${e.code},message is ${e.message}`); } ``` @@ -5533,7 +5504,6 @@ getEntries(query: Query): Promise<Entry[]> **示例:** ```js -let kvStore; try { var arr = new Uint8Array([21, 31]); let entries = []; @@ -5548,22 +5518,22 @@ try { } entries.push(entry); } - console.log(`entries: {entries}`); + console.info(`entries: {entries}`); kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting Batch'); + console.info('Succeeded in putting Batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getEntries(query).then((entries) => { - console.log('Succeeded in getting Entries'); + console.info('Succeeded in getting Entries'); }).catch((err) => { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to get Entries.code is ${err.code},message is ${err.message}`) + console.error(`Failed to get Entries.code is ${err.code},message is ${err.message}`) }); - console.log('Succeeded in getting Entries'); + console.info('Succeeded in getting Entries'); } catch (e) { - console.error(`Fail to get Entries.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get Entries.code is ${e.code},message is ${e.message}`); } ``` @@ -5572,6 +5542,10 @@ try { getEntries(deviceId: string, query: Query, callback: AsyncCallback<Entry[]>): void 获取与指定设备ID和Query对象匹配的键值对列表,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5595,7 +5569,6 @@ getEntries(deviceId: string, query: Query, callback: AsyncCallback<Entry[]> **示例:** ```js -let kvStore; try { var arr = new Uint8Array([21, 31]); let entries = []; @@ -5610,29 +5583,29 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); var query = new distributedKVStore.Query(); query.deviceId('localDeviceId'); query.prefixKey("batch_test"); kvStore.getEntries('localDeviceId', query, function (err, entries) { if (err != undefined) { - console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get entries.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting entries'); - console.log(`entries.length: ${entries.length}`); - console.log(`entries[0]: ${entries[0]}`); + console.info('Succeeded in getting entries'); + console.info(`entries.length: ${entries.length}`); + console.info(`entries[0]: ${entries[0]}`); }) }); - console.log('Succeeded in getting entries'); + console.info('Succeeded in getting entries'); } catch (e) { - console.error(`Fail to get entries.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get entries.code is ${e.code},message is ${e.message}`); } ``` @@ -5641,6 +5614,10 @@ try { getEntries(deviceId: string, query: Query): Promise<Entry[]> 获取与指定设备ID和Query对象匹配的键值对列表,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5669,7 +5646,6 @@ getEntries(deviceId: string, query: Query): Promise<Entry[]> **示例:** ```js -let kvStore; try { var arr = new Uint8Array([21, 31]); let entries = []; @@ -5684,23 +5660,23 @@ try { } entries.push(entry); } - console.log(`entries: ${entries}`); + console.info(`entries: ${entries}`); kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); var query = new distributedKVStore.Query(); query.deviceId('localDeviceId'); query.prefixKey("batch_test"); kvStore.getEntries('localDeviceId', query).then((entries) => { - console.log('Succeeded in getting entries'); + console.info('Succeeded in getting entries'); }).catch((err) => { - console.error(`Fail to get entries.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get entries.code is ${err.code},message is ${err.message}`); }); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); - console.log('Succeeded in getting entries'); + console.info('Succeeded in getting entries'); } catch (e) { - console.error(`Fail to get entries.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get entries.code is ${e.code},message is ${e.message}`); } ``` @@ -5732,7 +5708,6 @@ getResultSet(keyPrefix: string, callback: AsyncCallback<KVStoreResultSet>) **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -5749,23 +5724,23 @@ try { } kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); kvStore.getResultSet('batch_test_string_key', async function (err, result) { if (err != undefined) { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; kvStore.closeResultSet(resultSet, function (err, data) { if (err != undefined) { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); }); @@ -5807,7 +5782,6 @@ getResultSet(keyPrefix: string): Promise<KVStoreResultSet> **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -5823,20 +5797,20 @@ try { entries.push(entry); } kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }).catch((err) => { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -5848,6 +5822,10 @@ try { getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback<KVStoreResultSet>): void 获取与指定设备ID和key前缀匹配的KVStoreResultSet对象,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5872,26 +5850,25 @@ getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback<KVS **示例:** ```js -let kvStore; try { let resultSet; kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) { if (err != undefined) { - console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; kvStore.closeResultSet(resultSet, function (err, data) { if (err != undefined) { - console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing resultSet'); + console.info('Succeeded in closing resultSet'); }) }); } catch (e) { - console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get resultSet.code is ${e.code},message is ${e.message}`); } ``` @@ -5900,6 +5877,10 @@ try { getResultSet(deviceId: string, keyPrefix: string): Promise<KVStoreResultSet> 获取与指定设备ID和key前缀匹配的KVStoreResultSet对象,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5929,22 +5910,21 @@ getResultSet(deviceId: string, keyPrefix: string): Promise<KVStoreResultSet&g **示例:** ```js -let kvStore; try { let resultSet; kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => { - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); }); kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing resultSet'); + console.info('Succeeded in closing resultSet'); }).catch((err) => { - console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get resultSet.code is ${e.code},message is ${e.message}`); } ``` @@ -5953,6 +5933,10 @@ try { getResultSet(deviceId: string, query: Query, callback: AsyncCallback<KVStoreResultSet>): void 获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -5977,7 +5961,6 @@ getResultSet(deviceId: string, query: Query, callback: AsyncCallback<KVStoreR **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -5994,30 +5977,30 @@ try { } kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet('localDeviceId', query, async function (err, result) { if (err != undefined) { - console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; kvStore.closeResultSet(resultSet, function (err, data) { if (err != undefined) { - console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing resultSet'); + console.info('Succeeded in closing resultSet'); }) }); }); } catch (e) { - console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get resultSet.code is ${e.code},message is ${e.message}`); } ``` @@ -6026,6 +6009,10 @@ try { getResultSet(deviceId: string, query: Query): Promise<KVStoreResultSet> 获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -6055,7 +6042,6 @@ getResultSet(deviceId: string, query: Query): Promise<KVStoreResultSet> **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -6071,28 +6057,28 @@ try { entries.push(entry); } kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet('localDeviceId', query).then((result) => { - console.log('Succeeded in getting resultSet'); + console.info('Succeeded in getting resultSet'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); }); query.deviceId('localDeviceId'); - console.log("GetResultSet " + query.getSqlLike()); + console.info("GetResultSet " + query.getSqlLike()); kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing resultSet'); + console.info('Succeeded in closing resultSet'); }).catch((err) => { - console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get resultSet.code is ${e.code},message is ${e.message}`); } ``` @@ -6129,7 +6115,6 @@ getResultSet(query: Query): Promise<KVStoreResultSet> **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -6145,17 +6130,17 @@ try { entries.push(entry); } kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSet(query).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -6164,24 +6149,23 @@ try { ### getResultSet -getResultSet(deviceId: string, query: Query): Promise<KVStoreResultSet> +getResultSet(query: Query, callback:AsyncCallback<KVStoreResultSet>): void -获取与指定设备ID和Query对象匹配的KVStoreResultSet对象,使用Promise异步回调。 +获取与本设备指定Query对象匹配的KVStoreResultSet对象,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 -**系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore +**系统能力:** SystemCapability.DistributedDataManager.KVStore.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------- | ---- | ---------------------------------- | -| deviceId | string | 是 | KVStoreResultSet对象所属的设备ID。 | | query | [Query](#query) | 是 | 表示查询对象。 | +| callback | AsyncCallback<[KVStoreResultSet](#kvstoreresultset)> | 是 | 回调函数,获取与指定Predicates对象匹配的KVStoreResultSet对象。 | -**返回值:** - -| 类型 | 说明 | -| ---------------------------------------------------- | ------------------------------------------------------------ | -| Promise<[KVStoreResultSet](#kvstoreresultset)> | Promise对象。返回与指定设备ID和Query对象匹配的KVStoreResultSet对象。 | **错误码:** @@ -6196,7 +6180,6 @@ getResultSet(deviceId: string, query: Query): Promise<KVStoreResultSet> **示例:** ```js -let kvStore; try { let resultSet; let entries = []; @@ -6211,29 +6194,32 @@ try { } entries.push(entry); } - kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); - }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); - }); - const query = new distributedKVStore.Query(); - query.prefixKey("batch_test"); - kvStore.getResultSet('localDeviceId', query).then((result) => { - console.log('Succeeded in getting resultSet'); - resultSet = result; - }).catch((err) => { - console.error(`Fail to get resultSet.code is ${err.code},message is ${err.message}`); - }); - query.deviceId('localDeviceId'); - console.log("GetResultSet " + query.getSqlLike()); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing resultSet'); - }).catch((err) => { - console.error(`Fail to close resultSet.code is ${err.code},message is ${err.message}`); + kvStore.putBatch(entries, async function (err, data) { + if (err != undefined) { + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); + return; + } + console.info('Succeeded in putting batch'); + const query = new distributedKVStore.Query(); + query.prefixKey("batch_test"); + kvStore.getResultSet(query, async function (err, result) { + if (err != undefined) { + console.error(`Failed to get resultSet.code is ${err.code},message is ${err.message}`); + return; + } + console.info('Succeeded in getting resultSet'); + resultSet = result; + kvStore.closeResultSet(resultSet, function (err, data) { + if (err != undefined) { + console.error(`Failed to close resultSet.code is ${err.code},message is ${err.message}`); + return; + } + console.info('Succeeded in closing resultSet'); + }) + }); }); - } catch (e) { - console.error(`Fail to get resultSet.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get resultSet.code is ${e.code},message is ${e.message}`); } ``` @@ -6269,24 +6255,23 @@ getResultSet(predicates: dataSharePredicates.DataSharePredicates, callback: Asyn ```js import dataSharePredicates from '@ohos.data.dataSharePredicates'; -let kvStore; try { let resultSet; let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet(predicates, async function (err, result) { if (err != undefined) { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; kvStore.closeResultSet(resultSet, function (err, data) { if (err != undefined) { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); } catch (e) { @@ -6331,21 +6316,20 @@ getResultSet(predicates: dataSharePredicates.DataSharePredicates): Promise<KV ```js import dataSharePredicates from '@ohos.data.dataSharePredicates'; -let kvStore; try { let resultSet; let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet(predicates).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }).catch((err) => { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -6357,6 +6341,10 @@ try { getResultSet(deviceId: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<KVStoreResultSet>): void 获取与指定Predicate对象匹配的KVStoreResultSet对象,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统接口:** 此接口为系统接口。 @@ -6385,24 +6373,23 @@ getResultSet(deviceId: string, predicates: dataSharePredicates.DataSharePredicat ```js import dataSharePredicates from '@ohos.data.dataSharePredicates'; -let kvStore; try { let resultSet; let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet('localDeviceId', predicates, async function (err, result) { if (err != undefined) { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; kvStore.closeResultSet(resultSet, function (err, data) { if (err != undefined) { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }) }); } catch (e) { @@ -6415,6 +6402,10 @@ try { getResultSet(deviceId: string, predicates: dataSharePredicates.DataSharePredicates): Promise<KVStoreResultSet> 获取与指定Predicate对象匹配的KVStoreResultSet对象,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统接口:** 此接口为系统接口。 @@ -6447,21 +6438,21 @@ getResultSet(deviceId: string, predicates: dataSharePredicates.DataSharePredicat ```js import dataSharePredicates from '@ohos.data.dataSharePredicates'; -let kvStore; + try { let resultSet; let predicates = new dataSharePredicates.DataSharePredicates(); predicates.prefixKey("batch_test_string_key"); kvStore.getResultSet('localDeviceId', predicates).then((result) => { - console.log('Succeeded in getting result set'); + console.info('Succeeded in getting result set'); resultSet = result; }).catch((err) => { - console.error(`Fail to get resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultset.code is ${err.code},message is ${err.message}`); }); kvStore.closeResultSet(resultSet).then((err) => { - console.log('Succeeded in closing result set'); + console.info('Succeeded in closing result set'); }).catch((err) => { - console.error(`Fail to close resultset.code is ${err.code},message is ${err.message}`); + console.error(`Failed to close resultset.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -6495,7 +6486,6 @@ getResultSize(query: Query, callback: AsyncCallback<number>): void **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -6510,15 +6500,15 @@ try { entries.push(entry); } kvStore.putBatch(entries, async function (err, data) { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize(query, async function (err, resultSize) { if (err != undefined) { - console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get result size.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting result set size'); + console.info('Succeeded in getting result set size'); }); }); } catch (e) { @@ -6558,7 +6548,6 @@ getResultSize(query: Query): Promise<number> **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -6573,16 +6562,16 @@ try { entries.push(entry); } kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize(query).then((resultSize) => { - console.log('Succeeded in getting result set size'); + console.info('Succeeded in getting result set size'); }).catch((err) => { - console.error(`Fail to get result size.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get result size.code is ${err.code},message is ${err.message}`); }); } catch (e) { console.error(`An unexpected error occurred.code is ${e.code},message is ${e.code}`); @@ -6594,6 +6583,10 @@ try { getResultSize(deviceId: string, query: Query, callback: AsyncCallback<number>): void; 获取与指定设备ID和Query对象匹配的结果数,使用callback异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -6617,7 +6610,6 @@ getResultSize(deviceId: string, query: Query, callback: AsyncCallback<number& **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -6633,23 +6625,23 @@ try { } kvStore.putBatch(entries, async function (err, data) { if (err != undefined) { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); const query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) { if (err != undefined) { - console.error(`Fail to get resultSize.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultSize.code is ${err.code},message is ${err.message}`); return; } - console.log('Succeeded in getting resultSize'); + console.info('Succeeded in getting resultSize'); ; }); }); } catch (e) { - console.error(`Fail to get resultSize.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get resultSize.code is ${e.code},message is ${e.message}`); } ``` @@ -6658,6 +6650,10 @@ try { getResultSize(deviceId: string, query: Query): Promise<number> 获取与指定设备ID和Query对象匹配的结果数,使用Promise异步回调。 +> **说明:** +> +> 其中deviceId通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。 +> deviceId具体获取方式请参考[sync接口示例](#sync)。 **系统能力:** SystemCapability.DistributedDataManager.KVStore.DistributedKVStore @@ -6686,7 +6682,6 @@ getResultSize(deviceId: string, query: Query): Promise<number> **示例:** ```js -let kvStore; try { let entries = []; for (var i = 0; i < 10; i++) { @@ -6701,19 +6696,19 @@ try { entries.push(entry); } kvStore.putBatch(entries).then(async (err) => { - console.log('Succeeded in putting batch'); + console.info('Succeeded in putting batch'); }).catch((err) => { - console.error(`Fail to put batch.code is ${err.code},message is ${err.message}`); + console.error(`Failed to put batch.code is ${err.code},message is ${err.message}`); }); var query = new distributedKVStore.Query(); query.prefixKey("batch_test"); kvStore.getResultSize('localDeviceId', query).then((resultSize) => { - console.log('Succeeded in getting resultSize'); + console.info('Succeeded in getting resultSize'); ; }).catch((err) => { - console.error(`Fail to get resultSize.code is ${err.code},message is ${err.message}`); + console.error(`Failed to get resultSize.code is ${err.code},message is ${err.message}`); }); } catch (e) { - console.error(`Fail to get resultSize.code is ${e.code},message is ${e.message}`); + console.error(`Failed to get resultSize.code is ${e.code},message is ${e.message}`); } ```