1# DataAbilityHelper 2 3The **DataAbilityHelper** object is obtained through [acquireDataAbilityHelper](js-apis-ability-featureAbility.md#featureabilityacquiredataabilityhelper7). 4 5> **NOTE** 6> 7> 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. 8> 9> Except [PacMap](js-apis-inner-ability-dataAbilityHelper.md#pacmap), the APIs of this module can be used only in the FA model. 10 11## Modules to Import 12 13```ts 14import ability from '@ohos.ability.ability'; 15``` 16 17## Usage 18 19Import the following modules based on the actual situation before using the current module: 20```ts 21import ohos_data_ability from '@ohos.data.dataAbility'; 22import relationalStore from '@ohos.data.relationalStore'; 23``` 24 25## DataAbilityHelper.openFile 26 27openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void 28 29Opens a file with a specified URI. This API uses an asynchronous callback to return the result. 30 31**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 32 33**Model restriction**: This API can be used only in the FA model. 34 35**Parameters** 36 37| Name | Type | Mandatory| Description | 38| -------- | ---------------------- | ---- | ---------------------------------- | 39| uri | string | Yes | URI of the file to open. | 40| 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. | 41| callback | AsyncCallback\<number> | Yes | Callback used to return the file descriptor.| 42 43**Example** 44 45<!--code_no_check_fa--> 46```ts 47import ability from '@ohos.ability.ability'; 48import featureAbility from '@ohos.ability.featureAbility'; 49 50let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 51 'dataability:///com.example.DataAbility' 52); 53let mode = 'rw'; 54DAHelper.openFile('dataability:///com.example.DataAbility', mode, (error, data) => { 55 if (error && error.code !== 0) { 56 console.error(`openFile fail, error: ${JSON.stringify(error)}`); 57 } else { 58 console.log(`openFile success, data: ${JSON.stringify(data)}`); 59 } 60}); 61``` 62 63## DataAbilityHelper.openFile 64 65openFile(uri: string, mode: string): Promise\<number> 66 67Opens a file with a specified URI. This API uses a promise to return the result. 68 69**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 70 71**Model restriction**: This API can be used only in the FA model. 72 73**Parameters** 74 75| Name| Type | Mandatory| Description | 76| ---- | ------ | ---- | ------------------------ | 77| uri | string | Yes | URI of the file to open.| 78| 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. | 79 80**Return value** 81 82| Type | Description | 83| ---------------- | ---------------- | 84| Promise\<number> | Promise used to return the file descriptor.| 85 86**Example** 87 88<!--code_no_check_fa--> 89```ts 90import ability from '@ohos.ability.ability'; 91import featureAbility from '@ohos.ability.featureAbility'; 92 93let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 94 'dataability:///com.example.DataAbility' 95); 96let mode = 'rw'; 97DAHelper.openFile('dataability:///com.example.DataAbility', mode).then((data) => { 98 console.info(`openFile data: ${JSON.stringify(data)}`); 99}); 100``` 101 102## DataAbilityHelper.on('dataChange') 103 104on(type: 'dataChange', uri: string, callback: AsyncCallback\<void>): void 105 106Registers an observer to listen for changes in the data specified by a given URI. This API uses an asynchronous callback to return the result. 107 108**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 109 110**Model restriction**: This API can be used only in the FA model. 111 112**Parameters** 113 114| Name | Type | Mandatory| Description | 115| -------- | -------------------- | ---- | ------------------------ | 116| type | string | Yes | The value **'dataChange'** means data changes. | 117| uri | string | Yes | URI of the data.| 118| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the observer is registered, **err** is **undefined**. Otherwise, **err** is an error object. | 119 120**Example** 121 122<!--code_no_check_fa--> 123```ts 124import ability from '@ohos.ability.ability'; 125import featureAbility from '@ohos.ability.featureAbility'; 126 127let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 128 'dataability:///com.example.DataAbility' 129); 130function onChangeNotify() { 131 console.info('onChangeNotify call back'); 132}; 133DAHelper.on( 134 'dataChange', 135 'dataability:///com.example.DataAbility', 136 onChangeNotify 137); 138``` 139 140## DataAbilityHelper.off('dataChange') 141 142off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>): void 143 144Deregisters the observer that listens for changes in the data specified by a given URI. This API uses an asynchronous callback to return the result. 145 146**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 147 148**Model restriction**: This API can be used only in the FA model. 149 150**Parameters** 151 152| Name | Type | Mandatory| Description | 153| -------- | -------------------- | ---- | ------------------------ | 154| type | string | Yes | The value **'dataChange'** means data changes. | 155| uri | string | Yes | URI of the data.| 156| callback | AsyncCallback\<void> | No | Callback used to return the result. If the observer is deregistered, **err** is **undefined**. Otherwise, **err** is an error object. | 157 158**Example** 159 160<!--code_no_check_fa--> 161```ts 162import ability from '@ohos.ability.ability'; 163import featureAbility from '@ohos.ability.featureAbility'; 164 165let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 166 'dataability:///com.example.DataAbility' 167); 168function onChangeNotify() { 169 console.info('onChangeNotify call back'); 170}; 171DAHelper.off( 172 'dataChange', 173 'dataability:///com.example.DataAbility', 174 onChangeNotify 175); 176DAHelper.off( 177 'dataChange', 178 'dataability:///com.example.DataAbility', 179); 180``` 181 182## DataAbilityHelper.getType 183 184getType(uri: string, callback: AsyncCallback\<string>): void 185 186Obtains the media resource type of the data specified by a given URI. This API uses an asynchronous callback to return the result. 187 188**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 189 190**Model restriction**: This API can be used only in the FA model. 191 192**Parameters** 193 194| Name | Type | Mandatory| Description | 195| -------- | ---------------------- | ---- | --------------------------------------------- | 196| uri | string | Yes | URI of the data. | 197| callback | AsyncCallback\<string> | Yes | Callback used to return the media resource type.| 198 199**Example** 200 201<!--code_no_check_fa--> 202```ts 203import ability from '@ohos.ability.ability'; 204import featureAbility from '@ohos.ability.featureAbility'; 205 206let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 207 'dataability:///com.example.DataAbility' 208); 209DAHelper.getType('dataability:///com.example.DataAbility', (error, data) => { 210 if (error && error.code !== 0) { 211 console.error(`getType fail, error: ${JSON.stringify(error)}`); 212 } else { 213 console.log(`getType success, data: ${JSON.stringify(data)}`); 214 } 215}); 216``` 217 218## DataAbilityHelper.getType 219 220getType(uri: string): Promise\<string> 221 222Obtains the media resource type of the data specified by a given URI. This API uses a promise to return the result. 223 224**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 225 226**Model restriction**: This API can be used only in the FA model. 227 228**Parameters** 229 230| Name| Type | Mandatory| Description | 231| ---- | ------ | ---- | ------------------------ | 232| uri | string | Yes | URI of the data.| 233 234**Return value** 235 236| Type | Description | 237| ---------------- | ----------------------------------- | 238| Promise\<string> | Promise used to return the media resource type.| 239 240**Example** 241 242<!--code_no_check_fa--> 243```ts 244import ability from '@ohos.ability.ability'; 245import featureAbility from '@ohos.ability.featureAbility'; 246 247let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 248 'dataability:///com.example.DataAbility' 249); 250DAHelper.getType('dataability:///com.example.DataAbility').then((data) => { 251 console.info(`getType data: ${JSON.stringify(data)}`); 252}); 253``` 254 255## DataAbilityHelper.getFileTypes 256 257getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): void 258 259Obtains the supported media resource types of a specified file. This API uses an asynchronous callback to return the result. 260 261**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 262 263**Model restriction**: This API can be used only in the FA model. 264 265**Parameters** 266 267| Name | Type | Mandatory| Description | 268| -------------- | ------------------------------ | ---- | ---------------------------------- | 269| uri | string | Yes | URI of the file. | 270| mimeTypeFilter | string | Yes | Media resource type of the file to obtain. | 271| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return an array holding the media resource types.| 272 273**Example** 274 275<!--code_no_check_fa--> 276```ts 277import ability from '@ohos.ability.ability'; 278import featureAbility from '@ohos.ability.featureAbility'; 279 280let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 281 'dataability:///com.example.DataAbility' 282); 283DAHelper.getFileTypes( 'dataability:///com.example.DataAbility', 'image/*', (error, data) => { 284 if (error && error.code !== 0) { 285 console.error(`getFileTypes fail, error: ${JSON.stringify(error)}`); 286 } else { 287 console.log(`getFileTypes success, data: ${JSON.stringify(data)}`); 288 } 289}); 290``` 291 292## DataAbilityHelper.getFileTypes 293 294getFileTypes(uri: string, mimeTypeFilter: string): Promise\<Array\<string>> 295 296Obtains the supported media resource types of a specified file. This API uses a promise to return the result. 297 298**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 299 300**Model restriction**: This API can be used only in the FA model. 301 302**Parameters** 303 304| Name | Type | Mandatory| Description | 305| -------------- | ------ | ---- | ---------------------------- | 306| uri | string | Yes | URI of the file. | 307| mimeTypeFilter | string | Yes | Media resource type of the file to obtain.| 308 309**Return value** 310 311| Type | Description | 312| ------------------------ | ------------------------ | 313| Promise\<Array\<string>> | Promise used to return an array holding the media resource types.| 314 315**Example** 316 317<!--code_no_check_fa--> 318```ts 319import ability from '@ohos.ability.ability'; 320import featureAbility from '@ohos.ability.featureAbility'; 321 322let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 323 'dataability:///com.example.DataAbility' 324); 325DAHelper.getFileTypes('dataability:///com.example.DataAbility', 'image/*').then((data) => { 326 console.info(`getFileTypes data: ${JSON.stringify(data)}`); 327}); 328``` 329 330## DataAbilityHelper.normalizeUri 331 332normalizeUri(uri: string, callback: AsyncCallback\<string>): void 333 334Converts the URI that refers to a DataAbility into a normalized URI. This API uses an asynchronous callback to return the result. 335 336**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 337 338**Model restriction**: This API can be used only in the FA model. 339 340**Parameters** 341 342| Name | Type | Mandatory| Description | 343| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 344| uri | string | Yes | URI object to normalize. | 345| 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.| 346 347**Example** 348 349<!--code_no_check_fa--> 350```ts 351import ability from '@ohos.ability.ability'; 352import featureAbility from '@ohos.ability.featureAbility'; 353 354let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 355 'dataability:///com.example.DataAbility' 356); 357DAHelper.normalizeUri('dataability:///com.example.DataAbility', (error, data) => { 358 if (error && error.code !== 0) { 359 console.error(`normalizeUri fail, error: ${JSON.stringify(error)}`); 360 } else { 361 console.log(`normalizeUri success, data: ${JSON.stringify(data)}`); 362 } 363}); 364``` 365 366## DataAbilityHelper.normalizeUri 367 368normalizeUri(uri: string): Promise\<string> 369 370Converts the URI that refers to a DataAbility into a normalized URI. This API uses a promise to return the result. 371 372**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 373 374**Model restriction**: This API can be used only in the FA model. 375 376**Parameters** 377 378| Name| Type | Mandatory| Description | 379| ---- | ------ | ---- | ----------------------- | 380| uri | string | Yes | URI object to normalize.| 381 382**Return value** 383 384| Type | Description | 385| ---------------- | ------------------------------------------------------ | 386| 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.| 387 388**Example** 389 390<!--code_no_check_fa--> 391```ts 392import ability from '@ohos.ability.ability'; 393import featureAbility from '@ohos.ability.featureAbility'; 394 395let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 396 'dataability:///com.example.DataAbility' 397); 398DAHelper.normalizeUri('dataability:///com.example.DataAbility',).then((data) => { 399 console.info(`normalizeUri data: ${JSON.stringify(data)}`); 400}); 401``` 402 403## DataAbilityHelper.denormalizeUri 404 405denormalizeUri(uri: string, callback: AsyncCallback\<string>): void 406 407Converts a normalized URI generated by **normalizeUri** to a denormalized one. This API uses an asynchronous callback to return the result. 408 409**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 410 411**Model restriction**: This API can be used only in the FA model. 412 413**Parameters** 414 415| Name | Type | Mandatory| Description | 416| -------- | ---------------------- | ---- | --------------------------------------------------- | 417| uri | string | Yes | URI object to denormalize. | 418| callback | AsyncCallback\<string> | Yes | Callback used to return the denormalized URI object.| 419 420**Example** 421 422<!--code_no_check_fa--> 423```ts 424import ability from '@ohos.ability.ability'; 425import featureAbility from '@ohos.ability.featureAbility'; 426 427let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 428 'dataability:///com.example.DataAbility' 429); 430DAHelper.denormalizeUri('dataability:///com.example.DataAbility', (error, data) => { 431 if (error && error.code !== 0) { 432 console.error(`denormalizeUri fail, error: ${JSON.stringify(error)}`); 433 } else { 434 console.log(`denormalizeUri success, data: ${JSON.stringify(data)}`); 435 } 436}); 437``` 438 439## DataAbilityHelper.denormalizeUri 440 441denormalizeUri(uri: string): Promise\<string> 442 443Converts a normalized URI generated by **normalizeUri** to a denormalized one. This API uses a promise to return the result. 444 445**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 446 447**Model restriction**: This API can be used only in the FA model. 448 449**Parameters** 450 451| Name| Type | Mandatory| Description | 452| ---- | ------ | ---- | ----------------------- | 453| uri | string | Yes | URI object to normalize.| 454 455**Return value** 456 457| Type | Description | 458| ---------------- | ----------------------------------------- | 459| Promise\<string> |Promise used to return the denormalized URI object.| 460 461**Example** 462 463<!--code_no_check_fa--> 464```ts 465import ability from '@ohos.ability.ability'; 466import featureAbility from '@ohos.ability.featureAbility'; 467 468let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 469 'dataability:///com.example.DataAbility' 470); 471DAHelper.denormalizeUri('dataability:///com.example.DataAbility',).then((data) => { 472 console.info(`denormalizeUri data: ${JSON.stringify(data)}`); 473}); 474``` 475 476## DataAbilityHelper.notifyChange 477 478notifyChange(uri: string, callback: AsyncCallback\<void>): void 479 480Notifies the registered observer of a change to the data specified by the URI. This API uses an asynchronous callback to return the result. 481 482**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 483 484**Model restriction**: This API can be used only in the FA model. 485 486**Parameters** 487 488| Name | Type | Mandatory| Description | 489| -------- | -------------------- | ---- | ------------------------ | 490| uri | string | Yes | URI of the data that changes.| 491| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the observer is registered, **err** is **undefined**. Otherwise, **err** is an error object. | 492 493**Example** 494 495<!--code_no_check_fa--> 496```ts 497import ability from '@ohos.ability.ability'; 498import featureAbility from '@ohos.ability.featureAbility'; 499 500let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 501 'dataability:///com.example.DataAbility' 502); 503DAHelper.notifyChange('dataability:///com.example.DataAbility', (error) => { 504 if (error && error.code !== 0) { 505 console.error(`notifyChange fail, error: ${JSON.stringify(error)}`); 506 } else { 507 console.log('notifyChange success'); 508 } 509}); 510``` 511 512## DataAbilityHelper.notifyChange 513 514notifyChange(uri: string): Promise\<void> 515 516Notifies the registered observer of a change to the data specified by the URI. This API uses a promise to return the result. 517 518**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 519 520**Model restriction**: This API can be used only in the FA model. 521 522**Parameters** 523 524| Name| Type | Mandatory| Description | 525| ---- | ------ | ---- | ------------------------ | 526| uri | string | Yes | URI of the data that changes.| 527 528**Return value** 529 530| Type | Description | 531| -------------- | --------------------- | 532| Promise\<void> | Promise that returns no value.| 533 534**Example** 535 536<!--code_no_check_fa--> 537```ts 538import ability from '@ohos.ability.ability'; 539import featureAbility from '@ohos.ability.featureAbility'; 540 541let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 542 'dataability:///com.example.DataAbility' 543); 544DAHelper.notifyChange('dataability:///com.example.DataAbility').then(() => { 545 console.info('================>notifyChangeCallback================>'); 546}); 547``` 548 549## DataAbilityHelper.insert 550 551insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\<number>): void 552 553Inserts a single data record into the database. This API uses an asynchronous callback to return the result. 554 555**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 556 557**Model restriction**: This API can be used only in the FA model. 558 559**Parameters** 560 561| Name | Type | Mandatory| Description | 562| ------------ | ---------------------- | ---- | ------------------------------------------------------ | 563| uri | string | Yes | URI of the data to insert. | 564| valuesBucket | rdb.ValuesBucket | Yes | Data record to insert. If this parameter is **null**, a blank row will be inserted.| 565| callback | AsyncCallback\<number> | Yes | Callback used to return the index of the inserted data record. | 566 567**Example** 568 569<!--code_no_check_fa--> 570```ts 571import ability from '@ohos.ability.ability'; 572import featureAbility from '@ohos.ability.featureAbility'; 573import rdb from '@ohos.data.rdb'; 574 575let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 576 'dataability:///com.example.DataAbility' 577); 578const valueBucket: rdb.ValuesBucket = { 579 'name': 'rose', 580 'age': 22, 581 'salary': 200.5, 582 'blobType': 'u8', 583}; 584DAHelper.insert('dataability:///com.example.DataAbility', valueBucket, (error, data) => { 585 if (error && error.code !== 0) { 586 console.error(`insert fail, error: ${JSON.stringify(error)}`); 587 } else { 588 console.log(`insert success, data: ${JSON.stringify(data)}`); 589 } 590}); 591``` 592 593## DataAbilityHelper.insert 594 595insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\<number> 596 597Inserts a single data record into the database. This API uses a promise to return the result. 598 599**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 600 601**Model restriction**: This API can be used only in the FA model. 602 603**Parameters** 604 605| Name | Type | Mandatory| Description | 606| ------------ | ---------------- | ---- | ------------------------------------------------------ | 607| uri | string | Yes | URI of the data to insert. | 608| valuesBucket | rdb.ValuesBucket | Yes | Data record to insert. If this parameter is **null**, a blank row will be inserted.| 609 610**Return value** 611 612| Type | Description | 613| ---------------- | ------------------------ | 614| Promise\<number> | Promise used to return the index of the inserted data record.| 615 616**Example** 617 618<!--code_no_check_fa--> 619```ts 620import ability from '@ohos.ability.ability'; 621import featureAbility from '@ohos.ability.featureAbility'; 622import rdb from '@ohos.data.rdb'; 623 624let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 625 'dataability:///com.example.DataAbility' 626); 627const valueBucket: rdb.ValuesBucket = { 628 'name': 'rose1', 629 'age': 221, 630 'salary': 20.5, 631 'blobType': 'u8', 632}; 633DAHelper.insert('dataability:///com.example.DataAbility', valueBucket).then((data) => { 634 console.info(`insert data: ${JSON.stringify(data)}`); 635}); 636``` 637 638## DataAbilityHelper.batchInsert 639 640batchInsert(uri: string, valuesBuckets: Array\<rdb.ValuesBucket>, callback: AsyncCallback\<number>): void 641 642Inserts multiple data records into the database. This API uses an asynchronous callback to return the result. 643 644**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 645 646**Model restriction**: This API can be used only in the FA model. 647**Parameters** 648 649| Name | Type | Mandatory| Description | 650| ------------ | ----------------------- | ---- | -------------------------------- | 651| uri | string | Yes | URI of the data to insert. | 652| valuesBuckets | Array\<[rdb.ValuesBucket](../apis-arkdata/js-apis-data-rdb.md#valuesbucket)> | Yes | Data records to insert. | 653| callback | AsyncCallback\<number> | Yes | Callback used to return the number of inserted data records.| 654 655**Example** 656 657<!--code_no_check_fa--> 658```ts 659import ability from '@ohos.ability.ability'; 660import featureAbility from '@ohos.ability.featureAbility'; 661import rdb from '@ohos.data.rdb'; 662 663let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 664 'dataability:///com.example.DataAbility' 665); 666let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',} as rdb.ValuesBucket, 667 {'name': 'roe12', 'age': 21, 'salary': 20.5, 'blobType': 'u8',} as rdb.ValuesBucket, 668 {'name': 'roe13', 'age': 21, 'salary': 20.5, 'blobType': 'u8',} as rdb.ValuesBucket); 669DAHelper.batchInsert('dataability:///com.example.DataAbility', cars, (error, data) => { 670 if (error && error.code !== 0) { 671 console.error(`batchInsert fail, error: ${JSON.stringify(error)}`); 672 } else { 673 console.log(`batchInsert success, data: ${JSON.stringify(data)}`); 674 } 675}); 676``` 677 678## DataAbilityHelper.batchInsert 679 680batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise\<number> 681 682Inserts multiple data records into the database. This API uses a promise to return the result. 683 684**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 685 686**Model restriction**: This API can be used only in the FA model. 687 688**Parameters** 689 690| Name | Type | Mandatory| Description | 691| ------------ | ----------------------- | ---- | ------------------------ | 692| uri | string | Yes | URI of the data to insert.| 693| valuesBuckets | Array<[rdb.ValuesBucket](../apis-arkdata/js-apis-data-rdb.md#valuesbucket)> | Yes | Data records to insert. | 694 695**Return value** 696 697| Type | Description | 698| ---------------- | ---------------------- | 699| Promise\<number> | Promise used to return the number of inserted data records.| 700 701**Example** 702 703<!--code_no_check_fa--> 704```ts 705import ability from '@ohos.ability.ability'; 706import featureAbility from '@ohos.ability.featureAbility'; 707import rdb from '@ohos.data.rdb'; 708 709let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 710 'dataability:///com.example.DataAbility' 711); 712let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',} as rdb.ValuesBucket, 713 {'name': 'roe12', 'age': 21, 'salary': 20.5, 'blobType': 'u8',} as rdb.ValuesBucket, 714 {'name': 'roe13', 'age': 21, 'salary': 20.5, 'blobType': 'u8',} as rdb.ValuesBucket); 715DAHelper.batchInsert('dataability:///com.example.DataAbility', cars).then((data) => { 716 console.info(`batchInsert data: ${JSON.stringify(data)}`); 717}); 718``` 719 720## DataAbilityHelper.delete 721 722delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void 723 724Deletes one or more data records from the database. This API uses an asynchronous callback to return the result. 725 726**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 727 728**Model restriction**: This API can be used only in the FA model. 729 730**Parameters** 731 732| Name | Type | Mandatory| Description | 733| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 734| uri | string | Yes | URI of the data to delete. | 735| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.| 736| callback | AsyncCallback\<number> | Yes | Callback used to return the number of deleted data records. | 737 738**Example** 739 740<!--code_no_check_fa--> 741```ts 742import ability from '@ohos.ability.ability'; 743import featureAbility from '@ohos.ability.featureAbility'; 744import ohos_data_ability from '@ohos.data.dataAbility'; 745 746let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 747 'dataability:///com.example.DataAbility' 748); 749let da = new ohos_data_ability.DataAbilityPredicates(); 750DAHelper.delete('dataability:///com.example.DataAbility', da, (error, data) => { 751 if (error && error.code !== 0) { 752 console.error(`delete fail, error: ${JSON.stringify(error)}`); 753 } else { 754 console.log(`delete success, data: ${JSON.stringify(data)}`); 755 } 756}); 757``` 758 759## DataAbilityHelper.delete 760 761delete(uri: string, predicates?: dataAbility.DataAbilityPredicates): Promise\<number> 762 763Deletes one or more data records from the database. This API uses a promise to return the result. 764 765**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 766 767**Model restriction**: This API can be used only in the FA model. 768 769**Parameters** 770 771| Name | Type | Mandatory| Description | 772| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 773| uri | string | Yes | URI of the data to delete. | 774| predicates | dataAbility.DataAbilityPredicates | No | Filter criteria. You should define the processing logic when this parameter is **null**.| 775 776**Return value** 777 778| Type | Description | 779| ---------------- | ------------------------ | 780| Promise\<number> | Promise used to return the number of deleted data records.| 781 782**Example** 783 784<!--code_no_check_fa--> 785```ts 786import ability from '@ohos.ability.ability'; 787import featureAbility from '@ohos.ability.featureAbility'; 788import ohos_data_ability from '@ohos.data.dataAbility'; 789 790let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 791 'dataability:///com.example.DataAbility' 792); 793let da = new ohos_data_ability.DataAbilityPredicates(); 794DAHelper.delete('dataability:///com.example.DataAbility', da).then((data) => { 795 console.info(`delete data: ${JSON.stringify(data)}`); 796}); 797``` 798 799## DataAbilityHelper.delete 800 801delete(uri: string, callback: AsyncCallback\<number>): void 802 803Uses a custom processing logic to delete data records from the database. This API uses an asynchronous callback to return the result. 804 805**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 806 807**Model restriction**: This API can be used only in the FA model. 808 809**Parameters** 810 811| Name | Type | Mandatory| Description | 812| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 813| uri | string | Yes | URI of the data to delete. | 814| callback | AsyncCallback\<number> | Yes | Callback used to return the number of deleted data records. | 815 816**Example** 817 818<!--code_no_check_fa--> 819```ts 820import ability from '@ohos.ability.ability'; 821import featureAbility from '@ohos.ability.featureAbility'; 822 823let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 824 'dataability:///com.example.DataAbility' 825); 826DAHelper.delete('dataability:///com.example.DataAbility', (error, data) => { 827 if (error && error.code !== 0) { 828 console.error(`delete fail, error: ${JSON.stringify(error)}`); 829 } else { 830 console.log(`delete success, data: ${JSON.stringify(data)}`); 831 } 832}); 833``` 834 835## DataAbilityHelper.update 836 837update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void 838 839Updates data in the database. This API uses an asynchronous callback to return the result. 840 841**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 842 843**Model restriction**: This API can be used only in the FA model. 844 845**Parameters** 846 847| Name | Type | Mandatory| Description | 848| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 849| uri | string | Yes | URI of the data to update. | 850| valuesBucket | rdb.ValuesBucket | Yes | New values. | 851| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.| 852| callback | AsyncCallback\<number> | Yes | Callback used to return the number of updated data records. | 853 854**Example** 855 856<!--code_no_check_fa--> 857```ts 858import ability from '@ohos.ability.ability'; 859import featureAbility from '@ohos.ability.featureAbility'; 860import ohos_data_ability from '@ohos.data.dataAbility'; 861import rdb from '@ohos.data.rdb'; 862 863let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 864 'dataability:///com.example.DataAbility' 865); 866const va: rdb.ValuesBucket = { 867 'name': 'roe1', 868 'age': 21, 869 'salary': 20.5, 870 'blobType': 'u8', 871}; 872let da = new ohos_data_ability.DataAbilityPredicates(); 873DAHelper.update('dataability:///com.example.DataAbility', va, da, (error, data) => { 874 if (error && error.code !== 0) { 875 console.error(`update fail, error: ${JSON.stringify(error)}`); 876 } else { 877 console.log(`update success, data: ${JSON.stringify(data)}`); 878 } 879}); 880``` 881 882## DataAbilityHelper.update 883 884update(uri: string, valuesBucket: rdb.ValuesBucket, predicates?: dataAbility.DataAbilityPredicates): Promise\<number> 885 886Updates data in the database. This API uses a promise to return the result. 887 888**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 889 890**Model restriction**: This API can be used only in the FA model. 891 892**Parameters** 893 894| Name | Type | Mandatory| Description | 895| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 896| uri | string | Yes | URI of the data to update. | 897| valuesBucket | rdb.ValuesBucket | Yes | New values. | 898| predicates | dataAbility.DataAbilityPredicates | No | Filter criteria. You should define the processing logic when this parameter is **null**.| 899 900**Return value** 901 902| Type | Description | 903| ---------------- | -------------------------------------------- | 904| Promise\<number> | Promise used to return the number of updated data records.| 905 906**Example** 907 908<!--code_no_check_fa--> 909```ts 910import ability from '@ohos.ability.ability'; 911import featureAbility from '@ohos.ability.featureAbility'; 912import ohos_data_ability from '@ohos.data.dataAbility'; 913import rdb from '@ohos.data.rdb'; 914 915let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 916 'dataability:///com.example.DataAbility' 917); 918const va: rdb.ValuesBucket = { 919 'name': 'roe1', 920 'age': 21, 921 'salary': 20.5, 922 'blobType': 'u8', 923}; 924let da = new ohos_data_ability.DataAbilityPredicates(); 925DAHelper.update('dataability:///com.example.DataAbility', va, da).then((data) => { 926 console.info(`update data: ${JSON.stringify(data)}`); 927}); 928``` 929 930## DataAbilityHelper.update 931 932update(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\<number>): void 933 934Uses a custom processing logic to update data records in the database. This API uses an asynchronous callback to return the result. 935 936**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 937 938**Model restriction**: This API can be used only in the FA model. 939 940**Parameters** 941 942| Name | Type | Mandatory| Description | 943| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 944| uri | string | Yes | URI of the data to update. | 945| valuesBucket | rdb.ValuesBucket | Yes | New values. | 946| callback | AsyncCallback\<number> | Yes | Callback used to return the number of updated data records. | 947 948**Example** 949 950<!--code_no_check_fa--> 951```ts 952import ability from '@ohos.ability.ability'; 953import featureAbility from '@ohos.ability.featureAbility'; 954import rdb from '@ohos.data.rdb'; 955 956let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 957 'dataability:///com.example.DataAbility' 958); 959const va: rdb.ValuesBucket = { 960 'name': 'roe1', 961 'age': 21, 962 'salary': 20.5, 963 'blobType': 'u8', 964}; 965DAHelper.update('dataability:///com.example.DataAbility', va, (error, data) => { 966 if (error && error.code !== 0) { 967 console.error(`update fail, error: ${JSON.stringify(error)}`); 968 } else { 969 console.log(`update success, data: ${JSON.stringify(data)}`); 970 } 971}); 972``` 973 974## DataAbilityHelper.query 975 976query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>): void 977 978Queries data in the database. This API uses an asynchronous callback to return the result. 979 980**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 981 982**Model restriction**: This API can be used only in the FA model. 983 984**Parameters** 985 986| Name | Type | Mandatory| Description | 987| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 988| uri | string | Yes | URI of the data to query. | 989| columns | Array\<string> | Yes | Columns to query. If this parameter is **null**, all columns will be queried. | 990| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. When **null** is passed in, you need to customize the logic for querying data in the database.| 991| callback | AsyncCallback\<[ResultSet](../apis-arkdata/js-apis-data-relationalStore.md#resultset)> | Yes | Callback used to return the result. | 992 993**Example** 994 995<!--code_no_check_fa--> 996```ts 997import ability from '@ohos.ability.ability'; 998import featureAbility from '@ohos.ability.featureAbility'; 999import ohos_data_ability from '@ohos.data.dataAbility'; 1000 1001let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1002 'dataability:///com.example.DataAbility' 1003); 1004let cars=new Array('value1', 'value2', 'value3', 'value4'); 1005let da = new ohos_data_ability.DataAbilityPredicates(); 1006DAHelper.query('dataability:///com.example.DataAbility', cars, da, (error, data) => { 1007 if (error && error.code !== 0) { 1008 console.error(`query fail, error: ${JSON.stringify(error)}`); 1009 } else { 1010 console.log(`query success, data: ${JSON.stringify(data)}`); 1011 } 1012}); 1013``` 1014 1015## DataAbilityHelper.query 1016 1017query(uri: string, callback: AsyncCallback\<ResultSet>): void 1018 1019Queries data in the database. This API uses an asynchronous callback to return the result. 1020 1021**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1022 1023**Model restriction**: This API can be used only in the FA model. 1024 1025**Parameters** 1026 1027| Name | Type | Mandatory| Description | 1028| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 1029| uri | string | Yes | URI of the data to query. | 1030| callback | AsyncCallback\<[ResultSet](../apis-arkdata/js-apis-data-relationalStore.md#resultset)> | Yes | Callback used to return the result. | 1031 1032**Example** 1033 1034<!--code_no_check_fa--> 1035```ts 1036import ability from '@ohos.ability.ability'; 1037import featureAbility from '@ohos.ability.featureAbility'; 1038 1039let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1040 'dataability:///com.example.DataAbility' 1041); 1042DAHelper.query('dataability:///com.example.DataAbility', (error, data) => { 1043 if (error && error.code !== 0) { 1044 console.error(`query fail, error: ${JSON.stringify(error)}`); 1045 } else { 1046 console.log(`query success, data: ${JSON.stringify(data)}`); 1047 } 1048}); 1049``` 1050 1051## DataAbilityHelper.query 1052 1053query(uri: string, columns: Array\<string>, callback: AsyncCallback\<ResultSet>): void 1054 1055Queries data in the database. This API uses an asynchronous callback to return the result. 1056 1057**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1058 1059**Model restriction**: This API can be used only in the FA model. 1060 1061**Parameters** 1062 1063| Name | Type | Mandatory| Description | 1064| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 1065| uri | string | Yes | URI of the data to query. | 1066| columns | Array\<string> | Yes | Columns to query. If this parameter is **null**, all columns will be queried. | 1067| callback | AsyncCallback\<[ResultSet](../apis-arkdata/js-apis-data-relationalStore.md#resultset)> | Yes | Callback used to return the result. | 1068 1069**Example** 1070 1071<!--code_no_check_fa--> 1072```ts 1073import ability from '@ohos.ability.ability'; 1074import featureAbility from '@ohos.ability.featureAbility'; 1075 1076let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1077 'dataability:///com.example.DataAbility' 1078); 1079let cars = new Array('value1', 'value2', 'value3', 'value4'); 1080DAHelper.query('dataability:///com.example.DataAbility', cars, (error, data) => { 1081 if (error && error.code !== 0) { 1082 console.error(`query fail, error: ${JSON.stringify(error)}`); 1083 } else { 1084 console.log(`query success, data: ${JSON.stringify(data)}`); 1085 } 1086}); 1087``` 1088 1089## DataAbilityHelper.query 1090 1091query(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>): void 1092 1093Queries data in the database. This API uses an asynchronous callback to return the result. 1094 1095**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1096 1097**Model restriction**: This API can be used only in the FA model. 1098 1099**Parameters** 1100 1101| Name | Type | Mandatory| Description | 1102| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 1103| uri | string | Yes | URI of the data to query. | 1104| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. When **null** is passed in, you need to customize the logic for querying data in the database.| 1105| callback | AsyncCallback\<[ResultSet](../apis-arkdata/js-apis-data-relationalStore.md#resultset)> | Yes | Callback used to return the result. | 1106 1107**Example** 1108 1109<!--code_no_check_fa--> 1110```ts 1111import ability from '@ohos.ability.ability'; 1112import featureAbility from '@ohos.ability.featureAbility'; 1113import ohos_data_ability from '@ohos.data.dataAbility'; 1114 1115let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1116 'dataability:///com.example.DataAbility' 1117); 1118let da = new ohos_data_ability.DataAbilityPredicates(); 1119DAHelper.query('dataability:///com.example.DataAbility', da, (error, data) => { 1120 if (error && error.code !== 0) { 1121 console.error(`query fail, error: ${JSON.stringify(error)}`); 1122 } else { 1123 console.log(`query success, data: ${JSON.stringify(data)}`); 1124 } 1125}); 1126``` 1127 1128## DataAbilityHelper.query 1129 1130query(uri: string, columns?: Array\<string>, predicates?: dataAbility.DataAbilityPredicates): Promise\<ResultSet> 1131 1132Queries data in the database. This API uses a promise to return the result. 1133 1134**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1135 1136**Model restriction**: This API can be used only in the FA model. 1137 1138**Parameters** 1139 1140| Name | Type | Mandatory| Description | 1141| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 1142| uri | string | Yes | URI of the data to query. | 1143| columns | Array\<string> | No | Columns to query. If this parameter is **null**, all columns will be queried. | 1144| predicates | dataAbility.DataAbilityPredicates | No | Filter criteria. When **null** is passed in, you need to customize the logic for querying data in the database.| 1145 1146**Return value** 1147 1148| Type | Description | 1149| ------------------- | -------------- | 1150| Promise\<[ResultSet](../apis-arkdata/js-apis-data-relationalStore.md#resultset)> | Promise used to return the result.| 1151 1152**Example** 1153 1154<!--code_no_check_fa--> 1155```ts 1156import ability from '@ohos.ability.ability'; 1157import featureAbility from '@ohos.ability.featureAbility'; 1158import ohos_data_ability from '@ohos.data.dataAbility'; 1159 1160let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1161 'dataability:///com.example.DataAbility' 1162); 1163let cars = new Array('value1', 'value2', 'value3', 'value4'); 1164let da = new ohos_data_ability.DataAbilityPredicates(); 1165DAHelper.query('dataability:///com.example.DataAbility', cars, da).then((data) => { 1166 console.info(`query data: ${JSON.stringify(data)}`); 1167}); 1168``` 1169 1170## DataAbilityHelper.call 1171 1172call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback\<PacMap>): void 1173 1174Calls an extended method defined by the DataAbility. This API uses an asynchronous callback to return the result. 1175 1176**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1177 1178**Model restriction**: This API can be used only in the FA model. 1179 1180**Parameters** 1181 1182| Name | Type | Mandatory| Description | 1183| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 1184| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. | 1185| method | string | Yes | Name of the API to call. | 1186| arg | string | Yes | Parameter to pass in. | 1187| extras | [PacMap](js-apis-inner-ability-dataAbilityHelper.md#pacmap) | Yes | Key-value pair parameter. | 1188| callback | AsyncCallback\<[PacMap](js-apis-inner-ability-dataAbilityHelper.md#pacmap)> | Yes| Callback used to return the extended parameters in the format of key-value pairs. | 1189 1190**Example** 1191 1192<!--code_no_check_fa--> 1193```ts 1194import ability from '@ohos.ability.ability'; 1195import featureAbility from '@ohos.ability.featureAbility'; 1196 1197let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1198 'dataability:///com.example.jsapidemo.UserDataAbility' 1199); 1200dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility', 1201 'method', 'arg', {'key1':'value1'}, (error, data) => { 1202 if (error && error.code !== 0) { 1203 console.error(`call fail, error: ${JSON.stringify(error)}`); 1204 } else { 1205 console.log(`call success, data: ${JSON.stringify(data)}`); 1206 } 1207}); 1208``` 1209 1210## DataAbilityHelper.call 1211 1212call(uri: string, method: string, arg: string, extras: PacMap): Promise\<PacMap> 1213 1214Calls an extended method defined by the DataAbility. This API uses a promise to return the result. 1215 1216**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1217 1218**Model restriction**: This API can be used only in the FA model. 1219 1220**Parameters** 1221 1222| Name | Type | Mandatory| Description | 1223| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 1224| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. | 1225| method | string | Yes | Name of the API to call. | 1226| arg | string | Yes | Parameter to pass in. | 1227| extras | [PacMap](js-apis-inner-ability-dataAbilityHelper.md#pacmap) | Yes | Key-value pair parameter. | 1228 1229**Return value** 1230 1231| Type| Description| 1232|------ | ------- | 1233|Promise\<[PacMap](js-apis-inner-ability-dataAbilityHelper.md#pacmap)> | Promise used to return the extended parameters in the format of key-value pairs.| 1234 1235**Example** 1236 1237<!--code_no_check_fa--> 1238```ts 1239import ability from '@ohos.ability.ability'; 1240import featureAbility from '@ohos.ability.featureAbility'; 1241import { BusinessError } from '@ohos.base'; 1242 1243let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1244 'dataability:///com.example.jsapidemo.UserDataAbility' 1245); 1246dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility', 1247 'method', 'arg', {'key1':'value1'}).then((data) => { 1248 console.info('call success, data: ${data}'); 1249}).catch((error: BusinessError) => { 1250 console.error('call failed, error: ${error}'); 1251}); 1252``` 1253 1254## DataAbilityHelper.executeBatch 1255 1256executeBatch(uri: string, operations: Array\<DataAbilityOperation>, callback: AsyncCallback\<Array\<DataAbilityResult>>): void 1257 1258Operates data in the database in batches. This API uses an asynchronous callback to return the result. 1259 1260**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1261 1262**Model restriction**: This API can be used only in the FA model. 1263 1264**Parameters** 1265 1266| Name | Type | Mandatory| Description | 1267| ----------| ---------------------------------| ---- | ------------------------------------------------ | 1268| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.| 1269| operations | Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)> | Yes | An array holding the data operations on the database. | 1270| callback | AsyncCallback\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>> | Yes | Callback used to return the result of each operation in the **DataAbilityResult** array. | 1271 1272**Example** 1273 1274<!--code_no_check_fa--> 1275```ts 1276import ability from '@ohos.ability.ability'; 1277import featureAbility from '@ohos.ability.featureAbility'; 1278 1279// Select the operations to be performed on the database according to the DataAbilityOperation array. 1280let op: Array<ability.DataAbilityOperation> = new Array(); 1281let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1282 'dataability:///com.example.jsapidemo.UserDataAbility' 1283); 1284dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', op, (error, data) => { 1285 if (error && error.code !== 0) { 1286 console.error(`executeBatch fail, error: ${JSON.stringify(error)}`); 1287 } else { 1288 console.log(`executeBatch success, data: ${JSON.stringify(data)}`); 1289 } 1290}); 1291``` 1292 1293## DataAbilityHelper.executeBatch 1294 1295executeBatch(uri: string, operations: Array\<DataAbilityOperation>): Promise\<Array\<DataAbilityResult>> 1296 1297Operates data in the database in batches. This API uses a promise to return the result. 1298 1299**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1300 1301**Model restriction**: This API can be used only in the FA model. 1302 1303**Parameters** 1304 1305| Name | Type | Mandatory| Description | 1306| ---------- | -------------------------------| ---- | ------------------------------------------------ | 1307| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.| 1308| operations | Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)> | Yes | An array holding the data operations on the database. | 1309 1310**Return value** 1311 1312| Type| Description| 1313|------ | ------- | 1314|Promise\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>> | Promise used to return the result of each operation in the **DataAbilityResult** array.| 1315 1316**Example** 1317 1318<!--code_no_check_fa--> 1319```ts 1320import ability from '@ohos.ability.ability'; 1321import featureAbility from '@ohos.ability.featureAbility'; 1322import { BusinessError } from '@ohos.base'; 1323 1324// Select the operations to be performed on the database according to the DataAbilityOperation array. 1325let op: Array<ability.DataAbilityOperation> = new Array(); 1326let dataAbilityHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper( 1327 'dataability:///com.example.jsapidemo.UserDataAbility' 1328); 1329dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', op).then((data) => { 1330 console.info('executeBatch success, data: ${data}'); 1331}).catch((error: BusinessError) => { 1332 console.error('executeBatch failed, error: ${error}'); 1333}); 1334 1335``` 1336 1337## PacMap 1338 1339[key: string]: number | string | boolean | Array\<string | number | boolean> | null 1340 1341Defines the **PacMap** type used for data storage. 1342 1343**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 1344 1345| Name| Type| Mandatory| Description| 1346| ------ | ------ | ------ | ------ | 1347| [key: string] | number \| string \| boolean \| Array\<string \| number \| boolean\> \| null | Yes| Data stored in key-value pairs.| 1348