提交 eab662fa 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 05cd3ae9
...@@ -17,26 +17,6 @@ The **DataShareExtensionAbility** module provides data share services based on t ...@@ -17,26 +17,6 @@ The **DataShareExtensionAbility** module provides data share services based on t
import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility'; 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:<br>**datashare:///com.samples.datasharetest.DataShare**
- URI with the resource path:<br>**datashare:///com.samples.datasharetest.DataShare/DB00/TBL00**
**com.samples.datasharetest.DataShare** is the data share identifier, and **DB00/TBL00** is the resource path.
## Attributes ## Attributes
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider **System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
...@@ -57,7 +37,7 @@ Called by the server to initialize service logic when the DataShare client conne ...@@ -57,7 +37,7 @@ Called by the server to initialize service logic when the DataShare client conne
| Name| Type| Mandatory| Description| | 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&lt;void&gt; | Yes| Callback that returns no value.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback that returns no value.|
**Example** **Example**
...@@ -78,10 +58,10 @@ export default class DataShareExtAbility extends DataShareExtensionAbility { ...@@ -78,10 +58,10 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
name: DB_NAME, name: DB_NAME,
securityLevel: rdb.SecurityLevel.S1 securityLevel: rdb.SecurityLevel.S1
}, function (err, data) { }, function (err, data) {
console.log('getRdbStore done, data : ${data}'); console.info(`getRdbStore done, data : ${data}`);
rdbStore = data; rdbStore = data;
rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) {
console.error('executeSql done, error message : ${err}'); console.error(`executeSql done, error message : ${err}`);
}); });
if (callback) { if (callback) {
callback(); callback();
...@@ -122,11 +102,11 @@ let rdbStore; ...@@ -122,11 +102,11 @@ let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
insert(uri, valueBucket, callback) { insert(uri, valueBucket, callback) {
if (valueBucket === null) { if (valueBucket === null) {
console.info('invalid valueBuckets'); console.error('invalid valueBuckets');
return; return;
} }
rdbStore.insert(TBL_NAME, valueBucket, function (err, ret) { rdbStore.insert(TBL_NAME, valueBucket, function (err, ret) {
console.info('callback ret: ${ret}'); console.info(`callback ret: ${ret}`);
if (callback !== undefined) { if (callback !== undefined) {
callback(err, ret); callback(err, ret);
} }
...@@ -256,7 +236,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility { ...@@ -256,7 +236,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
} }
rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) { rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) {
if (resultSet !== undefined) { if (resultSet !== undefined) {
console.info('resultSet.rowCount: ${resultSet.rowCount}'); console.info(`resultSet.rowCount: ${resultSet.rowCount}`);
} }
if (callback !== undefined) { if (callback !== undefined) {
callback(err, resultSet); callback(err, resultSet);
...@@ -297,14 +277,12 @@ let rdbStore; ...@@ -297,14 +277,12 @@ let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
batchInsert(uri, valueBuckets, callback) { batchInsert(uri, valueBuckets, callback) {
if (valueBuckets === null || valueBuckets.length === undefined) { if (valueBuckets === null || valueBuckets.length === undefined) {
console.info('invalid valueBuckets'); console.error('invalid valueBuckets');
return; return;
} }
let resultNum = valueBuckets.length; rdbStore.batchInsert(TBL_NAME, valueBuckets, function (err, ret) {
valueBuckets.forEach(vb => {
rdbStore.insert(TBL_NAME, vb, function (err, ret) {
if (callback !== undefined) { if (callback !== undefined) {
callback(err, resultNum); callback(err, ret);
} }
}); });
}); });
...@@ -333,7 +311,7 @@ Normalizes a URI. This API can be overridden as required. ...@@ -333,7 +311,7 @@ Normalizes a URI. This API can be overridden as required.
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
normalizeUri(uri, callback) { normalizeUri(uri, callback) {
let err = {'code':0}; let err = {'code':0};
let ret = 'normalize+${uri}'; let ret = `normalize: ${uri}`;
callback(err, ret); callback(err, ret);
} }
}; };
...@@ -360,7 +338,7 @@ Denormalizes a URI. This API can be overridden as required. ...@@ -360,7 +338,7 @@ Denormalizes a URI. This API can be overridden as required.
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
denormalizeUri(uri, callback) { denormalizeUri(uri, callback) {
let err = {'code':0}; let err = {'code':0};
let ret = 'denormalize+${uri}'; let ret = `denormalize ${uri}`;
callback(err, ret); callback(err, ret);
} }
}; };
......
...@@ -27,7 +27,7 @@ let dataShareHelper; ...@@ -27,7 +27,7 @@ let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
await dataShare.createDataShareHelper(this.context, uri, (err, data) => { await dataShare.createDataShareHelper(this.context, uri, (err, data) => {
if (err != undefined) { if (err != undefined) {
console.info("createDataShareHelper fail, error message : " + err); console.error("createDataShareHelper fail, error message : " + err);
} else { } else {
console.info("createDataShareHelper end, data : " + data); console.info("createDataShareHelper end, data : " + data);
dataShareHelper = data; dataShareHelper = data;
...@@ -39,10 +39,10 @@ let da = new dataSharePredicates.DataSharePredicates(); ...@@ -39,10 +39,10 @@ let da = new dataSharePredicates.DataSharePredicates();
let resultSet; let resultSet;
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
dataShareHelper.query(uri, da, columns).then((data) => { dataShareHelper.query(uri, da, columns).then((data) => {
console.log("query end, data : " + data); console.info("query end, data : " + data);
resultSet = data; resultSet = data;
}).catch((err) => { }).catch((err) => {
console.log("query fail, error message : " + err); console.error("query fail, error message : " + err);
}); });
``` ```
......
...@@ -4,12 +4,11 @@ The **DataShare** module allows an application to manage its own data and share ...@@ -4,12 +4,11 @@ The **DataShare** module allows an application to manage its own data and share
> **NOTE** > **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 ## Modules to Import
...@@ -18,46 +17,74 @@ The **DataShare** module allows an application to manage its own data and share ...@@ -18,46 +17,74 @@ The **DataShare** module allows an application to manage its own data and share
import dataShare from '@ohos.data.dataShare' 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&lt;DataShareHelper&gt;): void
**Scheme://authority/path** Creates a **DataShareHelper** instance. This API uses an asynchronous callback to return the result.
- *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: 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:<br>**datashare:///com.samples.datasharetest.DataShare** **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
- URI with the resource path:<br>**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&lt;[DataShareHelper](#datasharehelper)&gt; | 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&lt;DataShareHelper&gt;): 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.createDataShareHelper<sup>10+</sup>
createDataShareHelper(context: Context, uri: string, options: DataShareHelperOptions, callback: AsyncCallback&lt;DataShareHelper&gt;): void
Creates a **DataShareHelper** instance. This API uses an asynchronous callback to return the result. Creates a **DataShareHelper** instance. This API uses an asynchronous callback to return the result.
Observe the following when using this API: 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 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). - 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 **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
**Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | | 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. | | 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&lt;[DataShareHelper](#datasharehelper)&gt; | 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.| | callback | AsyncCallback&lt;[DataShareHelper](#datasharehelper)&gt; | 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** **Error codes**
...@@ -66,18 +93,18 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err ...@@ -66,18 +93,18 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err
| ID| Error Message | | ID| Error Message |
| -------- | ---------------------------------------------------- | | -------- | ---------------------------------------------------- |
| 15700010 | The dataShareHelper is not initialized successfully. | | 15700010 | The DataShareHelper is not initialized successfully. |
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashareproxy://com.samples.datasharetest.DataShare");
let dataShareHelper; let dataShareHelper;
try { try {
dataShare.createDataShareHelper(this.context, uri, (err, data) => { dataShare.createDataShareHelper(this.context, uri, {isProxy : true}, (err, data) => {
if (err != undefined) { if (err !== undefined) {
console.error(`createDataShareHelper error: code: ${err.code}, message: ${err.message} `); console.error(`createDataShareHelper error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
...@@ -88,16 +115,15 @@ try { ...@@ -88,16 +115,15 @@ try {
console.error(`createDataShareHelper error: code: ${err.code}, message: ${err.message} `); console.error(`createDataShareHelper error: code: ${err.code}, message: ${err.message} `);
}; };
``` ```
## dataShare.createDataShareHelper ## dataShare.createDataShareHelper
createDataShareHelper(context: Context, uri: string): Promise&lt;DataShareHelper&gt; createDataShareHelper(context: Context, uri: string, options?: DataShareHelperOptions): Promise&lt;DataShareHelper&gt;
Creates a **DataShareHelper** instance. This API uses a promise to return the result. Creates a **DataShareHelper** instance. This API uses a promise to return the result.
Observe the following when using this API: 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 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). - 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 **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
...@@ -107,7 +133,8 @@ Observe the following when using this API: ...@@ -107,7 +133,8 @@ Observe the following when using this API:
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------------------- | ---- | ------------------------------ | | ------- | ------------------------------------------------- | ---- | ------------------------------ |
| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | | 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** **Return value**
...@@ -121,17 +148,17 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err ...@@ -121,17 +148,17 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err
| ID| Error Message | | ID| Error Message |
| -------- | ---------------------------------------------------- | | -------- | ---------------------------------------------------- |
| 15700010 | The dataShareHelper is not initialized successfully. | | 15700010 | The DataShareHelper is not initialized successfully. |
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashareproxy://com.samples.datasharetest.DataShare");
let dataShareHelper; let dataShareHelper;
try { try {
dataShare.createDataShareHelper(this.context, uri).then((data) => { dataShare.createDataShareHelper(this.context, uri, {isProxy : true}).then((data) => {
console.info("createDataShareHelper succeed, data : " + data); console.info("createDataShareHelper succeed, data : " + data);
dataShareHelper = data; dataShareHelper = data;
}). catch((err) => { }). catch((err) => {
...@@ -142,6 +169,83 @@ try { ...@@ -142,6 +169,83 @@ try {
}; };
``` ```
## DataShareHelperOptions<sup>10+</sup>
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**.<br>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.|
## TemplateId<sup>10+</sup>
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).|
## PublishedItem<sup>10+</sup>
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.|
## RdbDataChangeNode<sup>10+</sup>
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&lt;string&gt; | Yes| Data of the callback.|
## PublishedDataChangeNode<sup>10+</sup>
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&lt;[PublishedItem](#publisheditem10)&gt; | Yes| Data of the callback.|
## Template<sup>10+</sup>
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.<br>The scheduler SQL statement is triggered when:<br>1. The subscribed data is modified.<br>2. The first subscription is added to the corresponding database.|
## OperationResult<sup>10+</sup>
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 ## 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). 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 ...@@ -165,8 +269,6 @@ Subscribes to changes of the specified data. After an observer is registered, th
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
function onCallback() { function onCallback() {
console.info("**** Observer on callback ****"); console.info("**** Observer on callback ****");
} }
...@@ -178,7 +280,7 @@ dataShareHelper.on("dataChange", uri, onCallback); ...@@ -178,7 +280,7 @@ dataShareHelper.on("dataChange", uri, onCallback);
off(type: 'dataChange', uri: string, callback?: AsyncCallback&lt;void&gt;): void off(type: 'dataChange', uri: string, callback?: AsyncCallback&lt;void&gt;): 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 **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
...@@ -186,15 +288,13 @@ Unsubscribes from the changes of the specified data. This API uses an asynchrono ...@@ -186,15 +288,13 @@ Unsubscribes from the changes of the specified data. This API uses an asynchrono
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------------ |
| type | string | Yes | Event type to unsubscribe from. The value is **dataChange**, which indicates data change events.| | 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 data.| | uri | string | Yes | URI of the target data.|
| callback | AsyncCallback&lt;void&gt; | No | Callback for the data change event. If this parameter is left empty, all notification events of the URI are unsubscribed from.| | callback | AsyncCallback&lt;void&gt; | No | Callback for the data change event. If this parameter is left empty, all notification events of the URI will be unsubscribed from.|
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
function callback() { function callback() {
console.info("**** Observer callback ****"); console.info("**** Observer callback ****");
} }
...@@ -203,6 +303,437 @@ dataShareHelper.on("dataChange", uri, callback); ...@@ -203,6 +303,437 @@ dataShareHelper.on("dataChange", uri, callback);
dataShareHelper.off("dataChange", uri, callback); dataShareHelper.off("dataChange", uri, callback);
``` ```
### addTemplate<sup>10+</sup>
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);
```
### delTemplate<sup>10+</sup>
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')<sup>10+</sup>
on(type: 'rdbDataChange', uris: Array&lt;string&gt;, templateId: TemplateId, callback: AsyncCallback&lt;RdbDataChangeNode&gt;): Array&lt;OperationResult&gt;
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&lt;string&gt; | Yes | URIs of the data to operate. |
| templateId | [TemplateId](#templateid10) | Yes | ID of the template that triggers the callback. |
| callback | AsyncCallback&lt;[RdbDataChangeNode](#rdbdatachangenode10)&gt; | 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&lt;[OperationResult](#operationresult10)&gt; | 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<dataShare.OperationResult> = dataShareHelper.on("rdbDataChange", [uri], templateId, onCallback);
```
### off('rdbDataChange')<sup>10+</sup>
off(type: 'rdbDataChange', uris: Array&lt;string&gt;, templateId: TemplateId, callback?: AsyncCallback&lt;RdbDataChangeNode&gt;): Array&lt;OperationResult&gt;
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&lt;string&gt; | Yes | URIs of the data to operate. |
| templateId | [TemplateId](#templateid10) | Yes | ID of the template that triggers the callback. |
| callback | AsyncCallback&lt;[RdbDataChangeNode](#rdbdatachangenode10)&gt; | 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&lt;[OperationResult](#operationresult10)&gt; | 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<dataShare.OperationResult> = dataShareHelper.off("rdbDataChange", [uri], templateId);
```
### on('publishedDataChange')<sup>10+</sup>
on(type: 'publishedDataChange', uris: Array&lt;string&gt;, subscriberId: string, callback: AsyncCallback&lt;PublishedDataChangeNode&gt;): Array&lt;OperationResult&gt;
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&lt;string&gt; | Yes | URIs of the data to operate. |
| subscriberId | string | Yes | Subscriber ID of the callback. |
| callback | AsyncCallback&lt;[PublishedDataChangeNode](#publisheddatachangenode10)&gt; | 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&lt;[OperationResult](#operationresult10)&gt; | 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<string> = ['city', 'datashareproxy://com.acts.ohos.data.datasharetest/appInfo', 'key2'];
let subscriberId = '11';
let result: Array<dataShare.OperationResult> = dataShareHelper.on('publishedDataChange', uris, subscriberId, onPublishCallback);
```
### off('publishedDataChange')<sup>10+</sup>
off(type: 'publishedDataChange', uris: Array&lt;string&gt;, subscriberId: string, callback?: AsyncCallback&lt;PublishedDataChangeNode&gt;): Array&lt;OperationResult&gt;
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&lt;string&gt; | Yes | URIs of the data to operate. |
| subscriberId | string | Yes | Subscriber ID of the callback. |
| callback | AsyncCallback&lt;[PublishedDataChangeNode](#publisheddatachangenode10)&gt; | 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&lt;[OperationResult](#operationresult10)&gt; | Returns the operation result.|
**Example**
```ts
function offCallback(err, node:dataShare.PublishedDataChangeNode) {
console.info("**** Observer off callback ****");
}
let uris:Array<string> = ["city", "datashareproxy://com.acts.ohos.data.datasharetest/appInfo", "key2"];
let subscriberId = '11';
let result: Array<dataShare.OperationResult> = dataShareHelper.off("publishedDataChange", uris, subscriberId, offCallback);
```
### publish<sup>10+</sup>
publish(data: Array&lt;PublishedItem&gt;, bundleName: string, version: number, callback: AsyncCallback&lt;Array&lt;OperationResult&gt;&gt;): void
Publishes data to the database.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | -------------------------------------------------| ---- | ------------------- |
| data | Array&lt;[PublishedItem](#publisheditem10)&gt; | 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&lt;Array&lt;[OperationResult](#operationresult10)&gt;&gt; | 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<dataShare.PublishedItem> = [
{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<dataShare.OperationResult>) {
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));
}
```
### publish<sup>10+</sup>
publish(data: Array&lt;PublishedItem&gt;, bundleName: string, callback: AsyncCallback&lt;Array&lt;OperationResult&gt;&gt;): void
Publishes data to the database.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ---------------------------------- |
| data | Array&lt;[PublishedItem](#publisheditem10)&gt; | 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&lt;Array&lt;[OperationResult](#operationresult10)&gt;&gt; | 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<dataShare.OperationResult>) {
console.info("publishCallback " + JSON.stringify(result));
}
let data : Array<dataShare.PublishedItem> = [
{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);
```
### publish<sup>10+</sup>
publish(data: Array&lt;PublishedItem&gt;, bundleName: string, version?: number): Promise&lt;Array&lt;OperationResult&gt;&gt;
Publishes data to the database.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ------------------------------ |
| data | Array&lt;[PublishedItem](#publisheditem10)&gt; | 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.<br> If the data version is not checked, leave this parameter unspecified.|
**Return value**
| Type | Description |
| ---------------- | ------------------------------------------------------------ |
| Promise&lt;Array&lt;[OperationResult](#operationresult10)&gt;&gt; | 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<dataShare.PublishedItem> = [
{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<dataShare.OperationResult> = dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest");
```
### getPublishedData<sup>10+</sup>
getPublishedData(bundleName: string, callback: AsyncCallback&lt;Array&lt;PublishedItem&gt;&gt;): 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&lt;Array&lt;[PublishedItem](#publisheditem10)&gt;&gt; | 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<dataShare.PublishedItem>) {
console.info("**** Observer publish callback ****");
}
dataShareHelper.getPublishedData("com.acts.ohos.data.datasharetest", publishCallback);
```
### getPublishedData<sup>10+</sup>
getPublishedData(bundleName: string): Promise&lt;Array&lt;PublishedItem&gt;&gt;
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&lt;Array&lt;[PublishedItem](#publisheditem10)&gt;&gt; | 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<dataShare.PublishedItem> = dataShareHelper.getPublishedData("com.acts.ohos.data.datasharetest");
```
### insert ### insert
insert(uri: string, value: ValuesBucket, callback: AsyncCallback&lt;number&gt;): void insert(uri: string, value: ValuesBucket, callback: AsyncCallback&lt;number&gt;): void
...@@ -222,8 +753,6 @@ Inserts a single data record into the database. This API uses an asynchronous ca ...@@ -222,8 +753,6 @@ Inserts a single data record into the database. This API uses an asynchronous ca
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
const valueBucket = { const valueBucket = {
"name": "rose", "name": "rose",
...@@ -232,7 +761,7 @@ const valueBucket = { ...@@ -232,7 +761,7 @@ const valueBucket = {
} }
try { try {
dataShareHelper.insert(uri, valueBucket, (err, data) => { dataShareHelper.insert(uri, valueBucket, (err, data) => {
if (err != undefined) { if (err !== undefined) {
console.error(`insert error: code: ${err.code}, message: ${err.message} `); console.error(`insert error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
...@@ -267,8 +796,6 @@ Inserts a single data record into the database. This API uses a promise to retur ...@@ -267,8 +796,6 @@ Inserts a single data record into the database. This API uses a promise to retur
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
const valueBucket = { const valueBucket = {
"name": "rose1", "name": "rose1",
...@@ -277,7 +804,7 @@ const valueBucket = { ...@@ -277,7 +804,7 @@ const valueBucket = {
} }
try { try {
dataShareHelper.insert(uri, valueBucket).then((data) => { dataShareHelper.insert(uri, valueBucket).then((data) => {
console.log("insert succeed, data : " + data); console.info("insert succeed, data : " + data);
}). catch((err) => { }). catch((err) => {
console.error(`insert error: code: ${err.code}, message: ${err.message} `); 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 ...@@ -305,7 +832,6 @@ Deletes one or more data records from the database. This API uses an asynchronou
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
...@@ -313,7 +839,7 @@ let da = new dataSharePredicates.DataSharePredicates(); ...@@ -313,7 +839,7 @@ let da = new dataSharePredicates.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
try { try {
dataShareHelper.delete(uri, da, (err, data) => { dataShareHelper.delete(uri, da, (err, data) => {
if (err != undefined) { if (err !== undefined) {
console.error(`delete error: code: ${err.code}, message: ${err.message} `); console.error(`delete error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
...@@ -348,7 +874,6 @@ Deletes one or more data records from the database. This API uses a promise to r ...@@ -348,7 +874,6 @@ Deletes one or more data records from the database. This API uses a promise to r
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
...@@ -356,7 +881,7 @@ let da = new dataSharePredicates.DataSharePredicates(); ...@@ -356,7 +881,7 @@ let da = new dataSharePredicates.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
try { try {
dataShareHelper.delete(uri, da).then((data) => { dataShareHelper.delete(uri, da).then((data) => {
console.log("delete succeed, data : " + data); console.info("delete succeed, data : " + data);
}). catch((err) => { }). catch((err) => {
console.error(`delete error: code: ${err.code}, message: ${err.message} `); 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 ...@@ -385,7 +910,6 @@ Queries data in the database. This API uses an asynchronous callback to return t
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
...@@ -394,11 +918,11 @@ let da = new dataSharePredicates.DataSharePredicates(); ...@@ -394,11 +918,11 @@ let da = new dataSharePredicates.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
try { try {
dataShareHelper.query(uri, da, columns, (err, data) => { dataShareHelper.query(uri, da, columns, (err, data) => {
if (err != undefined) { if (err !== undefined) {
console.error(`query error: code: ${err.code}, message: ${err.message} `); console.error(`query error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
console.log("query succeed, rowCount : " + data.rowCount); console.info("query succeed, rowCount : " + data.rowCount);
}); });
} catch (err) { } catch (err) {
console.error(`query error: code: ${err.code}, message: ${err.message} `); 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. ...@@ -430,7 +954,6 @@ Queries data in the database. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
...@@ -439,7 +962,7 @@ let da = new dataSharePredicates.DataSharePredicates(); ...@@ -439,7 +962,7 @@ let da = new dataSharePredicates.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
try { try {
dataShareHelper.query(uri, da, columns).then((data) => { dataShareHelper.query(uri, da, columns).then((data) => {
console.log("query succeed, rowCount : " + data.rowCount); console.info("query succeed, rowCount : " + data.rowCount);
}). catch((err) => { }). catch((err) => {
console.error(`query error: code: ${err.code}, message: ${err.message} `); 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 ...@@ -468,7 +991,6 @@ Updates data in the database. This API uses an asynchronous callback to return t
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
...@@ -482,11 +1004,11 @@ const va = { ...@@ -482,11 +1004,11 @@ const va = {
} }
try { try {
dataShareHelper.update(uri, da, va, (err, data) => { dataShareHelper.update(uri, da, va, (err, data) => {
if (err != undefined) { if (err !== undefined) {
console.error(`update error: code: ${err.code}, message: ${err.message} `); console.error(`update error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
console.log("update succeed, data : " + data); console.info("update succeed, data : " + data);
}); });
} catch (err) { } catch (err) {
console.error(`update error: code: ${err.code}, message: ${err.message} `); 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. ...@@ -518,7 +1040,6 @@ Updates data in the database. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
...@@ -532,7 +1053,7 @@ const va = { ...@@ -532,7 +1053,7 @@ const va = {
} }
try { try {
dataShareHelper.update(uri, da, va).then((data) => { dataShareHelper.update(uri, da, va).then((data) => {
console.log("update succeed, data : " + data); console.info("update succeed, data : " + data);
}). catch((err) => { }). catch((err) => {
console.error(`update error: code: ${err.code}, message: ${err.message} `); 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 ...@@ -560,19 +1081,17 @@ Batch inserts data into the database. This API uses an asynchronous callback to
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,},
{"name": "roe12", "age": 21, "salary": 20.5,}, {"name": "roe12", "age": 21, "salary": 20.5,},
{"name": "roe13", "age": 21, "salary": 20.5,}) {"name": "roe13", "age": 21, "salary": 20.5,})
try { try {
dataShareHelper.batchInsert(uri, vbs, (err, data) => { dataShareHelper.batchInsert(uri, vbs, (err, data) => {
if (err != undefined) { if (err !== undefined) {
console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
console.log("batchInsert succeed, data : " + data); console.info("batchInsert succeed, data : " + data);
}); });
} catch (err) { } catch (err) {
console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); 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 ...@@ -603,15 +1122,13 @@ Batch inserts data into the database. This API uses a promise to return the resu
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,},
{"name": "roe12", "age": 21, "salary": 20.5,}, {"name": "roe12", "age": 21, "salary": 20.5,},
{"name": "roe13", "age": 21, "salary": 20.5,}) {"name": "roe13", "age": 21, "salary": 20.5,})
try { try {
dataShareHelper.batchInsert(uri, vbs).then((data) => { dataShareHelper.batchInsert(uri, vbs).then((data) => {
console.log("batchInsert succeed, data : " + data); console.info("batchInsert succeed, data : " + data);
}). catch((err) => { }). catch((err) => {
console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); 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 ...@@ -638,14 +1155,12 @@ Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the lo
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.normalizeUri(uri, (err, data) => { dataShareHelper.normalizeUri(uri, (err, data) => {
if (err != undefined) { if (err !== undefined) {
console.log("normalizeUri failed, error message : " + err); console.info("normalizeUri failed, error message : " + err);
}else{ }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 ...@@ -673,13 +1188,11 @@ Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the lo
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.normalizeUri(uri).then((data) => { dataShareHelper.normalizeUri(uri).then((data) => {
console.log("normalizeUri = " + data); console.info("normalizeUri = " + data);
}).catch((err) => { }).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. ...@@ -701,14 +1214,12 @@ Denormalizes a URI. This API uses an asynchronous callback to return the result.
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.denormalizeUri(uri, (err, data) => { dataShareHelper.denormalizeUri(uri, (err, data) => {
if (err != undefined) { if (err !== undefined) {
console.log("denormalizeUri failed, error message : " + err); console.error("denormalizeUri failed, error message : " + err);
}else{ }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. ...@@ -736,13 +1247,11 @@ Denormalizes a URI. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.denormalizeUri(uri).then((data) => { dataShareHelper.denormalizeUri(uri).then((data) => {
console.log("denormalizeUri = " + data); console.info("denormalizeUri = " + data);
}).catch((err) => { }).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 ...@@ -764,11 +1273,9 @@ Notifies the registered observer of data changes. This API uses an asynchronous
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.notifyChange(uri, () => { 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 ...@@ -795,8 +1302,6 @@ Notifies the registered observer of data changes. This API uses a promise to ret
**Example** **Example**
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.notifyChange(uri); dataShareHelper.notifyChange(uri);
``` ```
...@@ -7,8 +7,7 @@ The APIs provided by **DataSharePredicates** correspond to the filter criteria ...@@ -7,8 +7,7 @@ The APIs provided by **DataSharePredicates** correspond to the filter criteria
> **NOTE** > **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.
## Modules to Import ## Modules to Import
...@@ -20,7 +19,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates'; ...@@ -20,7 +19,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
## 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. 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 ### equalTo<sup>10+</sup>
equalTo(field: string, value: ValueType): DataSharePredicates equalTo(field: string, value: ValueType): DataSharePredicates
...@@ -59,6 +58,7 @@ Sets a **DataSharePredicates** object to match the data that is not equal to the ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -90,6 +90,7 @@ Adds a left parenthesis to this **DataSharePredicates**. ...@@ -90,6 +90,7 @@ Adds a left parenthesis to this **DataSharePredicates**.
Currently, only the RDB supports this **DataSharePredicates** object. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value** **Return value**
...@@ -119,6 +120,7 @@ Adds a right parenthesis to this **DataSharePredicates** object. ...@@ -119,6 +120,7 @@ Adds a right parenthesis to this **DataSharePredicates** object.
Currently, only the RDB supports this **DataSharePredicates** object. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value** **Return value**
...@@ -148,6 +150,7 @@ Adds the OR condition to this **DataSharePredicates** object. ...@@ -148,6 +150,7 @@ Adds the OR condition to this **DataSharePredicates** object.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value** **Return value**
...@@ -165,7 +168,7 @@ predicates.equalTo("NAME", "lisi") ...@@ -165,7 +168,7 @@ predicates.equalTo("NAME", "lisi")
.equalTo("NAME", "Rose") .equalTo("NAME", "Rose")
``` ```
### and ### and<sup>10+</sup>
and(): DataSharePredicates and(): DataSharePredicates
...@@ -199,6 +202,7 @@ Sets a **DataSharePredicates** object to match the data that contains the specif ...@@ -199,6 +202,7 @@ Sets a **DataSharePredicates** object to match the data that contains the specif
Currently, only the RDB supports this **DataSharePredicates** object. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -230,6 +234,7 @@ Sets a **DataSharePredicates** object to match the data that begins with the spe ...@@ -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. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -261,6 +266,7 @@ Sets a **DataSharePredicates** object to match the data that ends with the speci ...@@ -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. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -292,6 +298,7 @@ Sets a **DataSharePredicates** object to match the data whose value is null. ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -322,6 +329,7 @@ Sets a **DataSharePredicates** object to match the data whose value is not null. ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -352,6 +360,7 @@ Sets a **DataSharePredicates** object to match the data that matches the specifi ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -383,6 +392,7 @@ Sets a **DataSharePredicates** object to match the data that does not match the ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -414,6 +424,7 @@ Sets a **DataSharePredicates** object to match the data that matches the specifi ...@@ -414,6 +424,7 @@ Sets a **DataSharePredicates** object to match the data that matches the specifi
Currently, only the RDB supports this **DataSharePredicates** object. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -445,6 +456,7 @@ Sets a **DataSharePredicates** object to match the data that is within the speci ...@@ -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. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -477,6 +489,7 @@ Sets a **DataSharePredicates** object to match the data that is out of the speci ...@@ -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. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -509,6 +522,7 @@ Sets a **DataSharePredicates** object to match the data that is greater than the ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -540,6 +554,7 @@ Sets a **DataSharePredicates** object to match the data that is less than the sp ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -571,6 +586,7 @@ Sets a **DataSharePredicates** object to match the data that is greater than or ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -602,6 +618,7 @@ Sets a **DataSharePredicates** object to match the data that is less than or equ ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -624,7 +641,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -624,7 +641,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.lessThanOrEqualTo("AGE", 50) predicates.lessThanOrEqualTo("AGE", 50)
``` ```
### orderByAsc ### orderByAsc<sup>10+</sup>
orderByAsc(field: string): DataSharePredicates orderByAsc(field: string): DataSharePredicates
...@@ -653,7 +670,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -653,7 +670,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.orderByAsc("AGE") predicates.orderByAsc("AGE")
``` ```
### orderByDesc ### orderByDesc<sup>10+</sup>
orderByDesc(field: string): DataSharePredicates orderByDesc(field: string): DataSharePredicates
...@@ -691,6 +708,7 @@ Sets a **DataSharePredicates** object to filter out duplicate data records. ...@@ -691,6 +708,7 @@ Sets a **DataSharePredicates** object to filter out duplicate data records.
Currently, only the RDB supports this **DataSharePredicates** object. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value** **Return value**
...@@ -706,7 +724,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -706,7 +724,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose").distinct() predicates.equalTo("NAME", "Rose").distinct()
``` ```
### limit ### limit<sup>10+</sup>
limit(total: number, offset: number): DataSharePredicates limit(total: number, offset: number): DataSharePredicates
...@@ -745,6 +763,7 @@ Sets a **DataSharePredicates** object group the records according to the specifi ...@@ -745,6 +763,7 @@ Sets a **DataSharePredicates** object group the records according to the specifi
Currently, only the RDB supports this **DataSharePredicates** object. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -775,6 +794,7 @@ Sets a **DataSharePredicates** object to list data by the specified index. ...@@ -775,6 +794,7 @@ Sets a **DataSharePredicates** object to list data by the specified index.
Currently, only the RDB supports this **DataSharePredicates** object. Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -796,7 +816,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -796,7 +816,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.indexedBy("SALARY_INDEX") predicates.indexedBy("SALARY_INDEX")
``` ```
### in ### in<sup>10+</sup>
in(field: string, value: Array&lt;ValueType&gt;): DataSharePredicates in(field: string, value: Array&lt;ValueType&gt;): DataSharePredicates
...@@ -835,6 +855,7 @@ Sets a **DataSharePredicates** object to match the data that is not in the speci ...@@ -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. Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -866,6 +887,7 @@ Sets a **DataSharePredicates** object to match the data with the specified key p ...@@ -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. Currently, only the KVDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
...@@ -896,6 +918,7 @@ Sets a **DataSharePredicates** object to match the data whose keys are within th ...@@ -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. Currently, only the KVDB supports this **DataSharePredicates** object.
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core **System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters** **Parameters**
......
...@@ -4,8 +4,7 @@ The **ValueBucket** module holds data in key-value (KV) pairs. You can use it to ...@@ -4,8 +4,7 @@ The **ValueBucket** module holds data in key-value (KV) pairs. You can use it to
> **NOTE** > **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 ## Modules to Import
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册