js-apis-inner-ability-dataAbilityHelper.md 39.3 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

G
Gloria 已提交
10 11 12 13 14 15
## Modules to Import

```ts
import ability from '@ohos.ability.ability';
```

W
wusongqing 已提交
16 17 18
## Usage

Import the following modules based on the actual situation before using the current module:
19 20 21
```ts
import ohos_data_ability from '@ohos.data.dataAbility';
import ohos_data_rdb from '@ohos.data.rdb';
W
wusongqing 已提交
22 23
```

W
wusongqing 已提交
24
## DataAbilityHelper.openFile
W
wusongqing 已提交
25

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

G
Gloria 已提交
28
Opens a file with a specified URI. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
29

W
wusongqing 已提交
30
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
31

W
wusongqing 已提交
32
**Parameters**
W
wusongqing 已提交
33

W
wusongqing 已提交
34
| Name    | Type                  | Mandatory| Description                              |
W
wusongqing 已提交
35
| -------- | ---------------------- | ---- | ---------------------------------- |
W
wusongqing 已提交
36
| uri      | string                 | Yes  | URI of the file to open.          |
G
Gloria 已提交
37
| mode     | string                 | Yes  | Mode for opening the file. The value can be **rwt**.           |
W
wusongqing 已提交
38
| callback | AsyncCallback\<number> | Yes  | Callback used to return the file descriptor.|
W
wusongqing 已提交
39

W
wusongqing 已提交
40
**Example**
W
wusongqing 已提交
41

42 43
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
44
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
45
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
46
);
47 48 49
let mode = 'rwt';
DAHelper.openFile('dataability:///com.example.DataAbility', mode, (err) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
50 51 52
});
```

W
wusongqing 已提交
53
## DataAbilityHelper.openFile
W
wusongqing 已提交
54

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

G
Gloria 已提交
57
Opens a file with a specified URI. This API uses a promise to return the result.
W
wusongqing 已提交
58

W
wusongqing 已提交
59
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
60

W
wusongqing 已提交
61
**Parameters**
W
wusongqing 已提交
62

W
wusongqing 已提交
63
| Name| Type  | Mandatory| Description                    |
W
wusongqing 已提交
64
| ---- | ------ | ---- | ------------------------ |
W
wusongqing 已提交
65
| uri  | string | Yes  | URI of the file to open.|
G
Gloria 已提交
66
| mode | string | Yes  | Mode for opening the file. The value can be **rwt**. |
W
wusongqing 已提交
67

W
wusongqing 已提交
68
**Return value**
W
wusongqing 已提交
69

W
wusongqing 已提交
70
| Type            | Description            |
W
wusongqing 已提交
71 72
| ---------------- | ---------------- |
| Promise\<number> | Promise used to return the file descriptor.|
W
wusongqing 已提交
73

W
wusongqing 已提交
74
**Example**
W
wusongqing 已提交
75

76 77
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
78
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
79
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
80
);
81 82 83
let mode = 'rwt';
DAHelper.openFile('dataability:///com.example.DataAbility', mode).then((data) => {
	console.info('==========================>openFileCallback=======================>');
W
wusongqing 已提交
84 85 86
});
```

W
wusongqing 已提交
87
## DataAbilityHelper.on
W
wusongqing 已提交
88

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

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

W
wusongqing 已提交
93
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
94

W
wusongqing 已提交
95
**Parameters**
W
wusongqing 已提交
96

W
wusongqing 已提交
97
| Name    | Type                | Mandatory| Description                    |
W
wusongqing 已提交
98
| -------- | -------------------- | ---- | ------------------------ |
G
Gloria 已提交
99
| type     | string               | Yes  | Event type. The value is **dataChange**.              |
W
wusongqing 已提交
100 101
| uri      | string               | Yes  | URI of the data.|
| callback | AsyncCallback\<void> | Yes  | Callback invoked when the data is changed.  |
W
wusongqing 已提交
102

W
wusongqing 已提交
103
**Example**
W
wusongqing 已提交
104

105 106
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
107
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
108
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
109 110
);
function onChangeNotify() {
111
    console.info('==========================>onChangeNotify=======================>');
W
wusongqing 已提交
112
};
G
Gloria 已提交
113
DAHelper.on(
114 115
    'dataChange',
    'dataability:///com.example.DataAbility',
W
wusongqing 已提交
116
    onChangeNotify
117
);
W
wusongqing 已提交
118 119
```

W
wusongqing 已提交
120
## DataAbilityHelper.off
W
wusongqing 已提交
121

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

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

W
wusongqing 已提交
126
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
127

W
wusongqing 已提交
128
**Parameters**
W
wusongqing 已提交
129

W
wusongqing 已提交
130
| Name    | Type                | Mandatory| Description                    |
W
wusongqing 已提交
131
| -------- | -------------------- | ---- | ------------------------ |
G
Gloria 已提交
132
| type     | string               | Yes  | Event type. The value is **dataChange**.              |
W
wusongqing 已提交
133
| uri      | string               | Yes  | URI of the data.|
G
Gloria 已提交
134
| callback | AsyncCallback\<void> | No  | Callback used to return the result.      |
W
wusongqing 已提交
135

W
wusongqing 已提交
136
**Example**
W
wusongqing 已提交
137

138 139
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
140
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
141
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
142 143
);
function onChangeNotify() {
144
    console.info('==========================>onChangeNotify=======================>');
W
wusongqing 已提交
145
};
G
Gloria 已提交
146
DAHelper.off(
147 148
    'dataChange',
    'dataability:///com.example.DataAbility',
149
);
G
Gloria 已提交
150
DAHelper.off(
151 152 153
    'dataChange',
    'dataability:///com.example.DataAbility',
    onChangeNotify
154
);
W
wusongqing 已提交
155 156
```

W
wusongqing 已提交
157
## DataAbilityHelper.getType
W
wusongqing 已提交
158

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

G
Gloria 已提交
161
Obtains the MIME type of the data specified by a given URI. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
162

W
wusongqing 已提交
163
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
164

W
wusongqing 已提交
165
**Parameters**
W
wusongqing 已提交
166

W
wusongqing 已提交
167
| Name    | Type                  | Mandatory| Description                                         |
W
wusongqing 已提交
168
| -------- | ---------------------- | ---- | --------------------------------------------- |
W
wusongqing 已提交
169
| uri      | string                 | Yes  | URI of the data.                     |
G
Gloria 已提交
170
| callback | AsyncCallback\<string> | Yes  | Callback used to return the MIME type.|
W
wusongqing 已提交
171

W
wusongqing 已提交
172
**Example**
W
wusongqing 已提交
173

174 175
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
176
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
177
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
178
);
179 180
DAHelper.getType('dataability:///com.example.DataAbility', (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
181 182 183
});
```

W
wusongqing 已提交
184
## DataAbilityHelper.getType
W
wusongqing 已提交
185

W
wusongqing 已提交
186
getType(uri: string): Promise\<string>
W
wusongqing 已提交
187

G
Gloria 已提交
188
Obtains the MIME type of the data specified by a given URI. This API uses a promise to return the result.
W
wusongqing 已提交
189

W
wusongqing 已提交
190
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
191

W
wusongqing 已提交
192
**Parameters**
W
wusongqing 已提交
193

W
wusongqing 已提交
194
| Name| Type  | Mandatory| Description                    |
W
wusongqing 已提交
195
| ---- | ------ | ---- | ------------------------ |
W
wusongqing 已提交
196
| uri  | string | Yes  | URI of the data.|
W
wusongqing 已提交
197

W
wusongqing 已提交
198
**Return value**
W
wusongqing 已提交
199

W
wusongqing 已提交
200
| Type            | Description                               |
W
wusongqing 已提交
201
| ---------------- | ----------------------------------- |
G
Gloria 已提交
202
| Promise\<string> | Promise used to return the MIME type.|
W
wusongqing 已提交
203

W
wusongqing 已提交
204
**Example**
W
wusongqing 已提交
205

206 207
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
208
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
209
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
210
);
211 212
DAHelper.getType('dataability:///com.example.DataAbility').then((data) => {
	console.info('==========================>getTypeCallback=======================>');
W
wusongqing 已提交
213 214 215
});
```

W
wusongqing 已提交
216
## DataAbilityHelper.getFileTypes
W
wusongqing 已提交
217

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

G
Gloria 已提交
220
Obtains the supported MIME types of a specified file. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
221

W
wusongqing 已提交
222
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
223

W
wusongqing 已提交
224
**Parameters**
W
wusongqing 已提交
225

W
wusongqing 已提交
226
| Name          | Type                          | Mandatory| Description                              |
W
wusongqing 已提交
227
| -------------- | ------------------------------ | ---- | ---------------------------------- |
W
wusongqing 已提交
228
| uri            | string                         | Yes  | URI of the file.          |
G
Gloria 已提交
229 230
| mimeTypeFilter | string                         | Yes  | MIME types to match.      |
| callback       | AsyncCallback\<Array\<string>> | Yes  | Callback used to return the supported MIME types.|
W
wusongqing 已提交
231

W
wusongqing 已提交
232
**Example**
W
wusongqing 已提交
233

234 235
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
236
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
237
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
238
);
239 240 241
DAHelper.getFileTypes( 'dataability:///com.example.DataAbility',
    'image/*', (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
242 243 244
});
```

245 246


W
wusongqing 已提交
247
## DataAbilityHelper.getFileTypes
W
wusongqing 已提交
248 249

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

G
Gloria 已提交
251
Obtains the supported MIME types of a specified file. This API uses a promise to return the result.
W
wusongqing 已提交
252

W
wusongqing 已提交
253
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
254

W
wusongqing 已提交
255
**Parameters**
W
wusongqing 已提交
256

W
wusongqing 已提交
257
| Name          | Type  | Mandatory| Description                        |
W
wusongqing 已提交
258
| -------------- | ------ | ---- | ---------------------------- |
W
wusongqing 已提交
259
| uri            | string | Yes  | URI of the file.    |
G
Gloria 已提交
260
| mimeTypeFilter | string | Yes  | MIME types to match.|
W
wusongqing 已提交
261

W
wusongqing 已提交
262
**Return value**
W
wusongqing 已提交
263

W
wusongqing 已提交
264
| Type                    | Description                    |
W
wusongqing 已提交
265
| ------------------------ | ------------------------ |
G
Gloria 已提交
266
| Promise\<Array\<string>> | Promise used to return the supported MIME types.|
W
wusongqing 已提交
267

W
wusongqing 已提交
268
**Example**
W
wusongqing 已提交
269

270 271
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
272
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
273
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
274
);
275 276 277
DAHelper.getFileTypes('dataability:///com.example.DataAbility',
    'image/*').then((data) => {
     console.info('===================>getFileTypesCallback================>');
W
wusongqing 已提交
278 279 280
});
```

W
wusongqing 已提交
281
## DataAbilityHelper.normalizeUri
W
wusongqing 已提交
282

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

G
Gloria 已提交
285
Converts the URI that refers to a DataAbility into a normalized URI. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
286

W
wusongqing 已提交
287
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
288

W
wusongqing 已提交
289
**Parameters**
W
wusongqing 已提交
290

W
wusongqing 已提交
291
| Name    | Type                  | Mandatory| Description                                                        |
W
wusongqing 已提交
292
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
293
| uri      | string                 | Yes  | URI object to normalize.                                     |
G
Gloria 已提交
294
| callback | AsyncCallback\<string> | Yes  | Callback used to return the normalized URI object if the DataAbility supports URI normalization. If the DataAbility does not support URI normalization, **null** is returned.|
W
wusongqing 已提交
295

W
wusongqing 已提交
296
**Example**
W
wusongqing 已提交
297

298 299
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
300
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
301
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
302
);
303 304
DAHelper.normalizeUri('dataability:///com.example.DataAbility', (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
305 306 307
});
```

W
wusongqing 已提交
308
## DataAbilityHelper.normalizeUri
W
wusongqing 已提交
309

W
wusongqing 已提交
310
normalizeUri(uri: string): Promise\<string>
W
wusongqing 已提交
311

G
Gloria 已提交
312
Converts the URI that refers to a DataAbility into a normalized URI. This API uses a promise to return the result.
W
wusongqing 已提交
313

W
wusongqing 已提交
314
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
315

W
wusongqing 已提交
316
**Parameters**
W
wusongqing 已提交
317

W
wusongqing 已提交
318
| Name| Type  | Mandatory| Description                   |
W
wusongqing 已提交
319
| ---- | ------ | ---- | ----------------------- |
W
wusongqing 已提交
320
| uri  | string | Yes  | URI object to normalize.|
W
wusongqing 已提交
321

W
wusongqing 已提交
322
**Return value**
W
wusongqing 已提交
323

W
wusongqing 已提交
324
| Type            | Description                                                  |
W
wusongqing 已提交
325
| ---------------- | ------------------------------------------------------ |
G
Gloria 已提交
326
| Promise\<string> | Promise used to return the normalized URI object if the DataAbility supports URI normalization. If the DataAbility does not support URI normalization, **null** is returned.|
W
wusongqing 已提交
327

W
wusongqing 已提交
328
**Example**
W
wusongqing 已提交
329

330 331
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
332
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
333
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
334
);
335 336
DAHelper.normalizeUri('dataability:///com.example.DataAbility',).then((data) => {
    console.info('=================>normalizeUriCallback=======================>');
W
wusongqing 已提交
337 338 339
});
```

W
wusongqing 已提交
340
## DataAbilityHelper.denormalizeUri
W
wusongqing 已提交
341

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

W
wusongqing 已提交
344
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 已提交
345

W
wusongqing 已提交
346
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
347

W
wusongqing 已提交
348
**Parameters**
W
wusongqing 已提交
349

W
wusongqing 已提交
350
| Name    | Type                  | Mandatory| Description                                               |
W
wusongqing 已提交
351
| -------- | ---------------------- | ---- | --------------------------------------------------- |
G
Gloria 已提交
352
| uri      | string                 | Yes  | URI object to normalize.                            |
W
wusongqing 已提交
353
| callback | AsyncCallback\<string> | Yes  | Callback used to return the denormalized URI object.|
W
wusongqing 已提交
354

W
wusongqing 已提交
355
**Example**
W
wusongqing 已提交
356

357 358
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
359
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
360
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
361
);
362 363
DAHelper.denormalizeUri('dataability:///com.example.DataAbility', (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
364 365 366
});
```

367 368


W
wusongqing 已提交
369
## DataAbilityHelper.denormalizeUri
W
wusongqing 已提交
370 371

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

W
wusongqing 已提交
373
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 已提交
374

W
wusongqing 已提交
375
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
376

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

W
wusongqing 已提交
379
| Name| Type  | Mandatory| Description                   |
W
wusongqing 已提交
380
| ---- | ------ | ---- | ----------------------- |
W
wusongqing 已提交
381
| uri  | string | Yes  | URI object to normalize.|
W
wusongqing 已提交
382

W
wusongqing 已提交
383
**Return value**
W
wusongqing 已提交
384

W
wusongqing 已提交
385
| Type            | Description                                     |
W
wusongqing 已提交
386 387
| ---------------- | ----------------------------------------- |
| Promise\<string> | Promise used to return the denormalized URI object.|
W
wusongqing 已提交
388

W
wusongqing 已提交
389
**Example**
W
wusongqing 已提交
390

391 392
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
393
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
394
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
395
);
396 397
DAHelper.denormalizeUri('dataability:///com.example.DataAbility',).then((data) => {
    console.info('===============>denormalizeUriCallback=======================>');
W
wusongqing 已提交
398 399 400
});
```

W
wusongqing 已提交
401
## DataAbilityHelper.notifyChange
W
wusongqing 已提交
402

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

W
wusongqing 已提交
405
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 已提交
406

W
wusongqing 已提交
407
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
408

W
wusongqing 已提交
409
**Parameters**
W
wusongqing 已提交
410

W
wusongqing 已提交
411
| Name    | Type                | Mandatory| Description                    |
W
wusongqing 已提交
412
| -------- | -------------------- | ---- | ------------------------ |
G
Gloria 已提交
413
| uri      | string               | Yes  | URI of the data.|
W
wusongqing 已提交
414
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.              |
W
wusongqing 已提交
415

W
wusongqing 已提交
416
**Example**
W
wusongqing 已提交
417

418 419
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
420
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
421
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
422
);
G
Gloria 已提交
423
DAHelper.notifyChange('dataability:///com.example.DataAbility', (err) => {
424
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
425 426 427
});
```

W
wusongqing 已提交
428
## DataAbilityHelper.notifyChange
W
wusongqing 已提交
429

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

W
wusongqing 已提交
432
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 已提交
433

W
wusongqing 已提交
434
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
435

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

W
wusongqing 已提交
438
| Name| Type  | Mandatory| Description                    |
W
wusongqing 已提交
439
| ---- | ------ | ---- | ------------------------ |
G
Gloria 已提交
440
| uri  | string | Yes  | URI of the data.|
W
wusongqing 已提交
441

W
wusongqing 已提交
442
**Return value**
W
wusongqing 已提交
443

W
wusongqing 已提交
444
| Type          | Description                 |
W
wusongqing 已提交
445 446
| -------------- | --------------------- |
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
447

W
wusongqing 已提交
448
**Example**
W
wusongqing 已提交
449

450 451
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
452
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
453
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
454
);
455 456
DAHelper.notifyChange('dataability:///com.example.DataAbility').then(() => {
    console.info('================>notifyChangeCallback================>');
W
wusongqing 已提交
457 458 459
});
```

W
wusongqing 已提交
460
## DataAbilityHelper.insert
W
wusongqing 已提交
461

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

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

W
wusongqing 已提交
466
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
467

W
wusongqing 已提交
468
**Parameters**
W
wusongqing 已提交
469

W
wusongqing 已提交
470
| Name        | Type                  | Mandatory| Description                                                  |
W
wusongqing 已提交
471
| ------------ | ---------------------- | ---- | ------------------------------------------------------ |
W
wusongqing 已提交
472 473 474
| 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 已提交
475

W
wusongqing 已提交
476
**Example**
W
wusongqing 已提交
477

478 479
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
480
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
481
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
482 483
);
const valueBucket = {
484 485 486 487
    'name': 'rose',
    'age': 22,
    'salary': 200.5,
    'blobType': 'u8',
488
};
489 490 491
DAHelper.insert('dataability:///com.example.DataAbility', valueBucket,
    (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
492 493 494
});
```

W
wusongqing 已提交
495
## DataAbilityHelper.insert
W
wusongqing 已提交
496

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

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

W
wusongqing 已提交
501
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
502

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

W
wusongqing 已提交
505
| Name        | Type            | Mandatory| Description                                                  |
W
wusongqing 已提交
506
| ------------ | ---------------- | ---- | ------------------------------------------------------ |
W
wusongqing 已提交
507 508
| 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 已提交
509

W
wusongqing 已提交
510
**Return value**
W
wusongqing 已提交
511

W
wusongqing 已提交
512
| Type            | Description                    |
W
wusongqing 已提交
513 514
| ---------------- | ------------------------ |
| Promise\<number> | Promise used to return the index of the inserted data record.|
W
wusongqing 已提交
515

W
wusongqing 已提交
516
**Example**
W
wusongqing 已提交
517

518 519
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
520
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
521
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
522 523
);
const valueBucket = {
524 525 526 527
    'name': 'rose1',
    'age': 221,
    'salary': 20.5,
    'blobType': 'u8',
528
};
529 530
DAHelper.insert('dataability:///com.example.DataAbility', valueBucket).then((data) => {
    console.info('====================>insertCallback=======================>');
W
wusongqing 已提交
531 532 533
});
```

W
wusongqing 已提交
534
## DataAbilityHelper.batchInsert
W
wusongqing 已提交
535

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

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

W
wusongqing 已提交
540
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
541

W
wusongqing 已提交
542
**Parameters**
W
wusongqing 已提交
543

W
wusongqing 已提交
544
| Name        | Type                   | Mandatory| Description                            |
W
wusongqing 已提交
545
| ------------ | ----------------------- | ---- | -------------------------------- |
W
wusongqing 已提交
546
| uri          | string                  | Yes  | URI of the data to insert.        |
G
Gloria 已提交
547
| valuesBucket | Array\<rdb.ValuesBucket> | Yes  | Data record to insert.          |
W
wusongqing 已提交
548
| callback     | AsyncCallback\<number>  | Yes  | Callback used to return the number of inserted data records.|
W
wusongqing 已提交
549

W
wusongqing 已提交
550
**Example**
W
wusongqing 已提交
551

552 553
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
554
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
555
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
556
);
557 558 559 560 561 562
let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',},
                     {'name': 'roe12', 'age': 21, 'salary': 20.5, 'blobType': 'u8',},
                     {'name': 'roe13', 'age': 21, 'salary': 20.5, 'blobType': 'u8',});
DAHelper.batchInsert('dataability:///com.example.DataAbility', cars,
    (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
563 564 565
});
```

W
wusongqing 已提交
566
## DataAbilityHelper.batchInsert
W
wusongqing 已提交
567

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

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

W
wusongqing 已提交
572
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
573

W
wusongqing 已提交
574
**Parameters**
W
wusongqing 已提交
575

W
wusongqing 已提交
576
| Name        | Type                   | Mandatory| Description                    |
W
wusongqing 已提交
577
| ------------ | ----------------------- | ---- | ------------------------ |
W
wusongqing 已提交
578
| uri          | string                  | Yes  | URI of the data to insert.|
G
Gloria 已提交
579
| valuesBucket | Array<rdb.ValuesBucket> | Yes  | Data record to insert.  |
W
wusongqing 已提交
580

W
wusongqing 已提交
581
**Return value**
W
wusongqing 已提交
582

W
wusongqing 已提交
583
| Type            | Description                  |
W
wusongqing 已提交
584 585
| ---------------- | ---------------------- |
| Promise\<number> | Promise used to return the number of inserted data records.|
W
wusongqing 已提交
586

W
wusongqing 已提交
587
**Example**
W
wusongqing 已提交
588

589 590
```ts
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
591
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
592
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
593
);
594 595 596 597 598
let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',},
                     {'name': 'roe12', 'age': 21, 'salary': 20.5, 'blobType': 'u8',},
                     {'name': 'roe13', 'age': 21, 'salary': 20.5, 'blobType': 'u8',});
DAHelper.batchInsert('dataability:///com.example.DataAbility', cars).then((data) => {
    console.info('==================>batchInsertCallback=======================>');
W
wusongqing 已提交
599 600 601
});
```

W
wusongqing 已提交
602
## DataAbilityHelper.delete
W
wusongqing 已提交
603

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

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

W
wusongqing 已提交
608
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
609

W
wusongqing 已提交
610
**Parameters**
W
wusongqing 已提交
611

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

W
wusongqing 已提交
618
**Example**
W
wusongqing 已提交
619

620 621 622
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
G
Gloria 已提交
623
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
624
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
625
);
626
let da = new ohos_data_ability.DataAbilityPredicates();
627 628 629
DAHelper.delete('dataability:///com.example.DataAbility', da,
    (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
630 631 632
});
```

W
wusongqing 已提交
633
## DataAbilityHelper.delete
W
wusongqing 已提交
634

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

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

W
wusongqing 已提交
639
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
640

W
wusongqing 已提交
641
**Parameters**
W
wusongqing 已提交
642

W
wusongqing 已提交
643
| Name        | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
644
| ------------ | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
645
| uri          | string                            | Yes  | URI of the data to delete.                        |
646
| predicates | dataAbility.DataAbilityPredicates | No  | Filter criteria. You should define the processing logic when this parameter is **null**.|
W
wusongqing 已提交
647

W
wusongqing 已提交
648
**Return value**
W
wusongqing 已提交
649

W
wusongqing 已提交
650
| Type            | Description                    |
W
wusongqing 已提交
651 652
| ---------------- | ------------------------ |
| Promise\<number> | Promise used to return the number of deleted data records.|
W
wusongqing 已提交
653

W
wusongqing 已提交
654
**Example**
W
wusongqing 已提交
655

656 657 658
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
G
Gloria 已提交
659
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
660
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
661
);
662
let da = new ohos_data_ability.DataAbilityPredicates();
663 664
DAHelper.delete('dataability:///com.example.DataAbility', da).then((data) => {
    console.info('==========================>deleteCallback=======================>');
W
wusongqing 已提交
665 666 667
});
```

W
wusongqing 已提交
668
## DataAbilityHelper.update
W
wusongqing 已提交
669

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

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

W
wusongqing 已提交
674
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
675

W
wusongqing 已提交
676
**Parameters**
W
wusongqing 已提交
677

W
wusongqing 已提交
678
| Name        | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
679
| ------------ | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
680 681 682 683
| 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 已提交
684

W
wusongqing 已提交
685
**Example**
W
wusongqing 已提交
686

687 688 689
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
G
Gloria 已提交
690
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
691
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
692 693
);
const va = {
694 695 696 697
    'name': 'roe1',
    'age': 21,
    'salary': 20.5,
    'blobType': 'u8',
698 699
};
let da = new ohos_data_ability.DataAbilityPredicates();
700 701
DAHelper.update('dataability:///com.example.DataAbility', va, da, (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
702 703 704
});
```

W
wusongqing 已提交
705
## DataAbilityHelper.update
W
wusongqing 已提交
706

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

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

W
wusongqing 已提交
711
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
712

W
wusongqing 已提交
713
**Parameters**
W
wusongqing 已提交
714

W
wusongqing 已提交
715
| Name        | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
716
| ------------ | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
717 718
| uri          | string                            | Yes  | URI of the data to update.                        |
| valuesBucket | rdb.ValuesBucket                  | Yes  | New values.                              |
719
| predicates   | dataAbility.DataAbilityPredicates | No  | Filter criteria. You should define the processing logic when this parameter is **null**.|
W
wusongqing 已提交
720

W
wusongqing 已提交
721
**Return value**
W
wusongqing 已提交
722

W
wusongqing 已提交
723
| Type            | Description                                        |
W
wusongqing 已提交
724
| ---------------- | -------------------------------------------- |
W
wusongqing 已提交
725
| Promise\<number> | Promise used to return the number of updated data records.  |
W
wusongqing 已提交
726

W
wusongqing 已提交
727
**Example**
W
wusongqing 已提交
728

729 730 731
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
G
Gloria 已提交
732
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
733
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
734 735
);
const va = {
736 737 738 739
    'name': 'roe1',
    'age': 21,
    'salary': 20.5,
    'blobType': 'u8',
740 741
};
let da = new ohos_data_ability.DataAbilityPredicates();
742 743
DAHelper.update('dataability:///com.example.DataAbility', va, da).then((data) => {
    console.info('==========================>updateCallback=======================>');
W
wusongqing 已提交
744 745 746
});
```

W
wusongqing 已提交
747
## DataAbilityHelper.query
W
wusongqing 已提交
748

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

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

W
wusongqing 已提交
753
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
754

W
wusongqing 已提交
755
**Parameters**
W
wusongqing 已提交
756

W
wusongqing 已提交
757
| Name      | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
758
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
759
| uri        | string                            | Yes  | URI of the data to query.                        |
760
| columns    | Array\<string>                | Yes  | Columns to query. If this parameter is **null**, all columns will be queried.  |
W
wusongqing 已提交
761 762
| 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 已提交
763

W
wusongqing 已提交
764
**Example**
W
wusongqing 已提交
765

766 767 768
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
G
Gloria 已提交
769
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
770
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
771
);
772
let cars=new Array('value1', 'value2', 'value3', 'value4');
773
let da = new ohos_data_ability.DataAbilityPredicates();
774 775
DAHelper.query('dataability:///com.example.DataAbility', cars, da, (err, data) => {
    console.info('==========================>Called=======================>');
W
wusongqing 已提交
776 777 778 779 780
});
```



W
wusongqing 已提交
781
## DataAbilityHelper.query
W
wusongqing 已提交
782

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

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

W
wusongqing 已提交
787
**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
W
wusongqing 已提交
788

W
wusongqing 已提交
789
**Parameters**
W
wusongqing 已提交
790

W
wusongqing 已提交
791
| Name      | Type                             | Mandatory| Description                                            |
W
wusongqing 已提交
792
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
W
wusongqing 已提交
793
| uri        | string                            | Yes  | URI of the data to query.                        |
794 795
| 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 已提交
796

W
wusongqing 已提交
797
**Return value**
W
wusongqing 已提交
798

W
wusongqing 已提交
799
| Type               | Description          |
W
wusongqing 已提交
800 801
| ------------------- | -------------- |
| Promise\<ResultSet> | Promise used to return the data queried.|
W
wusongqing 已提交
802

W
wusongqing 已提交
803
**Example**
W
wusongqing 已提交
804

805 806 807
```ts
import featureAbility from '@ohos.ability.featureAbility';
import ohos_data_ability from '@ohos.data.dataAbility';
G
Gloria 已提交
808
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
809
    'dataability:///com.example.DataAbility'
W
wusongqing 已提交
810
);
811
let cars = new Array('value1', 'value2', 'value3', 'value4');
812
let da = new ohos_data_ability.DataAbilityPredicates();
813
DAHelper.query('dataability:///com.example.DataAbility', cars, da).then((data) => {
G
Gloria 已提交
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
    console.info('query data: ${JSON.stringify(data)}');
});
```

## DataAbilityHelper.call

call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback\<PacMap>): void

Calls an extended API of the DataAbility. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name      | Type                             | Mandatory| Description                                            |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
| uri        | string                 | Yes  | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.          |
| method    | string                  | Yes  | Name of the API to call.  |
| arg      | string                   | Yes  | Parameter to pass in.     |
| extras   | [PacMap](#pacmap)        | Yes  | Key-value pair parameter.      |
| callback | AsyncCallback\<[PacMap](#pacmap)> | Yes| Callback used to return the result.    |

**Example**

```ts
import featureAbility from '@ohos.ability.featureAbility';

let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
    'dataability:///com.example.jsapidemo.UserDataAbility'
);
dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility',
    'method', 'arg', {'key1':'value1'}, (error, data) => {
    if (error && error.code !== 0) {
        console.error('call fail, error: ${JSON.stringify(error)}');
    } else {
        console.log('call success, data: ${JSON.stringify(data)}');
    }
W
wusongqing 已提交
851 852
});
```
W
wusongqing 已提交
853 854 855

## DataAbilityHelper.call

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

858
Calls an extended API of the DataAbility. This API uses a promise to return the result.
W
wusongqing 已提交
859 860 861 862 863 864 865

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

**Parameters**

| Name      | Type                             | Mandatory| Description                                            |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
866
| uri        | string                 | Yes  | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.          |
W
wusongqing 已提交
867
| method    | string                  | Yes  | Name of the API to call.  |
G
Gloria 已提交
868
| arg      | string                   | Yes  |Parameter to pass in.     |
W
wusongqing 已提交
869
| extras   | [PacMap](#pacmap)        | Yes  | Key-value pair parameter.      |
870 871 872 873 874 875

**Return value**

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

**Example**

879
```ts
W
wusongqing 已提交
880 881
import featureAbility from '@ohos.ability.featureAbility';

G
Gloria 已提交
882 883 884
let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
    'dataability:///com.example.jsapidemo.UserDataAbility'
);
885 886
dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility',
    'method', 'arg', {'key1':'value1'}).then((data) => {
W
wusongqing 已提交
887
    console.info('Operation succeeded: ' + data);
888 889
}).catch((error) => {
    console.error('Operation failed. Cause: ' + error);
W
wusongqing 已提交
890 891 892 893 894
});
```

## DataAbilityHelper.call

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

897
Calls an extended API of the DataAbility. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
898 899 900 901 902 903 904

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

**Parameters**

| Name      | Type                             | Mandatory| Description                                            |
| ---------- | --------------------------------- | ---- | ------------------------------------------------ |
905
| uri        | string                 | Yes  | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.          |
W
wusongqing 已提交
906
| method    | string                  | Yes  | Name of the API to call.  |
G
Gloria 已提交
907
| arg      | string                   | Yes  |Parameter to pass in.     |
W
wusongqing 已提交
908
| extras   | [PacMap](#pacmap)        | Yes  | Key-value pair parameter.      |
G
Gloria 已提交
909
| callback | AsyncCallback\<[PacMap](#pacmap)> | Yes| Callback used to return the result.    |
W
wusongqing 已提交
910 911 912

**Example**

913
```ts
W
wusongqing 已提交
914 915
import featureAbility from '@ohos.ability.featureAbility';

916
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
917 918 919 920 921 922 923
    '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 已提交
924 925 926
    console.info('Operation succeeded: ' + data);
});
```
927 928 929 930 931

## DataAbilityHelper.executeBatch

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

932
Operates data in the database in batches. This API uses an asynchronous callback to return the result.
933 934 935 936 937

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

**Parameters**

G
Gloria 已提交
938 939 940 941
| 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.  |
942
| callback      |  AsyncCallback\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>>    | Yes  | Callback used to return the result of each operation in the **DataAbilityResult** array.     |
943 944 945

**Example**

946
```ts
947 948 949 950
import featureAbility from '@ohos.ability.featureAbility';

// Select the operations to be performed on the database according to the DataAbilityOperation array.
let op=new Array();
G
Gloria 已提交
951 952 953 954 955 956 957 958
let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
    'dataability:///com.example.jsapidemo.UserDataAbility'
);
dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', op, (error, data) => {
    if (error && error.code !== 0) {
        console.error('executeBatch fail, error: ${JSON.stringify(error)}');
    } else {
        console.log('executeBatch success, data: ${JSON.stringify(data)}');
959 960 961 962 963 964 965 966 967
    }
    console.info('Operation succeeded: ' + data);
});
```

## DataAbilityHelper.executeBatch

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

968
Operates data in the database in batches. This API uses a promise to return the result.
969 970 971 972 973 974 975

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

**Parameters**

| Name         | Type                           | Mandatory| Description                                            |
| ----------    | -------------------------------| ---- | ------------------------------------------------ |
976
| uri           | string                         | Yes  | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.|
977
| operations    |  Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)>  | Yes  | An array holding the data operations on the database.  |
978 979 980 981 982

**Return value**

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

**Example**

987
```ts
988 989 990 991
import featureAbility from '@ohos.ability.featureAbility';

// Select the operations to be performed on the database according to the DataAbilityOperation array.
let op=new Array();
G
Gloria 已提交
992 993 994 995 996
let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(
    'dataability:///com.example.jsapidemo.UserDataAbility'
);
dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', op).then((data) => {
    console.info('executeBatch success, data: ${data}');
997 998 999 1000 1001 1002
}).catch((error) => {
    console.error('Operation failed. Cause: ' + error);
});

```

W
wusongqing 已提交
1003 1004
## PacMap

1005 1006 1007 1008
[key: string]: number | string | boolean | Array\<string | number | boolean> | null;

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

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