js-apis-inner-ability-dataAbilityHelper.md 37.1 KB
Newer Older
W
wusongqing 已提交
1
# DataAbilityHelper
W
wusongqing 已提交
2

3 4
The **DataAbilityHelper** object is obtained through [acquireDataAbilityHelper](js-apis-ability-featureAbility.md#featureabilityacquiredataabilityhelper7).

W
wusongqing 已提交
5 6 7 8
> **NOTE**
> 
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 
> The APIs of this module can be used only in the FA model.
W
wusongqing 已提交
9

W
wusongqing 已提交
10 11 12
## Usage

Import the following modules based on the actual situation before using the current module:
13 14 15
```ts
import ohos_data_ability from '@ohos.data.dataAbility';
import ohos_data_rdb from '@ohos.data.rdb';
W
wusongqing 已提交
16 17
```

W
wusongqing 已提交
18
## DataAbilityHelper.openFile
W
wusongqing 已提交
19

W
wusongqing 已提交
20
openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void
W
wusongqing 已提交
21

22
Opens a file with a specified URI. This API uses an asynchronous callback to return a file descriptor.
W
wusongqing 已提交
23

W
wusongqing 已提交
24
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
25

W
wusongqing 已提交
26
**Parameters**
W
wusongqing 已提交
27

W
wusongqing 已提交
28
| Name    | Type                  | Mandatory| Description                              |
W
wusongqing 已提交
29
| -------- | ---------------------- | ---- | ---------------------------------- |
W
wusongqing 已提交
30
| uri      | string                 | Yes  | URI of the file to open.          |
31
| mode     | string                 | Yes  | Mode for opening the file. The value **r** indicates read-only access, **w** indicates **write-only** access, and **rw** indicates read-write access.           |
W
wusongqing 已提交
32
| callback | AsyncCallback\<number> | Yes  | Callback used to return the file descriptor.|
W
wusongqing 已提交
33

W
wusongqing 已提交
34
**Example**
W
wusongqing 已提交
35

36 37
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
38 39 40
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
41 42 43
var mode = "rw";
DAHelper.openFile("dataability:///com.example.DataAbility", mode, (err, data) => {
    console.info("openFile err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
44 45 46
});
```

W
wusongqing 已提交
47
## DataAbilityHelper.openFile
W
wusongqing 已提交
48

W
wusongqing 已提交
49
openFile(uri: string, mode: string): Promise\<number>
W
wusongqing 已提交
50

51
Opens a file with a specified URI. This API uses a promise to return a file descriptor.
W
wusongqing 已提交
52

W
wusongqing 已提交
53
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
54

W
wusongqing 已提交
55
**Parameters**
W
wusongqing 已提交
56

W
wusongqing 已提交
57
| Name| Type  | Mandatory| Description                    |
W
wusongqing 已提交
58
| ---- | ------ | ---- | ------------------------ |
W
wusongqing 已提交
59
| uri  | string | Yes  | URI of the file to open.|
60
| mode | string | Yes  | Mode for opening the file. The value **r** indicates read-only access, **w** indicates **write-only** access, and **rw** indicates read-write access. |
W
wusongqing 已提交
61

W
wusongqing 已提交
62
**Return value**
W
wusongqing 已提交
63

W
wusongqing 已提交
64
| Type            | Description            |
W
wusongqing 已提交
65 66
| ---------------- | ---------------- |
| Promise\<number> | Promise used to return the file descriptor.|
W
wusongqing 已提交
67

W
wusongqing 已提交
68
**Example**
W
wusongqing 已提交
69

70 71
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
72 73 74
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
75 76 77
var mode = "rw";
DAHelper.openFile("dataability:///com.example.DataAbility", mode).then((data) => {
    console.info("openFile data: " + JSON.stringify(data));
W
wusongqing 已提交
78 79 80
});
```

W
wusongqing 已提交
81
## DataAbilityHelper.on
W
wusongqing 已提交
82

W
wusongqing 已提交
83
on(type: 'dataChange', uri: string, callback: AsyncCallback\<void>): void
W
wusongqing 已提交
84

85
Registers an observer to listen for changes in the data specified by a given URI.
W
wusongqing 已提交
86

W
wusongqing 已提交
87
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
88

W
wusongqing 已提交
89
**Parameters**
W
wusongqing 已提交
90

W
wusongqing 已提交
91
| Name    | Type                | Mandatory| Description                    |
W
wusongqing 已提交
92
| -------- | -------------------- | ---- | ------------------------ |
93
| type     | string               | Yes  | The value **dataChange** means data changes.              |
W
wusongqing 已提交
94 95
| uri      | string               | Yes  | URI of the data.|
| callback | AsyncCallback\<void> | Yes  | Callback invoked when the data is changed.  |
W
wusongqing 已提交
96

W
wusongqing 已提交
97
**Example**
W
wusongqing 已提交
98

99 100 101
```ts
import featureAbility from '@ohos.ability.featureAbility';
var DAHelper = featureAbility.acquireDataAbilityHelper(
W
wusongqing 已提交
102 103 104
    "dataability:///com.example.DataAbility"
);
function onChangeNotify() {
105
    console.info("onChangeNotify call back");
W
wusongqing 已提交
106
};
107
DAHelper.on(
W
wusongqing 已提交
108 109 110
    "dataChange",
    "dataability:///com.example.DataAbility",
    onChangeNotify
111
);
W
wusongqing 已提交
112 113
```

W
wusongqing 已提交
114
## DataAbilityHelper.off
W
wusongqing 已提交
115

W
wusongqing 已提交
116
off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>): void
W
wusongqing 已提交
117

118
Deregisters the observer that listens for changes in the data specified by a given URI.
W
wusongqing 已提交
119

W
wusongqing 已提交
120
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
121

W
wusongqing 已提交
122
**Parameters**
W
wusongqing 已提交
123

W
wusongqing 已提交
124
| Name    | Type                | Mandatory| Description                    |
W
wusongqing 已提交
125
| -------- | -------------------- | ---- | ------------------------ |
126
| type     | string               | Yes  | The value **dataChange** means data changes.              |
W
wusongqing 已提交
127
| uri      | string               | Yes  | URI of the data.|
128
| callback | AsyncCallback\<void> | No  | Callback of the listener to deregister. If the callback is set to **null**, all data change listeners are canceled.      |
W
wusongqing 已提交
129

W
wusongqing 已提交
130
**Example**
W
wusongqing 已提交
131

132 133 134
```ts
import featureAbility from '@ohos.ability.featureAbility';
var DAHelper = featureAbility.acquireDataAbilityHelper(
W
wusongqing 已提交
135 136 137
    "dataability:///com.example.DataAbility"
);
function onChangeNotify() {
138
    console.info("onChangeNotify call back");
W
wusongqing 已提交
139
};
140
DAHelper.off(
W
wusongqing 已提交
141 142
    "dataChange",
    "dataability:///com.example.DataAbility",
143 144 145
    onChangeNotify
);
DAHelper.off(
W
wusongqing 已提交
146 147
    "dataChange",
    "dataability:///com.example.DataAbility",
148
);
W
wusongqing 已提交
149 150
```

W
wusongqing 已提交
151
## DataAbilityHelper.getType
W
wusongqing 已提交
152

W
wusongqing 已提交
153
getType(uri: string, callback: AsyncCallback\<string>): void
W
wusongqing 已提交
154

155
Obtains the media resource type of the data specified by a given URI. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
156

W
wusongqing 已提交
157
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
158

W
wusongqing 已提交
159
**Parameters**
W
wusongqing 已提交
160

W
wusongqing 已提交
161
| Name    | Type                  | Mandatory| Description                                         |
W
wusongqing 已提交
162
| -------- | ---------------------- | ---- | --------------------------------------------- |
W
wusongqing 已提交
163
| uri      | string                 | Yes  | URI of the data.                     |
164
| callback | AsyncCallback\<string> | Yes  | Callback used to return the media resource type.|
W
wusongqing 已提交
165

W
wusongqing 已提交
166
**Example**
W
wusongqing 已提交
167

168 169
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
170 171 172
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
173 174
DAHelper.getType("dataability:///com.example.DataAbility", (err, data) => {
    console.info("getType err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
175 176 177
});
```

W
wusongqing 已提交
178
## DataAbilityHelper.getType
W
wusongqing 已提交
179

W
wusongqing 已提交
180
getType(uri: string): Promise\<string>
W
wusongqing 已提交
181

182
Obtains the media resource type of the data specified by a given URI. This API uses a promise to return the result.
W
wusongqing 已提交
183

W
wusongqing 已提交
184
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
185

W
wusongqing 已提交
186
**Parameters**
W
wusongqing 已提交
187

W
wusongqing 已提交
188
| Name| Type  | Mandatory| Description                    |
W
wusongqing 已提交
189
| ---- | ------ | ---- | ------------------------ |
W
wusongqing 已提交
190
| uri  | string | Yes  | URI of the data.|
W
wusongqing 已提交
191

W
wusongqing 已提交
192
**Return value**
W
wusongqing 已提交
193

W
wusongqing 已提交
194
| Type            | Description                               |
W
wusongqing 已提交
195
| ---------------- | ----------------------------------- |
196
| Promise\<string> | Promise used to return the media resource type.|
W
wusongqing 已提交
197

W
wusongqing 已提交
198
**Example**
W
wusongqing 已提交
199

200 201
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
202 203 204
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
205 206
DAHelper.getType("dataability:///com.example.DataAbility").then((data) => {
    console.info("getType data: " + JSON.stringify(data));
W
wusongqing 已提交
207 208 209
});
```

W
wusongqing 已提交
210
## DataAbilityHelper.getFileTypes
W
wusongqing 已提交
211

W
wusongqing 已提交
212
getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): void
W
wusongqing 已提交
213

214
Obtains the supported media resource types of a specified file. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
215

W
wusongqing 已提交
216
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
217

W
wusongqing 已提交
218
**Parameters**
W
wusongqing 已提交
219

W
wusongqing 已提交
220
| Name          | Type                          | Mandatory| Description                              |
W
wusongqing 已提交
221
| -------------- | ------------------------------ | ---- | ---------------------------------- |
W
wusongqing 已提交
222
| uri            | string                         | Yes  | URI of the file.          |
223 224
| mimeTypeFilter | string                         | Yes  | Media resource type of the file to obtain.      |
| callback       | AsyncCallback\<Array\<string>> | Yes  | Callback used to return an array holding the media resource type.|
W
wusongqing 已提交
225

W
wusongqing 已提交
226
**Example**
W
wusongqing 已提交
227

228 229
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
230 231 232
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
233 234
DAHelper.getFileTypes( "dataability:///com.example.DataAbility", "image/*", (err, data) => {
    console.info("getFileTypes err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
235 236 237
});
```

W
wusongqing 已提交
238
## DataAbilityHelper.getFileTypes
W
wusongqing 已提交
239 240

getFileTypes(uri: string, mimeTypeFilter: string): Promise\<Array\<string>>
W
wusongqing 已提交
241

242
Obtains the supported media resource types of a specified file. This API uses a promise to return the result.
W
wusongqing 已提交
243

W
wusongqing 已提交
244
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
245

W
wusongqing 已提交
246
**Parameters**
W
wusongqing 已提交
247

W
wusongqing 已提交
248
| Name          | Type  | Mandatory| Description                        |
W
wusongqing 已提交
249
| -------------- | ------ | ---- | ---------------------------- |
W
wusongqing 已提交
250
| uri            | string | Yes  | URI of the file.    |
251
| mimeTypeFilter | string | Yes  | Media resource type of the file to obtain.|
W
wusongqing 已提交
252

W
wusongqing 已提交
253
**Return value**
W
wusongqing 已提交
254

W
wusongqing 已提交
255
| Type                    | Description                    |
W
wusongqing 已提交
256
| ------------------------ | ------------------------ |
257
| Promise\<Array\<string>> | Promise used to return an array holding the media resource type.|
W
wusongqing 已提交
258

W
wusongqing 已提交
259
**Example**
W
wusongqing 已提交
260

261 262
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
263 264 265
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
266 267
DAHelper.getFileTypes("dataability:///com.example.DataAbility", "image/*").then((data) => {
    console.info("getFileTypes data: " + JSON.stringify(data));
W
wusongqing 已提交
268 269 270
});
```

W
wusongqing 已提交
271
## DataAbilityHelper.normalizeUri
W
wusongqing 已提交
272

W
wusongqing 已提交
273
normalizeUri(uri: string, callback: AsyncCallback\<string>): void
W
wusongqing 已提交
274

W
wusongqing 已提交
275
Converts the URI that refers to a Data ability into a normalized URI. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
276

W
wusongqing 已提交
277
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
278

W
wusongqing 已提交
279
**Parameters**
W
wusongqing 已提交
280

W
wusongqing 已提交
281
| Name    | Type                  | Mandatory| Description                                                        |
W
wusongqing 已提交
282
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
283 284
| uri      | string                 | Yes  | URI object to normalize.                                     |
| callback | AsyncCallback\<string> | Yes  | Callback used to return the normalized URI object if the Data ability supports URI normalization. If the Data ability does not support URI normalization, **null** is returned.|
W
wusongqing 已提交
285

W
wusongqing 已提交
286
**Example**
W
wusongqing 已提交
287

288 289
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
290 291 292
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
293 294
DAHelper.normalizeUri("dataability:///com.example.DataAbility", (err, data) => {
    console.info("normalizeUri err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
295 296 297
});
```

W
wusongqing 已提交
298
## DataAbilityHelper.normalizeUri
W
wusongqing 已提交
299

W
wusongqing 已提交
300
normalizeUri(uri: string): Promise\<string>
W
wusongqing 已提交
301

W
wusongqing 已提交
302
Converts the URI that refers to a Data ability into a normalized URI. This API uses a promise to return the result.
W
wusongqing 已提交
303

W
wusongqing 已提交
304
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
305

W
wusongqing 已提交
306
**Parameters**
W
wusongqing 已提交
307

W
wusongqing 已提交
308
| Name| Type  | Mandatory| Description                   |
W
wusongqing 已提交
309
| ---- | ------ | ---- | ----------------------- |
W
wusongqing 已提交
310
| uri  | string | Yes  | URI object to normalize.|
W
wusongqing 已提交
311

W
wusongqing 已提交
312
**Return value**
W
wusongqing 已提交
313

W
wusongqing 已提交
314
| Type            | Description                                                  |
W
wusongqing 已提交
315 316
| ---------------- | ------------------------------------------------------ |
| Promise\<string> | Promise used to return the normalized URI object if the Data ability supports URI normalization. If the Data ability does not support URI normalization, **null** is returned.|
W
wusongqing 已提交
317

W
wusongqing 已提交
318
**Example**
W
wusongqing 已提交
319

320 321
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
322 323 324
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
325 326
DAHelper.normalizeUri("dataability:///com.example.DataAbility",).then((data) => {
    console.info("normalizeUri data: " + JSON.stringify(data));
W
wusongqing 已提交
327 328 329
});
```

W
wusongqing 已提交
330
## DataAbilityHelper.denormalizeUri
W
wusongqing 已提交
331

W
wusongqing 已提交
332
denormalizeUri(uri: string, callback: AsyncCallback\<string>): void
W
wusongqing 已提交
333

W
wusongqing 已提交
334
Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\<string>)** to a denormalized one. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
335

W
wusongqing 已提交
336
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
337

W
wusongqing 已提交
338
**Parameters**
W
wusongqing 已提交
339

W
wusongqing 已提交
340
| Name    | Type                  | Mandatory| Description                                               |
W
wusongqing 已提交
341
| -------- | ---------------------- | ---- | --------------------------------------------------- |
342
| uri      | string                 | Yes  | URI object to denormalize.                            |
W
wusongqing 已提交
343
| callback | AsyncCallback\<string> | Yes  | Callback used to return the denormalized URI object.|
W
wusongqing 已提交
344

W
wusongqing 已提交
345
**Example**
W
wusongqing 已提交
346

347 348
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
349 350 351
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
352 353
DAHelper.denormalizeUri("dataability:///com.example.DataAbility", (err, data) => {
    console.info("denormalizeUri err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
354 355 356
});
```

W
wusongqing 已提交
357
## DataAbilityHelper.denormalizeUri
W
wusongqing 已提交
358 359

denormalizeUri(uri: string): Promise\<string>
W
wusongqing 已提交
360

W
wusongqing 已提交
361
Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string)** to a denormalized one. This API uses a promise to return the result.
W
wusongqing 已提交
362

W
wusongqing 已提交
363
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
364

W
wusongqing 已提交
365
**Parameters**
W
wusongqing 已提交
366

W
wusongqing 已提交
367
| Name| Type  | Mandatory| Description                   |
W
wusongqing 已提交
368
| ---- | ------ | ---- | ----------------------- |
W
wusongqing 已提交
369
| uri  | string | Yes  | URI object to normalize.|
W
wusongqing 已提交
370

W
wusongqing 已提交
371
**Return value**
W
wusongqing 已提交
372

W
wusongqing 已提交
373
| Type            | Description                                     |
W
wusongqing 已提交
374 375
| ---------------- | ----------------------------------------- |
| Promise\<string> | Promise used to return the denormalized URI object.|
W
wusongqing 已提交
376

W
wusongqing 已提交
377
**Example**
W
wusongqing 已提交
378

379 380
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
381 382 383
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
384 385
DAHelper.denormalizeUri("dataability:///com.example.DataAbility",).then((data) => {
    console.info("denormalizeUri data: " + JSON.stringify(data));
W
wusongqing 已提交
386 387 388
});
```

W
wusongqing 已提交
389
## DataAbilityHelper.notifyChange
W
wusongqing 已提交
390

W
wusongqing 已提交
391
notifyChange(uri: string, callback: AsyncCallback\<void>): void
W
wusongqing 已提交
392

W
wusongqing 已提交
393
Notifies the registered observer of a change to the data specified by the URI. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
394

W
wusongqing 已提交
395
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
396

W
wusongqing 已提交
397
**Parameters**
W
wusongqing 已提交
398

W
wusongqing 已提交
399
| Name    | Type                | Mandatory| Description                    |
W
wusongqing 已提交
400
| -------- | -------------------- | ---- | ------------------------ |
401
| uri      | string               | Yes  | URI of the data that changes.|
W
wusongqing 已提交
402
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.              |
W
wusongqing 已提交
403

W
wusongqing 已提交
404
**Example**
W
wusongqing 已提交
405

406 407 408
```ts
import featureAbility from '@ohos.ability.featureAbility';
var DAHelper = featureAbility.acquireDataAbilityHelper(
W
wusongqing 已提交
409 410
    "dataability:///com.example.DataAbility"
);
411 412
DAHelper.notifyChange("dataability:///com.example.DataAbility", (err) => {
    console.info("==========================>Called=======================>");
W
wusongqing 已提交
413 414 415
});
```

W
wusongqing 已提交
416
## DataAbilityHelper.notifyChange
W
wusongqing 已提交
417

W
wusongqing 已提交
418
notifyChange(uri: string): Promise\<void>
W
wusongqing 已提交
419

W
wusongqing 已提交
420
Notifies the registered observer of a change to the data specified by the URI. This API uses a promise to return the result.
W
wusongqing 已提交
421

W
wusongqing 已提交
422
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
423

W
wusongqing 已提交
424
**Parameters**
W
wusongqing 已提交
425

W
wusongqing 已提交
426
| Name| Type  | Mandatory| Description                    |
W
wusongqing 已提交
427
| ---- | ------ | ---- | ------------------------ |
428
| uri  | string | Yes  | URI of the data that changes.|
W
wusongqing 已提交
429

W
wusongqing 已提交
430
**Return value**
W
wusongqing 已提交
431

W
wusongqing 已提交
432
| Type          | Description                 |
W
wusongqing 已提交
433 434
| -------------- | --------------------- |
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
435

W
wusongqing 已提交
436
**Example**
W
wusongqing 已提交
437

438 439
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
440 441 442
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
443 444
DAHelper.notifyChange("dataability:///com.example.DataAbility").then(() => {
    console.info("================>notifyChangeCallback================>");
W
wusongqing 已提交
445 446 447
});
```

W
wusongqing 已提交
448
## DataAbilityHelper.insert
W
wusongqing 已提交
449

W
wusongqing 已提交
450
insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\<number>): void
W
wusongqing 已提交
451

W
wusongqing 已提交
452
Inserts a single data record into the database. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
453

W
wusongqing 已提交
454
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
455

W
wusongqing 已提交
456
**Parameters**
W
wusongqing 已提交
457

W
wusongqing 已提交
458
| Name        | Type                  | Mandatory| Description                                                  |
W
wusongqing 已提交
459
| ------------ | ---------------------- | ---- | ------------------------------------------------------ |
W
wusongqing 已提交
460 461 462
| uri          | string                 | Yes  | URI of the data to insert.                              |
| valuesBucket | rdb.ValuesBucket       | Yes  | Data record to insert. If this parameter is **null**, a blank row will be inserted.|
| callback     | AsyncCallback\<number> | Yes  | Callback used to return the index of the inserted data record.                    |
W
wusongqing 已提交
463

W
wusongqing 已提交
464
**Example**
W
wusongqing 已提交
465

466 467
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
468 469 470 471 472 473 474
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
const valueBucket = {
    "name": "rose",
    "age": 22,
    "salary": 200.5,
W
wusongqing 已提交
475
    "blobType": "u8",
476 477 478
};
DAHelper.insert("dataability:///com.example.DataAbility", valueBucket, (err, data) => {
    console.info("insert err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
479 480 481
});
```

W
wusongqing 已提交
482
## DataAbilityHelper.insert
W
wusongqing 已提交
483

W
wusongqing 已提交
484
insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\<number>
W
wusongqing 已提交
485

W
wusongqing 已提交
486
Inserts a single data record into the database. This API uses a promise to return the result.
W
wusongqing 已提交
487

W
wusongqing 已提交
488
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
489

W
wusongqing 已提交
490
**Parameters**
W
wusongqing 已提交
491

W
wusongqing 已提交
492
| Name        | Type            | Mandatory| Description                                                  |
W
wusongqing 已提交
493
| ------------ | ---------------- | ---- | ------------------------------------------------------ |
W
wusongqing 已提交
494 495
| uri          | string           | Yes  | URI of the data to insert.                              |
| valuesBucket | rdb.ValuesBucket | Yes  | Data record to insert. If this parameter is **null**, a blank row will be inserted.|
W
wusongqing 已提交
496

W
wusongqing 已提交
497
**Return value**
W
wusongqing 已提交
498

W
wusongqing 已提交
499
| Type            | Description                    |
W
wusongqing 已提交
500 501
| ---------------- | ------------------------ |
| Promise\<number> | Promise used to return the index of the inserted data record.|
W
wusongqing 已提交
502

W
wusongqing 已提交
503
**Example**
W
wusongqing 已提交
504

505 506
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
507 508 509 510 511 512 513
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
const valueBucket = {
    "name": "rose1",
    "age": 221,
    "salary": 20.5,
W
wusongqing 已提交
514
    "blobType": "u8",
515 516 517
};
DAHelper.insert("dataability:///com.example.DataAbility", valueBucket).then((data) => {
    console.info("insert data: " + JSON.stringify(data));
W
wusongqing 已提交
518 519 520
});
```

W
wusongqing 已提交
521
## DataAbilityHelper.batchInsert
W
wusongqing 已提交
522

523
batchInsert(uri: string, valuesBuckets: Array\<rdb.ValuesBucket>, callback: AsyncCallback\<number>): void
W
wusongqing 已提交
524

W
wusongqing 已提交
525
Inserts multiple data records into the database. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
526

W
wusongqing 已提交
527
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
528

W
wusongqing 已提交
529
**Parameters**
W
wusongqing 已提交
530

W
wusongqing 已提交
531
| Name        | Type                   | Mandatory| Description                            |
W
wusongqing 已提交
532
| ------------ | ----------------------- | ---- | -------------------------------- |
W
wusongqing 已提交
533
| uri          | string                  | Yes  | URI of the data to insert.        |
534
| valuesBucket | Array\<rdb.ValuesBucket> | Yes  | Data records to insert.          |
W
wusongqing 已提交
535
| callback     | AsyncCallback\<number>  | Yes  | Callback used to return the number of inserted data records.|
W
wusongqing 已提交
536

W
wusongqing 已提交
537
**Example**
W
wusongqing 已提交
538

539 540
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
541 542 543
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
W
wusongqing 已提交
544 545
var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": "u8",},
                     {"name": "roe12", "age": 21, "salary": 20.5, "blobType": "u8",},
546 547 548
                     {"name": "roe13", "age": 21, "salary": 20.5, "blobType": "u8",});
DAHelper.batchInsert("dataability:///com.example.DataAbility", cars, (err, data) => {
    console.info("batchInsert err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
549 550 551
});
```

W
wusongqing 已提交
552
## DataAbilityHelper.batchInsert
W
wusongqing 已提交
553

W
wusongqing 已提交
554
batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise\<number>
W
wusongqing 已提交
555

W
wusongqing 已提交
556
Inserts multiple data records into the database. This API uses a promise to return the result.
W
wusongqing 已提交
557

W
wusongqing 已提交
558
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
559

W
wusongqing 已提交
560
**Parameters**
W
wusongqing 已提交
561

W
wusongqing 已提交
562
| Name        | Type                   | Mandatory| Description                    |
W
wusongqing 已提交
563
| ------------ | ----------------------- | ---- | ------------------------ |
W
wusongqing 已提交
564
| uri          | string                  | Yes  | URI of the data to insert.|
565
| valuesBucket | Array<rdb.ValuesBucket> | Yes  | Data records to insert.  |
W
wusongqing 已提交
566

W
wusongqing 已提交
567
**Return value**
W
wusongqing 已提交
568

W
wusongqing 已提交
569
| Type            | Description                  |
W
wusongqing 已提交
570 571
| ---------------- | ---------------------- |
| Promise\<number> | Promise used to return the number of inserted data records.|
W
wusongqing 已提交
572

W
wusongqing 已提交
573
**Example**
W
wusongqing 已提交
574

575 576
```ts
import featureAbility from '@ohos.ability.featureAbility';
W
wusongqing 已提交
577 578 579
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
W
wusongqing 已提交
580 581
var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": "u8",},
                     {"name": "roe12", "age": 21, "salary": 20.5, "blobType": "u8",},
582 583 584
                     {"name": "roe13", "age": 21, "salary": 20.5, "blobType": "u8",});
DAHelper.batchInsert("dataability:///com.example.DataAbility", cars).then((data) => {
    console.info("batchInsert data: " + JSON.stringify(data));
W
wusongqing 已提交
585 586 587
});
```

W
wusongqing 已提交
588
## DataAbilityHelper.delete
W
wusongqing 已提交
589

W
wusongqing 已提交
590
delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void
W
wusongqing 已提交
591

W
wusongqing 已提交
592
Deletes one or more data records from the database. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
593

W
wusongqing 已提交
594
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
595

W
wusongqing 已提交
596
**Parameters**
W
wusongqing 已提交
597

W
wusongqing 已提交
598
| Name        | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
599
| ------------ | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
600
| uri          | string                            | Yes  | URI of the data to delete.                        |
601
| predicates | dataAbility.DataAbilityPredicates | Yes  | Filter criteria. You should define the processing logic when this parameter is **null**.|
W
wusongqing 已提交
602
| callback     | AsyncCallback\<number>            | Yes  | Callback used to return the number of deleted data records.              |
W
wusongqing 已提交
603

W
wusongqing 已提交
604
**Example**
W
wusongqing 已提交
605

606 607 608
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
W
wusongqing 已提交
609 610 611
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
612 613 614
let da = new ohos_data_ability.DataAbilityPredicates();
DAHelper.delete("dataability:///com.example.DataAbility", da, (err, data) => {
    console.info("delete err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
615 616 617
});
```

W
wusongqing 已提交
618
## DataAbilityHelper.delete
W
wusongqing 已提交
619

620
delete(uri: string, predicates?: dataAbility.DataAbilityPredicates): Promise\<number>;
W
wusongqing 已提交
621

W
wusongqing 已提交
622
Deletes one or more data records from the database. This API uses a promise to return the result.
W
wusongqing 已提交
623

W
wusongqing 已提交
624
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
625

W
wusongqing 已提交
626
**Parameters**
W
wusongqing 已提交
627

W
wusongqing 已提交
628
| Name        | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
629
| ------------ | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
630
| uri          | string                            | Yes  | URI of the data to delete.                        |
631
| predicates | dataAbility.DataAbilityPredicates | No  | Filter criteria. You should define the processing logic when this parameter is **null**.|
W
wusongqing 已提交
632

W
wusongqing 已提交
633
**Return value**
W
wusongqing 已提交
634

W
wusongqing 已提交
635
| Type            | Description                    |
W
wusongqing 已提交
636 637
| ---------------- | ------------------------ |
| Promise\<number> | Promise used to return the number of deleted data records.|
W
wusongqing 已提交
638

W
wusongqing 已提交
639
**Example**
W
wusongqing 已提交
640

641 642 643
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
W
wusongqing 已提交
644 645 646
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
647 648 649
let da = new ohos_data_ability.DataAbilityPredicates();
DAHelper.delete("dataability:///com.example.DataAbility", da).then((data) => {
    console.info("delete data: " + JSON.stringify(data));
W
wusongqing 已提交
650 651 652
});
```

W
wusongqing 已提交
653
## DataAbilityHelper.update
W
wusongqing 已提交
654

W
wusongqing 已提交
655
update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void
W
wusongqing 已提交
656

W
wusongqing 已提交
657
Updates data records in the database. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
658

W
wusongqing 已提交
659
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
660

W
wusongqing 已提交
661
**Parameters**
W
wusongqing 已提交
662

W
wusongqing 已提交
663
| Name        | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
664
| ------------ | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
665 666 667 668
| uri          | string                            | Yes  | URI of the data to update.                        |
| valuesBucket | rdb.ValuesBucket                  | Yes  | New values.                              |
| predicates   | dataAbility.DataAbilityPredicates | Yes  | Filter criteria. You should define the processing logic when this parameter is **null**.|
| callback     | AsyncCallback\<number>            | Yes  | Callback used to return the number of updated data records.                |
W
wusongqing 已提交
669

W
wusongqing 已提交
670
**Example**
W
wusongqing 已提交
671

672 673 674
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
W
wusongqing 已提交
675 676 677 678 679 680 681
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
const va = {
    "name": "roe1",
    "age": 21,
    "salary": 20.5,
W
wusongqing 已提交
682
    "blobType": "u8",
683 684 685 686
};
let da = new ohos_data_ability.DataAbilityPredicates();
DAHelper.update("dataability:///com.example.DataAbility", va, da, (err, data) => {
    console.info("update err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
687 688 689
});
```

W
wusongqing 已提交
690
## DataAbilityHelper.update
W
wusongqing 已提交
691

692
update(uri: string, valuesBucket: rdb.ValuesBucket, predicates?: dataAbility.DataAbilityPredicates): Promise\<number>;
W
wusongqing 已提交
693

W
wusongqing 已提交
694
Updates data records in the database. This API uses a promise to return the result.
W
wusongqing 已提交
695

W
wusongqing 已提交
696
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
697

W
wusongqing 已提交
698
**Parameters**
W
wusongqing 已提交
699

W
wusongqing 已提交
700
| Name        | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
701
| ------------ | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
702 703
| uri          | string                            | Yes  | URI of the data to update.                        |
| valuesBucket | rdb.ValuesBucket                  | Yes  | New values.                              |
704
| predicates   | dataAbility.DataAbilityPredicates | No  | Filter criteria. You should define the processing logic when this parameter is **null**.|
W
wusongqing 已提交
705

W
wusongqing 已提交
706
**Return value**
W
wusongqing 已提交
707

W
wusongqing 已提交
708
| Type            | Description                                        |
W
wusongqing 已提交
709
| ---------------- | -------------------------------------------- |
W
wusongqing 已提交
710
| Promise\<number> | Promise used to return the number of updated data records.  |
W
wusongqing 已提交
711

W
wusongqing 已提交
712
**Example**
W
wusongqing 已提交
713

714 715 716
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
W
wusongqing 已提交
717 718 719 720 721 722 723
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
const va = {
    "name": "roe1",
    "age": 21,
    "salary": 20.5,
W
wusongqing 已提交
724
    "blobType": "u8",
725 726 727 728
};
let da = new ohos_data_ability.DataAbilityPredicates();
DAHelper.update("dataability:///com.example.DataAbility", va, da).then((data) => {
    console.info("update data: " + JSON.stringify(data));
W
wusongqing 已提交
729 730 731
});
```

W
wusongqing 已提交
732
## DataAbilityHelper.query
W
wusongqing 已提交
733

W
wusongqing 已提交
734
query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>): void
W
wusongqing 已提交
735

W
wusongqing 已提交
736
Queries data in the database. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
737

W
wusongqing 已提交
738
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
739

W
wusongqing 已提交
740
**Parameters**
W
wusongqing 已提交
741

W
wusongqing 已提交
742
| Name      | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
743
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
744
| uri        | string                            | Yes  | URI of the data to query.                        |
745
| columns    | Array\<string>                | Yes  | Columns to query. If this parameter is **null**, all columns will be queried.  |
W
wusongqing 已提交
746 747
| predicates | dataAbility.DataAbilityPredicates | Yes  | Filter criteria. You should define the processing logic when this parameter is **null**.|
| callback   | AsyncCallback\<ResultSet>         | Yes  | Callback used to return the data queried.                        |
W
wusongqing 已提交
748

W
wusongqing 已提交
749
**Example**
W
wusongqing 已提交
750

751 752 753
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
W
wusongqing 已提交
754 755 756
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
W
wusongqing 已提交
757
var cars=new Array("value1", "value2", "value3", "value4");
758 759 760
let da = new ohos_data_ability.DataAbilityPredicates();
DAHelper.query("dataability:///com.example.DataAbility", cars, da, (err, data) => {
    console.info("query err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
W
wusongqing 已提交
761 762 763 764 765
});
```



W
wusongqing 已提交
766
## DataAbilityHelper.query
W
wusongqing 已提交
767

768
query(uri: string, columns?: Array\<string>, predicates?: dataAbility.DataAbilityPredicates): Promise\<ResultSet>;
W
wusongqing 已提交
769

W
wusongqing 已提交
770
Queries data in the database. This API uses a promise to return the result.
W
wusongqing 已提交
771

W
wusongqing 已提交
772
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
773

W
wusongqing 已提交
774
**Parameters**
W
wusongqing 已提交
775

W
wusongqing 已提交
776
| Name      | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
777
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
778
| uri        | string                            | Yes  | URI of the data to query.                        |
779 780
| columns    | Array\<string>               | No  | Columns to query. If this parameter is **null**, all columns will be queried.  |
| predicates | dataAbility.DataAbilityPredicates | No  | Filter criteria. You should define the processing logic when this parameter is **null**.|
W
wusongqing 已提交
781

W
wusongqing 已提交
782
**Return value**
W
wusongqing 已提交
783

W
wusongqing 已提交
784
| Type               | Description          |
W
wusongqing 已提交
785 786
| ------------------- | -------------- |
| Promise\<ResultSet> | Promise used to return the data queried.|
W
wusongqing 已提交
787

W
wusongqing 已提交
788
**Example**
W
wusongqing 已提交
789

790 791 792
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
W
wusongqing 已提交
793 794 795
var DAHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.DataAbility"
);
796 797 798 799
var cars = new Array("value1", "value2", "value3", "value4");
let da = new ohos_data_ability.DataAbilityPredicates();
DAHelper.query("dataability:///com.example.DataAbility", cars, da).then((data) => {
    console.info("query data: " + JSON.stringify(data));
W
wusongqing 已提交
800 801
});
```
W
wusongqing 已提交
802 803 804

## DataAbilityHelper.call

805
call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback\<PacMap>): void
W
wusongqing 已提交
806

807
Calls an extended API of the DataAbility. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
808 809 810 811 812 813 814

**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

**Parameters**

| Name      | Type                             | Mandatory| Description                                            |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
815
| uri        | string                 | Yes  | URI of the DataAbility. Example: "dataability:///com.example.xxx.xxxx".          |
W
wusongqing 已提交
816
| method    | string                  | Yes  | Name of the API to call.  |
817
| arg      | string                   | Yes  | Parameter to pass in.     |
W
wusongqing 已提交
818
| extras   | [PacMap](#pacmap)        | Yes  | Key-value pair parameter.      |
819
| callback | AsyncCallback\<[PacMap](#pacmap)> | Yes| Callback used to return the result.    |
W
wusongqing 已提交
820 821 822

**Example**

823
```ts
W
wusongqing 已提交
824 825
import featureAbility from '@ohos.ability.featureAbility';

826 827 828 829 830 831 832 833 834
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.jsapidemo.UserDataAbility"
);
dataAbilityHelper.call("dataability:///com.example.jsapidemo.UserDataAbility",
    "method", "arg", {"key1":"value1"}, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + err);
        return;
    }
W
wusongqing 已提交
835 836 837 838 839 840
    console.info('Operation succeeded: ' + data);
});
```

## DataAbilityHelper.call

841
call(uri: string, method: string, arg: string, extras: PacMap): Promise\<PacMap>
W
wusongqing 已提交
842

843
Calls an extended API of the DataAbility. This API uses a promise to return the result.
W
wusongqing 已提交
844 845 846 847 848 849 850

**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

**Parameters**

| Name      | Type                             | Mandatory| Description                                            |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
851
| uri        | string                 | Yes  | URI of the DataAbility. Example: "dataability:///com.example.xxx.xxxx".          |
W
wusongqing 已提交
852
| method    | string                  | Yes  | Name of the API to call.  |
853
| arg      | string                   | Yes  | Parameter to pass in.     |
W
wusongqing 已提交
854
| extras   | [PacMap](#pacmap)        | Yes  | Key-value pair parameter.      |
855 856 857 858 859 860

**Return value**

| Type| Description|
|------ | ------- |
|Promise\<[PacMap](#pacmap)> | Promise used to return the result.|
W
wusongqing 已提交
861 862 863

**Example**

864
```ts
W
wusongqing 已提交
865 866
import featureAbility from '@ohos.ability.featureAbility';

867 868 869 870 871
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.jsapidemo.UserDataAbility"
);
dataAbilityHelper.call("dataability:///com.example.jsapidemo.UserDataAbility",
    "method", "arg", {"key1":"value1"}).then((data) => {
W
wusongqing 已提交
872
    console.info('Operation succeeded: ' + data);
873 874
}).catch((error) => {
    console.error('Operation failed. Cause: ' + error);
W
wusongqing 已提交
875 876
});
```
877 878 879 880 881

## DataAbilityHelper.executeBatch

executeBatch(uri: string, operations: Array\<DataAbilityOperation>, callback: AsyncCallback\<Array\<DataAbilityResult>>): void;

882
Operates data in the database in batches. This API uses an asynchronous callback to return the result.
883 884 885 886 887

**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

**Parameters**

888 889 890 891 892
| Name       | Type                         | Mandatory| Description                                            |
| ----------| ---------------------------------| ---- | ------------------------------------------------ |
| uri       | string                           | Yes  | URI of the DataAbility. Example: "dataability:///com.example.xxx.xxxx".|
| operations    |  Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)>        | Yes  | An array holding the data operations on the database.  |
| callback      |  AsyncCallback\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>>    | Yes  | Callback used to return the result of each operation in the **DataAbilityResult** array.     |
893 894 895

**Example**

896
```ts
897 898 899 900
import featureAbility from '@ohos.ability.featureAbility';

// Select the operations to be performed on the database according to the DataAbilityOperation array.
let op=new Array();
901 902 903
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.jsapidemo.UserDataAbility"
);
904 905 906 907 908 909 910 911 912 913 914 915 916
dataAbilityHelper.executeBatch("dataability:///com.example.jsapidemo.UserDataAbility", op, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + err);
        return;
    }
    console.info('Operation succeeded: ' + data);
});
```

## DataAbilityHelper.executeBatch

executeBatch(uri: string, operations: Array\<DataAbilityOperation>): Promise\<Array\<DataAbilityResult>>;

917
Operates data in the database in batches. This API uses a promise to return the result.
918 919 920 921 922 923 924

**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

**Parameters**

| Name         | Type                           | Mandatory| Description                                            |
| ----------    | -------------------------------| ---- | ------------------------------------------------ |
925 926
| uri           | string                         | Yes  | URI of the DataAbility. Example: "dataability:///com.example.xxx.xxxx".|
| operations    |  Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)>  | Yes  | An array holding the data operations on the database.  |
927 928 929 930 931

**Return value**

| Type| Description|
|------ | ------- |
932
|Promise\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>> | Promise used to return the result of each operation in the **DataAbilityResult** array.|
933 934 935

**Example**

936
```ts
937 938 939 940
import featureAbility from '@ohos.ability.featureAbility';

// Select the operations to be performed on the database according to the DataAbilityOperation array.
let op=new Array();
941 942 943 944
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
    "dataability:///com.example.jsapidemo.UserDataAbility"
);
dataAbilityHelper.executeBatch("dataability:///com.example.jsapidemo.UserDataAbility", op).then((data) => {
945 946 947 948 949 950 951
    console.info('Operation succeeded: ' + data);
}).catch((error) => {
    console.error('Operation failed. Cause: ' + error);
});

```

W
wusongqing 已提交
952 953
## PacMap

954 955 956 957
[key: string]: number | string | boolean | Array\<string | number | boolean> | null;

**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel

W
wusongqing 已提交
958 959 960
| Name| Type| Mandatory| Description|
| ------ | ------ | ------ | ------ |
| [key: string] | number \| string \| boolean \| Array\<string \| number \| boolean\> \| null | Yes| Data stored in key-value pairs.|