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