diff --git a/en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md b/en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md index 0a97689f23cdf69527c61dfc8dfba28e6869badf..f90ebe121ecd896a3f63425ec1b7f79d277c7d8e 100644 --- a/en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md +++ b/en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md @@ -17,26 +17,6 @@ The **DataShareExtensionAbility** module provides data share services based on t import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility'; ``` -## URI Naming Rule - -The URIs are in the following format: - -**Scheme://authority/path** -- *Scheme*: scheme name, which has a fixed value of **datashare** for the **DataShare** module. -- *authority*: [userinfo@]host[:port] - - *userinfo*: login information, which can be left unspecified. - - *host*: server address. It is the target device ID for cross-device access and empty for local device access. - - *port*: port number of the server, which can be left unspecified. -- *path*: **DataShare** identifier and the resource path. The **DataShare** identifier is mandatory, and the resource path is optional. - -Example: - -- URI without the resource path:
**datashare:///com.samples.datasharetest.DataShare** - -- URI with the resource path:
**datashare:///com.samples.datasharetest.DataShare/DB00/TBL00** - -**com.samples.datasharetest.DataShare** is the data share identifier, and **DB00/TBL00** is the resource path. - ## Attributes **System capability**: SystemCapability.DistributedDataManager.DataShare.Provider @@ -57,7 +37,7 @@ Called by the server to initialize service logic when the DataShare client conne | Name| Type| Mandatory| Description| | ----- | ------ | ------ | ------ | -| want | [Want](js-apis-application-want.md#want) | Yes | **Want** information, including the ability name and bundle name.| +| want | [Want](js-apis-application-want.md#want) | Yes | Want information, including the ability name and bundle name.| | callback | AsyncCallback<void> | Yes| Callback that returns no value.| **Example** @@ -78,10 +58,10 @@ export default class DataShareExtAbility extends DataShareExtensionAbility { name: DB_NAME, securityLevel: rdb.SecurityLevel.S1 }, function (err, data) { - console.log('getRdbStore done, data : ${data}'); + console.info(`getRdbStore done, data : ${data}`); rdbStore = data; rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { - console.error('executeSql done, error message : ${err}'); + console.error(`executeSql done, error message : ${err}`); }); if (callback) { callback(); @@ -122,11 +102,11 @@ let rdbStore; export default class DataShareExtAbility extends DataShareExtensionAbility { insert(uri, valueBucket, callback) { if (valueBucket === null) { - console.info('invalid valueBuckets'); + console.error('invalid valueBuckets'); return; } rdbStore.insert(TBL_NAME, valueBucket, function (err, ret) { - console.info('callback ret: ${ret}'); + console.info(`callback ret: ${ret}`); if (callback !== undefined) { callback(err, ret); } @@ -256,7 +236,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility { } rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) { if (resultSet !== undefined) { - console.info('resultSet.rowCount: ${resultSet.rowCount}'); + console.info(`resultSet.rowCount: ${resultSet.rowCount}`); } if (callback !== undefined) { callback(err, resultSet); @@ -297,14 +277,12 @@ let rdbStore; export default class DataShareExtAbility extends DataShareExtensionAbility { batchInsert(uri, valueBuckets, callback) { if (valueBuckets === null || valueBuckets.length === undefined) { - console.info('invalid valueBuckets'); + console.error('invalid valueBuckets'); return; } - let resultNum = valueBuckets.length; - valueBuckets.forEach(vb => { - rdbStore.insert(TBL_NAME, vb, function (err, ret) { + rdbStore.batchInsert(TBL_NAME, valueBuckets, function (err, ret) { if (callback !== undefined) { - callback(err, resultNum); + callback(err, ret); } }); }); @@ -333,7 +311,7 @@ Normalizes a URI. This API can be overridden as required. export default class DataShareExtAbility extends DataShareExtensionAbility { normalizeUri(uri, callback) { let err = {'code':0}; - let ret = 'normalize+${uri}'; + let ret = `normalize: ${uri}`; callback(err, ret); } }; @@ -360,7 +338,7 @@ Denormalizes a URI. This API can be overridden as required. export default class DataShareExtAbility extends DataShareExtensionAbility { denormalizeUri(uri, callback) { let err = {'code':0}; - let ret = 'denormalize+${uri}'; + let ret = `denormalize ${uri}`; callback(err, ret); } }; diff --git a/en/application-dev/reference/apis/js-apis-data-DataShareResultSet.md b/en/application-dev/reference/apis/js-apis-data-DataShareResultSet.md index 4cdef60fa628733e5be8cc6df783548b7b5bcd07..020d8c43c94ccb8313a7cde1fbad39048b11395b 100644 --- a/en/application-dev/reference/apis/js-apis-data-DataShareResultSet.md +++ b/en/application-dev/reference/apis/js-apis-data-DataShareResultSet.md @@ -27,7 +27,7 @@ let dataShareHelper; let uri = ("datashare:///com.samples.datasharetest.DataShare"); await dataShare.createDataShareHelper(this.context, uri, (err, data) => { if (err != undefined) { - console.info("createDataShareHelper fail, error message : " + err); + console.error("createDataShareHelper fail, error message : " + err); } else { console.info("createDataShareHelper end, data : " + data); dataShareHelper = data; @@ -39,10 +39,10 @@ let da = new dataSharePredicates.DataSharePredicates(); let resultSet; da.equalTo("name", "ZhangSan"); dataShareHelper.query(uri, da, columns).then((data) => { - console.log("query end, data : " + data); + console.info("query end, data : " + data); resultSet = data; }).catch((err) => { - console.log("query fail, error message : " + err); + console.error("query fail, error message : " + err); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-data-dataShare.md b/en/application-dev/reference/apis/js-apis-data-dataShare.md index b79161a08e5916eecca479c99f6fd852f8e6fd4a..991aa683273c5c1408c0574bffa48c8cd342a96a 100644 --- a/en/application-dev/reference/apis/js-apis-data-dataShare.md +++ b/en/application-dev/reference/apis/js-apis-data-dataShare.md @@ -4,12 +4,11 @@ The **DataShare** module allows an application to manage its own data and share > **NOTE** > -> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > +> The APIs provided by this module are system APIs. > -> - The APIs provided by this module are system APIs. -> -> - The APIs of this module can be used only in the stage model. +> The APIs of this module can be used only in the stage model. ## Modules to Import @@ -18,46 +17,74 @@ The **DataShare** module allows an application to manage its own data and share import dataShare from '@ohos.data.dataShare' ``` -## URI Naming Rule +## dataShare.createDataShareHelper -The URIs are in the following format: +createDataShareHelper(context: Context, uri: string, callback: AsyncCallback<DataShareHelper>): void -**Scheme://authority/path** -- *Scheme*: scheme name, which has a fixed value of **datashare** for the **DataShare** module. -- *authority*: [userinfo@]host[:port] - - *userinfo*: login information, which can be left unspecified. - - *host*: server address. It is the target device ID for cross-device access and empty for local device access. - - *port*: port number of the server, which can be left unspecified. -- *path*: **DataShare** identifier and the resource path. The **DataShare** identifier is mandatory, and the resource path is optional. +Creates a **DataShareHelper** instance. This API uses an asynchronous callback to return the result. -Example: +Observe the following when using this API: + - If an application running in the background needs to call this API to access **DataShareExtension**, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + - If **exported** of the target **DataShareExtension** is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). -- URI without the resource path:
**datashare:///com.samples.datasharetest.DataShare** +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer -- URI with the resource path:
**datashare:///com.samples.datasharetest.DataShare/DB00/TBL00** +**Parameters** -**com.samples.datasharetest.DataShare** is the data share identifier, and **DB00/TBL00** is the resource path. +| Name | Type | Mandatory| Description | +| -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | +| uri | string | Yes | Uniform Resource Identifier (URI) of the server application to connect. | +| callback | AsyncCallback<[DataShareHelper](#datasharehelper)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the **DataShareHelper** instance created. Otherwise, **err** is an error object.| +**Error codes** -## dataShare.createDataShareHelper +For details about the error codes, see [DataShare Error Codes](../errorcodes/errorcode-datashare.md). -createDataShareHelper(context: Context, uri: string, callback: AsyncCallback<DataShareHelper>): void +| ID| Error Message | +| -------- | ---------------------------------------------------- | +| 15700010 | The DataShareHelper is not initialized successfully. | + +**Example** + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; + +let uri = ("datashare:///com.samples.datasharetest.DataShare"); +let dataShareHelper; +try { + dataShare.createDataShareHelper(this.context, uri, (err, data) => { + if (err !== undefined) { + console.error(`createDataShareHelper error: code: ${err.code}, message: ${err.message} `); + return; + } + console.info("createDataShareHelper succeed, data : " + data); + dataShareHelper = data; + }); +} catch (err) { + console.error(`createDataShareHelper error: code: ${err.code}, message: ${err.message} `); +}; +``` + +## dataShare.createDataShareHelper10+ +createDataShareHelper(context: Context, uri: string, options: DataShareHelperOptions, callback: AsyncCallback<DataShareHelper>): void Creates a **DataShareHelper** instance. This API uses an asynchronous callback to return the result. Observe the following when using this API: - If an application running in the background needs to call this API to access **DataShareExtension**, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. - - If **visible** of the target **DataShareExtension** is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - If **exported** of the target **DataShareExtension** is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer -**Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ | | context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | | uri | string | Yes | Uniform Resource Identifier (URI) of the server application to connect. | +| options | [DataShareHelperOptions](#datasharehelperoptions10)| Yes | Configuration specifying whether [DataShareHelper](#datasharehelper) is in proxy mode.| | callback | AsyncCallback<[DataShareHelper](#datasharehelper)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the **DataShareHelper** instance created. Otherwise, **err** is an error object.| **Error codes** @@ -66,18 +93,18 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err | ID| Error Message | | -------- | ---------------------------------------------------- | -| 15700010 | The dataShareHelper is not initialized successfully. | +| 15700010 | The DataShareHelper is not initialized successfully. | **Example** ```ts import UIAbility from '@ohos.app.ability.UIAbility'; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); +let uri = ("datashareproxy://com.samples.datasharetest.DataShare"); let dataShareHelper; try { - dataShare.createDataShareHelper(this.context, uri, (err, data) => { - if (err != undefined) { + dataShare.createDataShareHelper(this.context, uri, {isProxy : true}, (err, data) => { + if (err !== undefined) { console.error(`createDataShareHelper error: code: ${err.code}, message: ${err.message} `); return; } @@ -88,16 +115,15 @@ try { console.error(`createDataShareHelper error: code: ${err.code}, message: ${err.message} `); }; ``` - ## dataShare.createDataShareHelper -createDataShareHelper(context: Context, uri: string): Promise<DataShareHelper> +createDataShareHelper(context: Context, uri: string, options?: DataShareHelperOptions): Promise<DataShareHelper> Creates a **DataShareHelper** instance. This API uses a promise to return the result. Observe the following when using this API: - If an application running in the background needs to call this API to access **DataShareExtension**, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. - - If **visible** of the target **DataShareExtension** is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - If **exported** of the target **DataShareExtension** is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -107,7 +133,8 @@ Observe the following when using this API: | Name | Type | Mandatory| Description | | ------- | ------------------------------------------------- | ---- | ------------------------------ | | context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | -| uri | string | Yes | URI of the server application to connect.| +| uri | string | Yes | Uniform Resource Identifier (URI) of the server application to connect.| +| options | [DataShareHelperOptions](#datasharehelperoptions10) | No| Optional configuration of the **DataShareHelper** instance. This parameter is supported from API version 10. If it is not set, [DataShareHelper](#datasharehelper) is not in proxy mode.| **Return value** @@ -121,17 +148,17 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err | ID| Error Message | | -------- | ---------------------------------------------------- | -| 15700010 | The dataShareHelper is not initialized successfully. | +| 15700010 | The DataShareHelper is not initialized successfully. | **Example** ```ts import UIAbility from '@ohos.app.ability.UIAbility'; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); +let uri = ("datashareproxy://com.samples.datasharetest.DataShare"); let dataShareHelper; try { - dataShare.createDataShareHelper(this.context, uri).then((data) => { + dataShare.createDataShareHelper(this.context, uri, {isProxy : true}).then((data) => { console.info("createDataShareHelper succeed, data : " + data); dataShareHelper = data; }). catch((err) => { @@ -142,6 +169,83 @@ try { }; ``` +## DataShareHelperOptions10+ + +Defines whether [DataShareHelper](#datasharehelper) is in proxy mode. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| isProxy | boolean | No| Whether the [DataShareHelper](#datasharehelper) is in proxy mode. The default value is **false**.
If the value is **true**, the [DataShareHelper](#datasharehelper) to be created is in proxy mode, and all operations will not open the data provider application unless the database does not exist. If the database does not exist, [createDataShareHelper] (#datasharecreatedatasharehelper10) will start the data provider to create a database.| + +## TemplateId10+ + +Defines the **TemplateId** struct. **TemplateId** is generated by [**addTemplate**](#addtemplate10) to identify a template. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| subscriberId | string | Yes| ID of the subscriber who handles the callback. The value must the same as the **subscriberId** in [**addTemplate**](#addtemplate10). The ID of each subscriber must be unique.| +| bundleNameOfOwner | string | Yes| Bundle name of the template owner. The value must be the same as the **bundleName** in [**addTemplate**](#addtemplate10).| + +## PublishedItem10+ + +Defines the type of the data to publish. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| key | string | Yes| Key of the data to publish.| +| data | string \| [Ashmem](js-apis-rpc.md#ashmem8) | Yes| Data to publish. If the data volume is large, use **Ashmem**.| +| subscriberId | string | Yes| Subscriber ID.| + +## RdbDataChangeNode10+ + +Defines the subscription/unsubscription result of the RDB data changes. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| uri | string | Yes| URI of the callback.| +| templateId | [TemplateId](#templateid10) | Yes| ID of the template that triggers the callback.| +| data | Array<string> | Yes| Data of the callback.| + +## PublishedDataChangeNode10+ + +Defines the subscription/unsubscription result of the changes in the published data. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| bundleName | string | Yes| Bundle name of the callback.| +| data | Array<[PublishedItem](#publisheditem10)> | Yes| Data of the callback.| + +## Template10+ + +Defines the struct of the template used in a subscription. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| predicates | { [key: string]: string } | Yes| Predicates to use. When [**on**](#onrdbdatachange10) is called, the predicates are used to generate data. This parameter applies only to RDB data storage. | +| scheduler | string | Yes| Template scheduler SQL, which is embedded with a custom function. Currently, the **remindTimer** function is embedded. The **remindTimer** triggers a subscription-based update in specified scenarios.
The scheduler SQL statement is triggered when:
1. The subscribed data is modified.
2. The first subscription is added to the corresponding database.| + +## OperationResult10+ + +Defines the result of the operation for subscribing to or unsubscribing from the data changes or published data. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +| Name| Type| Mandatory| Description| +| -------- | -------- | ----- | -------- | +| key | string | Yes| Key of the operation result.| +| result | number | Yes| Operation result. | ## DataShareHelper Provides a **DataShareHelper** instance to access or manage data on the server. Before calling an API provided by **DataShareHelper**, you must create a **DataShareHelper** instance using [createDataShareHelper](#datasharecreatedatasharehelper). @@ -165,8 +269,6 @@ Subscribes to changes of the specified data. After an observer is registered, th **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - function onCallback() { console.info("**** Observer on callback ****"); } @@ -178,7 +280,7 @@ dataShareHelper.on("dataChange", uri, onCallback); off(type: 'dataChange', uri: string, callback?: AsyncCallback<void>): void -Unsubscribes from the changes of the specified data. This API uses an asynchronous callback to return the result. +Unsubscribes from data changes. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -186,15 +288,13 @@ Unsubscribes from the changes of the specified data. This API uses an asynchrono | Name | Type | Mandatory| Description | | -------- | -------------------- | ---- | ------------------------ | -| type | string | Yes | Event type to unsubscribe from. The value is **dataChange**, which indicates data change events.| -| uri | string | Yes | URI of the data.| -| callback | AsyncCallback<void> | No | Callback for the data change event. If this parameter is left empty, all notification events of the URI are unsubscribed from.| +| type | string | Yes | Event or callback type to unsubscribe from. The value is **dataChange**, which indicates data change events.| +| uri | string | Yes | URI of the target data.| +| callback | AsyncCallback<void> | No | Callback for the data change event. If this parameter is left empty, all notification events of the URI will be unsubscribed from.| **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - function callback() { console.info("**** Observer callback ****"); } @@ -203,6 +303,437 @@ dataShareHelper.on("dataChange", uri, callback); dataShareHelper.off("dataChange", uri, callback); ``` +### addTemplate10+ + +addTemplate(uri: string, subscriberId: string, template: Template): void + +Adds a data template with the specified subscriber. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------| +| uri | string | Yes | URI of the data template to add. | +| subscriberId | string | Yes | Unique ID of the template subscriber.| +| template | [Template](#template10) | Yes | Data template to add. | + +**Error codes** + +For details about the error codes, see [DataShare Error Codes](../errorcodes/errorcode-datashare.md). + +| ID| Error Message | +| -------- | -------------------- | +| 15700011 | The uri is not exist.| + +**Example** + +```ts +let uri = ("datashareproxy://com.samples.datasharetest.DataShare"); +let subscriberId = '11'; +let template = { + predicates : { + "p1" : "select cityColumn as city_1, visitedCilumn as visited_1 from citys where like = true", + "p2" : "select cityColumn as city_2, visitedCilumn as visited_2 from citys where like = false", + }, + scheduler : "select remindTimer(time) from TBL00" +} +dataShareHelper.addTemplate(uri, subscriberId, template); +``` + +### delTemplate10+ + +delTemplate(uri: string, subscriberId: string): void + +Deletes a data template based on the specified subscriber. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------| ---- | ------------------------- | +| uri | string | Yes | URI of the data template to delete. | +| subscriberId | string | Yes | Unique ID of the subscriber. | + +**Error codes** + +For details about the error codes, see [DataShare Error Codes](../errorcodes/errorcode-datashare.md). + +| ID| Error Message | +| -------- | -------------------- | +| 15700011 | The uri is not exist.| + +**Example** + +```ts +let uri = ("datashareproxy://com.samples.datasharetest.DataShare"); +let subscriberId = '11'; +let template = { + predicates : { + "p1" : "select cityColumn as city_1, visitedCilumn as visited_1 from citys where like = true", + "p2" : "select cityColumn as city_2, visitedCilumn as visited_2 from citys where like = false", + }, + scheduler : "select remindTimer(time) from TBL00" +} +dataShareHelper.addTemplate(uri, subscriberId, template); +dataShareHelper.delTemplate(uri, subscriberId); +``` + +### on('rdbDataChange')10+ + +on(type: 'rdbDataChange', uris: Array<string>, templateId: TemplateId, callback: AsyncCallback<RdbDataChangeNode>): Array<OperationResult> + +Subscribes to the changes of the data corresponding to the specified URI and template. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------| ---- | ------------------------------------------------------------ | +| type | string | Yes | Type of the event to subscribe to. The value is **rdbDataChange**, which indicates the RDB data change event. | +| uris | Array<string> | Yes | URIs of the data to operate. | +| templateId | [TemplateId](#templateid10) | Yes | ID of the template that triggers the callback. | +| callback | AsyncCallback<[RdbDataChangeNode](#rdbdatachangenode10)> | Yes | Callback invoked to return the result when the specified data changes. The **err** is **undefined**, and **node** is the new data. Otherwise, this callback is not triggered or **err** is an error object. | + +**Return value** + +| Type | Description | +| ---------------- | ------------------------------------------------------------ | +| Array<[OperationResult](#operationresult10)> | Returns the operation result.| + +**Example** + +```ts +function onCallback(err, node:dataShare.RdbDataChangeNode) { + console.info("onCallback " + JSON.stringify(node.uri)); + console.info("onCallback " + JSON.stringify(node.templateId)); + console.info("onCallback " + node.data.length); + for (let i = 0; i < node.data.length; i++) { + console.info("onCallback " + typeof node.data[i] + " " + node.data[i]); + } +} + +let uri = ("datashareproxy://com.samples.datasharetest.DataShare"); +let templateId:dataShare.TemplateId = {subscriberId:"11", bundleNameOfOwner:"com.acts.ohos.data.datasharetest"}; +let result:Array = dataShareHelper.on("rdbDataChange", [uri], templateId, onCallback); +``` + +### off('rdbDataChange')10+ + +off(type: 'rdbDataChange', uris: Array<string>, templateId: TemplateId, callback?: AsyncCallback<RdbDataChangeNode>): Array<OperationResult> + +Unsubscribes from the changes of the data corresponding to the specified URI and template. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------------------------------- | ---- | ---------------------------------------------------------- | +| type | string | Yes | Type of the event to unsubscribe from. The value is **rdbDataChange**, which indicates the RDB data change event. | +| uris | Array<string> | Yes | URIs of the data to operate. | +| templateId | [TemplateId](#templateid10) | Yes | ID of the template that triggers the callback. | +| callback | AsyncCallback<[RdbDataChangeNode](#rdbdatachangenode10)> | No | Callback invoked to return the result. Callback for the data change event. If this parameter is left empty, all notification events of the URI will be unsubscribed from.| + +**Return value** + +| Type | Description | +| ---------------- | ------------------------------------------------------------ | +| Array<[OperationResult](#operationresult10)> | Returns the operation result.| + +**Example** + +```ts +let uri = ("datashareproxy://com.samples.datasharetest.DataShare"); +let templateId:dataShare.TemplateId = {subscriberId:"11", bundleNameOfOwner:"com.acts.ohos.data.datasharetest"}; +let result:Array = dataShareHelper.off("rdbDataChange", [uri], templateId); +``` + +### on('publishedDataChange')10+ + +on(type: 'publishedDataChange', uris: Array<string>, subscriberId: string, callback: AsyncCallback<PublishedDataChangeNode>): Array<OperationResult> + +Subscribes to the changes of the published data. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------| ---- | ------------------------------------------------------------ | +| type | string | Yes | Type of the event to subscribe to. The value is **publishedDataChange**, which indicates the event of published data changes.| +| uris | Array<string> | Yes | URIs of the data to operate. | +| subscriberId | string | Yes | Subscriber ID of the callback. | +| callback | AsyncCallback<[PublishedDataChangeNode](#publisheddatachangenode10)> | Yes | Callback invoked to return the result when the published data changes. The **err** is **undefined**, and **node** is the new data. Otherwise, this callback is not triggered or **err** is an error object. | + +**Return value** + +| Type | Description | +| ---------------- | ------------------------------------------------------------ | +| Array<[OperationResult](#operationresult10)> | Returns the operation result.| + +**Example** + +```ts +import rpc from '@ohos.rpc'; + +function onPublishCallback(err, node:dataShare.PublishedDataChangeNode) { + console.info("onPublishCallback node bundleName " + JSON.stringify(node.bundleName)); + console.info("onPublishCallback node data size" + node.data.length); + for (let i = 0; i < node.data.length; i++) { + console.info("onPublishCallback node " + typeof node.data[i].data); + if (typeof node.data[i].data != 'string') { + let ash:rpc.Ashmem = node.data[i].data; + ash.mapReadonlyAshmem(); + console.info("onPublishCallback " + JSON.stringify(ash.readAshmem(ash.getAshmemSize()/4, 0))); + ash.closeAshmem(); + } + console.info("onPublishCallback data " + i + " " + JSON.stringify(node.data[i])); + } +} +let uris:Array = ['city', 'datashareproxy://com.acts.ohos.data.datasharetest/appInfo', 'key2']; +let subscriberId = '11'; +let result: Array = dataShareHelper.on('publishedDataChange', uris, subscriberId, onPublishCallback); +``` + +### off('publishedDataChange')10+ + +off(type: 'publishedDataChange', uris: Array<string>, subscriberId: string, callback?: AsyncCallback<PublishedDataChangeNode>): Array<OperationResult> + +Unsubscribes from the changes of the published data. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------------------------------- | ---- | ---------------------------------------------------------- | +| type | string | Yes | Type of the event to unsubscribe from. The value is **publishedDataChange**, which indicates the event of published data changes.| +| uris | Array<string> | Yes | URIs of the data to operate. | +| subscriberId | string | Yes | Subscriber ID of the callback. | +| callback | AsyncCallback<[PublishedDataChangeNode](#publisheddatachangenode10)> | No | Callback invoked to return the result. Callback for the published data change event. If this parameter is left empty, all notification events of the URI will be unsubscribed from.| + +**Return value** + +| Type | Description | +| ---------------- | ------------------------------------------------------------ | +| Array<[OperationResult](#operationresult10)> | Returns the operation result.| + +**Example** + +```ts +function offCallback(err, node:dataShare.PublishedDataChangeNode) { + console.info("**** Observer off callback ****"); +} +let uris:Array = ["city", "datashareproxy://com.acts.ohos.data.datasharetest/appInfo", "key2"]; +let subscriberId = '11'; +let result: Array = dataShareHelper.off("publishedDataChange", uris, subscriberId, offCallback); +``` + +### publish10+ + +publish(data: Array<PublishedItem>, bundleName: string, version: number, callback: AsyncCallback<Array<OperationResult>>): void + +Publishes data to the database. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | -------------------------------------------------| ---- | ------------------- | +| data | Array<[PublishedItem](#publisheditem10)> | Yes | Data to publish. | +| bundleName | string | Yes | Application of the data to publish. This parameter is valid only for the private data published. Only the application can read the data. | +| version | number | Yes | Version of the data to publish. A larger value indicates a later data version. If the version of the data published is earlier than that of the data in the database, the data in the database will not be updated.| +| callback | AsyncCallback<Array<[OperationResult](#operationresult10)>> | Yes | Callback invoked to return the result. If data is published, **err** is **undefined**, and **result** is the data publish result. Otherwise, this callback will not be triggered or **err** is an error object. | + +**Error codes** + +For details about the error codes, see [DataShare Error Codes](../errorcodes/errorcode-datashare.md). + +| ID| Error Message | +| -------- | -------------------------- | +| 15700012 | The data area is not exist.| + +**Example** + +```ts +import rpc from '@ohos.rpc'; + +let ashmem = null; +let subscriberId = '11'; +let version = 1; +let data : Array = [ + {key:"city", subscriberId:"11", data:"xian"}, + {key:"datashareproxy://com.acts.ohos.data.datasharetest/appInfo", subscriberId:"11", data:"appinfo is just a test app"}, + {key:"empty", subscriberId:"11", data:"nobody sub"}]; +let nums:number[] = [1,2,3]; +function publishCallback(err, result: Array) { + console.info("publishCallback " + JSON.stringify(result)); + ashmem.closeAshmem(); +} +try { + ashmem = rpc.Ashmem.create("ashmem", (nums.length) * 4); + ashmem.mapReadWriteAshmem(); + ashmem.writeAshmem(nums, nums.length, 0); + data.push({ + "key" : "key2", + "data" : ashmem, + "subscriberId" : "11", + }); + console.info("data length is:", data.length); + dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); +} catch (e) { + console.error("publish error " + JSON.stringify(e)); +} +``` + +### publish10+ + +publish(data: Array<PublishedItem>, bundleName: string, callback: AsyncCallback<Array<OperationResult>>): void + +Publishes data to the database. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------- | ---- | ---------------------------------- | +| data | Array<[PublishedItem](#publisheditem10)> | Yes | Data to publish. | +| bundleName | string | Yes | Application of the data to publish. This parameter is valid only for the private data published. Only the application can read the data. | +| callback | AsyncCallback<Array<[OperationResult](#operationresult10)>> | Yes | Callback invoked to return the result. If data is published, **err** is **undefined**, and **result** is the data publish result. Otherwise, this callback will not be triggered or **err** is an error object.| + +**Example** + +**Error codes** + +For details about the error codes, see [DataShare Error Codes](../errorcodes/errorcode-datashare.md). + +| ID| Error Message | +| -------- | -------------------------- | +| 15700012 | The data area is not exist.| + +```ts +function publishCallback(err, result: Array) { + console.info("publishCallback " + JSON.stringify(result)); +} +let data : Array = [ + {key:"city", subscriberId:"11", data:"xian"}, + {key:"datashareproxy://com.acts.ohos.data.datasharetest/appInfo", subscriberId:"11", data:"appinfo is just a test app"}, + {key:"empty", subscriberId:"11", data:"nobody sub"}]; +dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", publishCallback); +``` + +### publish10+ + +publish(data: Array<PublishedItem>, bundleName: string, version?: number): Promise<Array<OperationResult>> + +Publishes data to the database. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------- | ---- | ------------------------------ | +| data | Array<[PublishedItem](#publisheditem10)> | Yes | Data to publish.| +| bundleName | string | Yes | Application of the data to publish. This parameter is valid only for the private data published. Only the application can read the data. | +| version | number | No | Version of the data to publish. A larger value indicates a later data version. If the version of the data published is earlier than that of the data in the database, the data in the database will not be updated.
If the data version is not checked, leave this parameter unspecified.| + +**Return value** + +| Type | Description | +| ---------------- | ------------------------------------------------------------ | +| Promise<Array<[OperationResult](#operationresult10)>> | Returns the operation result.| + +**Error codes** + +For details about the error codes, see [DataShare Error Codes](../errorcodes/errorcode-datashare.md). + +| ID| Error Message | +| -------- | -------------------------- | +| 15700012 | The data area is not exist.| + +**Example** + +```ts +let data : Array = [ + {key:"city", subscriberId:"11", data:"xian"}, + {key:"datashareproxy://com.acts.ohos.data.datasharetest/appInfo", subscriberId:"11", data:"appinfo is just a test app"}, + {key:"empty", subscriberId:"11", data:"nobody sub"}]; +let result: Array = dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest"); +``` + +### getPublishedData10+ + +getPublishedData(bundleName: string, callback: AsyncCallback<Array<PublishedItem>>): void + +Obtains the published data of an application. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -----------------| ---- | ----------------------------- | +| bundleName | string | Yes | Application to which the data belongs. | +| callback | AsyncCallback<Array<[PublishedItem](#publisheditem10)>> | Yes | Callback invoked to return the result.| + +**Error codes** + +For details about the error codes, see [DataShare Error Codes](../errorcodes/errorcode-datashare.md). + +| ID| Error Message | +| -------- | -------------------------- | +| 15700012 | The data area is not exist.| + +**Example** + +```ts +function publishCallback(err, data: Array) { + console.info("**** Observer publish callback ****"); +} +dataShareHelper.getPublishedData("com.acts.ohos.data.datasharetest", publishCallback); +``` + +### getPublishedData10+ + +getPublishedData(bundleName: string): Promise<Array<PublishedItem>> + +Obtains the published data of an application. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------| ---- | -------------------------------------- | +| bundleName | string | Yes | Application to which the data belongs. | + +**Return value** + +| Type | Description | +| ---------------- | ------------------------------------------------------------ | +| Promise<Array<[PublishedItem](#publisheditem10)>> | Promise used to return the data obtained.| + +**Error codes** + +For details about the error codes, see [DataShare Error Codes](../errorcodes/errorcode-datashare.md). + +| ID| Error Message | +| -------- | -------------------------- | +| 15700012 | The data area is not exist.| + +**Example** + +```ts +let publishedData:Array = dataShareHelper.getPublishedData("com.acts.ohos.data.datasharetest"); +``` + ### insert insert(uri: string, value: ValuesBucket, callback: AsyncCallback<number>): void @@ -222,8 +753,6 @@ Inserts a single data record into the database. This API uses an asynchronous ca **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); const valueBucket = { "name": "rose", @@ -232,7 +761,7 @@ const valueBucket = { } try { dataShareHelper.insert(uri, valueBucket, (err, data) => { - if (err != undefined) { + if (err !== undefined) { console.error(`insert error: code: ${err.code}, message: ${err.message} `); return; } @@ -267,8 +796,6 @@ Inserts a single data record into the database. This API uses a promise to retur **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); const valueBucket = { "name": "rose1", @@ -277,7 +804,7 @@ const valueBucket = { } try { dataShareHelper.insert(uri, valueBucket).then((data) => { - console.log("insert succeed, data : " + data); + console.info("insert succeed, data : " + data); }). catch((err) => { console.error(`insert error: code: ${err.code}, message: ${err.message} `); }); @@ -305,7 +832,6 @@ Deletes one or more data records from the database. This API uses an asynchronou **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; let uri = ("datashare:///com.samples.datasharetest.DataShare"); @@ -313,7 +839,7 @@ let da = new dataSharePredicates.DataSharePredicates(); da.equalTo("name", "ZhangSan"); try { dataShareHelper.delete(uri, da, (err, data) => { - if (err != undefined) { + if (err !== undefined) { console.error(`delete error: code: ${err.code}, message: ${err.message} `); return; } @@ -348,7 +874,6 @@ Deletes one or more data records from the database. This API uses a promise to r **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; let uri = ("datashare:///com.samples.datasharetest.DataShare"); @@ -356,7 +881,7 @@ let da = new dataSharePredicates.DataSharePredicates(); da.equalTo("name", "ZhangSan"); try { dataShareHelper.delete(uri, da).then((data) => { - console.log("delete succeed, data : " + data); + console.info("delete succeed, data : " + data); }). catch((err) => { console.error(`delete error: code: ${err.code}, message: ${err.message} `); }); @@ -385,7 +910,6 @@ Queries data in the database. This API uses an asynchronous callback to return t **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; let uri = ("datashare:///com.samples.datasharetest.DataShare"); @@ -394,11 +918,11 @@ let da = new dataSharePredicates.DataSharePredicates(); da.equalTo("name", "ZhangSan"); try { dataShareHelper.query(uri, da, columns, (err, data) => { - if (err != undefined) { + if (err !== undefined) { console.error(`query error: code: ${err.code}, message: ${err.message} `); return; } - console.log("query succeed, rowCount : " + data.rowCount); + console.info("query succeed, rowCount : " + data.rowCount); }); } catch (err) { console.error(`query error: code: ${err.code}, message: ${err.message} `); @@ -430,7 +954,6 @@ Queries data in the database. This API uses a promise to return the result. **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; let uri = ("datashare:///com.samples.datasharetest.DataShare"); @@ -439,7 +962,7 @@ let da = new dataSharePredicates.DataSharePredicates(); da.equalTo("name", "ZhangSan"); try { dataShareHelper.query(uri, da, columns).then((data) => { - console.log("query succeed, rowCount : " + data.rowCount); + console.info("query succeed, rowCount : " + data.rowCount); }). catch((err) => { console.error(`query error: code: ${err.code}, message: ${err.message} `); }); @@ -468,7 +991,6 @@ Updates data in the database. This API uses an asynchronous callback to return t **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; let uri = ("datashare:///com.samples.datasharetest.DataShare"); @@ -482,11 +1004,11 @@ const va = { } try { dataShareHelper.update(uri, da, va, (err, data) => { - if (err != undefined) { + if (err !== undefined) { console.error(`update error: code: ${err.code}, message: ${err.message} `); return; } - console.log("update succeed, data : " + data); + console.info("update succeed, data : " + data); }); } catch (err) { console.error(`update error: code: ${err.code}, message: ${err.message} `); @@ -518,7 +1040,6 @@ Updates data in the database. This API uses a promise to return the result. **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; let uri = ("datashare:///com.samples.datasharetest.DataShare"); @@ -532,7 +1053,7 @@ const va = { } try { dataShareHelper.update(uri, da, va).then((data) => { - console.log("update succeed, data : " + data); + console.info("update succeed, data : " + data); }). catch((err) => { console.error(`update error: code: ${err.code}, message: ${err.message} `); }); @@ -560,19 +1081,17 @@ Batch inserts data into the database. This API uses an asynchronous callback to **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, {"name": "roe12", "age": 21, "salary": 20.5,}, {"name": "roe13", "age": 21, "salary": 20.5,}) try { dataShareHelper.batchInsert(uri, vbs, (err, data) => { - if (err != undefined) { + if (err !== undefined) { console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); return; } - console.log("batchInsert succeed, data : " + data); + console.info("batchInsert succeed, data : " + data); }); } catch (err) { console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); @@ -603,15 +1122,13 @@ Batch inserts data into the database. This API uses a promise to return the resu **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, {"name": "roe12", "age": 21, "salary": 20.5,}, {"name": "roe13", "age": 21, "salary": 20.5,}) try { dataShareHelper.batchInsert(uri, vbs).then((data) => { - console.log("batchInsert succeed, data : " + data); + console.info("batchInsert succeed, data : " + data); }). catch((err) => { console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); }); @@ -638,14 +1155,12 @@ Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the lo **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.normalizeUri(uri, (err, data) => { - if (err != undefined) { - console.log("normalizeUri failed, error message : " + err); + if (err !== undefined) { + console.info("normalizeUri failed, error message : " + err); }else{ - console.log("normalizeUri = " + data); + console.info("normalizeUri = " + data); } }); ``` @@ -673,13 +1188,11 @@ Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the lo **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.normalizeUri(uri).then((data) => { - console.log("normalizeUri = " + data); + console.info("normalizeUri = " + data); }).catch((err) => { - console.log("normalizeUri failed, error message : " + err); + console.info("normalizeUri failed, error message : " + err); }); ``` @@ -701,14 +1214,12 @@ Denormalizes a URI. This API uses an asynchronous callback to return the result. **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.denormalizeUri(uri, (err, data) => { - if (err != undefined) { - console.log("denormalizeUri failed, error message : " + err); + if (err !== undefined) { + console.error("denormalizeUri failed, error message : " + err); }else{ - console.log("denormalizeUri = " + data); + console.info("denormalizeUri = " + data); } }); ``` @@ -736,13 +1247,11 @@ Denormalizes a URI. This API uses a promise to return the result. **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.denormalizeUri(uri).then((data) => { - console.log("denormalizeUri = " + data); + console.info("denormalizeUri = " + data); }).catch((err) => { - console.log("denormalizeUri failed, error message : " + err); + console.error("denormalizeUri failed, error message : " + err); }); ``` @@ -764,11 +1273,9 @@ Notifies the registered observer of data changes. This API uses an asynchronous **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.notifyChange(uri, () => { - console.log("***** notifyChange *****"); + console.info("***** notifyChange *****"); }); ``` @@ -795,8 +1302,6 @@ Notifies the registered observer of data changes. This API uses a promise to ret **Example** ```ts -import UIAbility from '@ohos.app.ability.UIAbility'; - let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.notifyChange(uri); ``` diff --git a/en/application-dev/reference/apis/js-apis-data-dataSharePredicates.md b/en/application-dev/reference/apis/js-apis-data-dataSharePredicates.md index 6f63bb98574f0499ea47acb1f9ff0e04fff65f34..22acad67b553e5bcc9b216cffaeae28663c9f23a 100644 --- a/en/application-dev/reference/apis/js-apis-data-dataSharePredicates.md +++ b/en/application-dev/reference/apis/js-apis-data-dataSharePredicates.md @@ -7,8 +7,7 @@ The APIs provided by **DataSharePredicates** correspond to the filter criteria > **NOTE** > > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> -> The APIs provided by this module are system APIs. + ## Modules to Import @@ -20,7 +19,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates'; ## DataSharePredicates Provides methods for setting different **DataSharePredicates** objects. This type is not multi-thread safe. If a **DataSharePredicates** instance is operated by multiple threads at the same time in an application, use a lock for the instance. -### equalTo +### equalTo10+ equalTo(field: string, value: ValueType): DataSharePredicates @@ -59,6 +58,7 @@ Sets a **DataSharePredicates** object to match the data that is not equal to the Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -90,6 +90,7 @@ Adds a left parenthesis to this **DataSharePredicates**. Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** @@ -119,6 +120,7 @@ Adds a right parenthesis to this **DataSharePredicates** object. Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** @@ -148,6 +150,7 @@ Adds the OR condition to this **DataSharePredicates** object. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** @@ -165,7 +168,7 @@ predicates.equalTo("NAME", "lisi") .equalTo("NAME", "Rose") ``` -### and +### and10+ and(): DataSharePredicates @@ -199,6 +202,7 @@ Sets a **DataSharePredicates** object to match the data that contains the specif Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -230,6 +234,7 @@ Sets a **DataSharePredicates** object to match the data that begins with the spe Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -261,6 +266,7 @@ Sets a **DataSharePredicates** object to match the data that ends with the speci Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -292,6 +298,7 @@ Sets a **DataSharePredicates** object to match the data whose value is null. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -322,6 +329,7 @@ Sets a **DataSharePredicates** object to match the data whose value is not null. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -352,6 +360,7 @@ Sets a **DataSharePredicates** object to match the data that matches the specifi Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -383,6 +392,7 @@ Sets a **DataSharePredicates** object to match the data that does not match the Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -414,6 +424,7 @@ Sets a **DataSharePredicates** object to match the data that matches the specifi Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -445,6 +456,7 @@ Sets a **DataSharePredicates** object to match the data that is within the speci Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -477,6 +489,7 @@ Sets a **DataSharePredicates** object to match the data that is out of the speci Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -509,6 +522,7 @@ Sets a **DataSharePredicates** object to match the data that is greater than the Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -540,6 +554,7 @@ Sets a **DataSharePredicates** object to match the data that is less than the sp Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -571,6 +586,7 @@ Sets a **DataSharePredicates** object to match the data that is greater than or Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -602,6 +618,7 @@ Sets a **DataSharePredicates** object to match the data that is less than or equ Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -624,7 +641,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() predicates.lessThanOrEqualTo("AGE", 50) ``` -### orderByAsc +### orderByAsc10+ orderByAsc(field: string): DataSharePredicates @@ -653,7 +670,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() predicates.orderByAsc("AGE") ``` -### orderByDesc +### orderByDesc10+ orderByDesc(field: string): DataSharePredicates @@ -691,6 +708,7 @@ Sets a **DataSharePredicates** object to filter out duplicate data records. Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Return value** @@ -706,7 +724,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() predicates.equalTo("NAME", "Rose").distinct() ``` -### limit +### limit10+ limit(total: number, offset: number): DataSharePredicates @@ -745,6 +763,7 @@ Sets a **DataSharePredicates** object group the records according to the specifi Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -775,6 +794,7 @@ Sets a **DataSharePredicates** object to list data by the specified index. Currently, only the RDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -796,7 +816,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() predicates.indexedBy("SALARY_INDEX") ``` -### in +### in10+ in(field: string, value: Array<ValueType>): DataSharePredicates @@ -835,6 +855,7 @@ Sets a **DataSharePredicates** object to match the data that is not in the speci Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -866,6 +887,7 @@ Sets a **DataSharePredicates** object to match the data with the specified key p Currently, only the KVDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** @@ -896,6 +918,7 @@ Sets a **DataSharePredicates** object to match the data whose keys are within th Currently, only the KVDB supports this **DataSharePredicates** object. **System API**: This is a system API. + **System capability**: SystemCapability.DistributedDataManager.DataShare.Core **Parameters** diff --git a/en/application-dev/reference/apis/js-apis-data-valuesBucket.md b/en/application-dev/reference/apis/js-apis-data-valuesBucket.md index ee21647ac71dacf7afa8240d2aa93e2ea65967f4..76ea731994e13d3ecf1f49d25db249666992434c 100644 --- a/en/application-dev/reference/apis/js-apis-data-valuesBucket.md +++ b/en/application-dev/reference/apis/js-apis-data-valuesBucket.md @@ -4,8 +4,7 @@ The **ValueBucket** module holds data in key-value (KV) pairs. You can use it to > **NOTE** > -> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> +> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import