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