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> The APIs of this module can be used only in the FA model. 9 10## Usage 11 12Import the following modules based on the actual situation before using the current module: 13```ts 14import ohos_data_ability from '@ohos.data.dataAbility'; 15import ohos_data_rdb from '@ohos.data.rdb'; 16``` 17 18## DataAbilityHelper.openFile 19 20openFile(uri: string, mode: string, callback: AsyncCallback\<number>): void 21 22Opens a file with a specified URI. This API uses an asynchronous callback to return a file descriptor. 23 24**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 25 26**Parameters** 27 28| Name | Type | Mandatory| Description | 29| -------- | ---------------------- | ---- | ---------------------------------- | 30| uri | string | Yes | URI of the file to open. | 31| mode | string | Yes | Mode for opening the file. The value **r** indicates read-only access, **w** indicates **write-only** access, and **rw** indicates read-write access. | 32| callback | AsyncCallback\<number> | Yes | Callback used to return the file descriptor.| 33 34**Example** 35 36```ts 37import featureAbility from '@ohos.ability.featureAbility'; 38let DAHelper = featureAbility.acquireDataAbilityHelper( 39 'dataability:///com.example.DataAbility' 40); 41let mode = 'rwt'; 42DAHelper.openFile('dataability:///com.example.DataAbility', mode, (err) => { 43 console.info('==========================>Called=======================>'); 44}); 45``` 46 47## DataAbilityHelper.openFile 48 49openFile(uri: string, mode: string): Promise\<number> 50 51Opens a file with a specified URI. This API uses a promise to return a file descriptor. 52 53**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 54 55**Parameters** 56 57| Name| Type | Mandatory| Description | 58| ---- | ------ | ---- | ------------------------ | 59| uri | string | Yes | URI of the file to open.| 60| mode | string | Yes | Mode for opening the file. The value **r** indicates read-only access, **w** indicates **write-only** access, and **rw** indicates read-write access. | 61 62**Return value** 63 64| Type | Description | 65| ---------------- | ---------------- | 66| Promise\<number> | Promise used to return the file descriptor.| 67 68**Example** 69 70```ts 71import featureAbility from '@ohos.ability.featureAbility'; 72let DAHelper = featureAbility.acquireDataAbilityHelper( 73 'dataability:///com.example.DataAbility' 74); 75let mode = 'rwt'; 76DAHelper.openFile('dataability:///com.example.DataAbility', mode).then((data) => { 77 console.info('==========================>openFileCallback=======================>'); 78}); 79``` 80 81## DataAbilityHelper.on 82 83on(type: 'dataChange', uri: string, callback: AsyncCallback\<void>): void 84 85Registers an observer to listen for changes in the data specified by a given URI. 86 87**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 88 89**Parameters** 90 91| Name | Type | Mandatory| Description | 92| -------- | -------------------- | ---- | ------------------------ | 93| type | string | Yes | The value **dataChange** means data changes. | 94| uri | string | Yes | URI of the data.| 95| callback | AsyncCallback\<void> | Yes | Callback invoked when the data is changed. | 96 97**Example** 98 99```ts 100import featureAbility from '@ohos.ability.featureAbility'; 101let helper = featureAbility.acquireDataAbilityHelper( 102 'dataability:///com.example.DataAbility' 103); 104function onChangeNotify() { 105 console.info('==========================>onChangeNotify=======================>'); 106}; 107helper.on( 108 'dataChange', 109 'dataability:///com.example.DataAbility', 110 onChangeNotify 111); 112``` 113 114## DataAbilityHelper.off 115 116off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>): void 117 118Deregisters the observer that listens for changes in the data specified by a given URI. 119 120**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 121 122**Parameters** 123 124| Name | Type | Mandatory| Description | 125| -------- | -------------------- | ---- | ------------------------ | 126| type | string | Yes | The value **dataChange** means data changes. | 127| uri | string | Yes | URI of the data.| 128| callback | AsyncCallback\<void> | No | Callback of the listener to deregister. If the callback is set to **null**, all data change listeners are canceled. | 129 130**Example** 131 132```ts 133import featureAbility from '@ohos.ability.featureAbility'; 134let helper = featureAbility.acquireDataAbilityHelper( 135 'dataability:///com.example.DataAbility' 136); 137function onChangeNotify() { 138 console.info('==========================>onChangeNotify=======================>'); 139}; 140helper.off( 141 'dataChange', 142 'dataability:///com.example.DataAbility', 143); 144helper.off( 145 'dataChange', 146 'dataability:///com.example.DataAbility', 147 onChangeNotify 148); 149``` 150 151## DataAbilityHelper.getType 152 153getType(uri: string, callback: AsyncCallback\<string>): void 154 155Obtains the media resource type of the data specified by a given URI. This API uses an asynchronous callback to return the result. 156 157**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 158 159**Parameters** 160 161| Name | Type | Mandatory| Description | 162| -------- | ---------------------- | ---- | --------------------------------------------- | 163| uri | string | Yes | URI of the data. | 164| callback | AsyncCallback\<string> | Yes | Callback used to return the media resource type.| 165 166**Example** 167 168```ts 169import featureAbility from '@ohos.ability.featureAbility'; 170let DAHelper = featureAbility.acquireDataAbilityHelper( 171 'dataability:///com.example.DataAbility' 172); 173DAHelper.getType('dataability:///com.example.DataAbility', (err, data) => { 174 console.info('==========================>Called=======================>'); 175}); 176``` 177 178## DataAbilityHelper.getType 179 180getType(uri: string): Promise\<string> 181 182Obtains the media resource type of the data specified by a given URI. This API uses a promise to return the result. 183 184**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 185 186**Parameters** 187 188| Name| Type | Mandatory| Description | 189| ---- | ------ | ---- | ------------------------ | 190| uri | string | Yes | URI of the data.| 191 192**Return value** 193 194| Type | Description | 195| ---------------- | ----------------------------------- | 196| Promise\<string> | Promise used to return the media resource type.| 197 198**Example** 199 200```ts 201import featureAbility from '@ohos.ability.featureAbility'; 202let DAHelper = featureAbility.acquireDataAbilityHelper( 203 'dataability:///com.example.DataAbility' 204); 205DAHelper.getType('dataability:///com.example.DataAbility').then((data) => { 206 console.info('==========================>getTypeCallback=======================>'); 207}); 208``` 209 210## DataAbilityHelper.getFileTypes 211 212getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): void 213 214Obtains the supported media resource types of a specified file. This API uses an asynchronous callback 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 file. | 223| mimeTypeFilter | string | Yes | Media resource type of the file to obtain. | 224| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return an array holding the media resource type.| 225 226**Example** 227 228```ts 229import featureAbility from '@ohos.ability.featureAbility'; 230let DAHelper = featureAbility.acquireDataAbilityHelper( 231 'dataability:///com.example.DataAbility' 232); 233DAHelper.getFileTypes( 'dataability:///com.example.DataAbility', 234 'image/*', (err, data) => { 235 console.info('==========================>Called=======================>'); 236}); 237``` 238 239 240 241## DataAbilityHelper.getFileTypes 242 243getFileTypes(uri: string, mimeTypeFilter: string): Promise\<Array\<string>> 244 245Obtains the supported media resource types of a specified file. This API uses a promise to return the result. 246 247**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 248 249**Parameters** 250 251| Name | Type | Mandatory| Description | 252| -------------- | ------ | ---- | ---------------------------- | 253| uri | string | Yes | URI of the file. | 254| mimeTypeFilter | string | Yes | Media resource type of the file to obtain.| 255 256**Return value** 257 258| Type | Description | 259| ------------------------ | ------------------------ | 260| Promise\<Array\<string>> | Promise used to return an array holding the media resource type.| 261 262**Example** 263 264```ts 265import featureAbility from '@ohos.ability.featureAbility'; 266let DAHelper = featureAbility.acquireDataAbilityHelper( 267 'dataability:///com.example.DataAbility' 268); 269DAHelper.getFileTypes('dataability:///com.example.DataAbility', 270 'image/*').then((data) => { 271 console.info('===================>getFileTypesCallback================>'); 272}); 273``` 274 275## DataAbilityHelper.normalizeUri 276 277normalizeUri(uri: string, callback: AsyncCallback\<string>): void 278 279Converts the URI that refers to a Data ability into a normalized URI. This API uses an asynchronous callback to return the result. 280 281**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 282 283**Parameters** 284 285| Name | Type | Mandatory| Description | 286| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 287| uri | string | Yes | URI object to normalize. | 288| 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.| 289 290**Example** 291 292```ts 293import featureAbility from '@ohos.ability.featureAbility'; 294let DAHelper = featureAbility.acquireDataAbilityHelper( 295 'dataability:///com.example.DataAbility' 296); 297DAHelper.normalizeUri('dataability:///com.example.DataAbility', (err, data) => { 298 console.info('==========================>Called=======================>'); 299}); 300``` 301 302## DataAbilityHelper.normalizeUri 303 304normalizeUri(uri: string): Promise\<string> 305 306Converts the URI that refers to a Data ability into a normalized URI. This API uses a promise to return the result. 307 308**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 309 310**Parameters** 311 312| Name| Type | Mandatory| Description | 313| ---- | ------ | ---- | ----------------------- | 314| uri | string | Yes | URI object to normalize.| 315 316**Return value** 317 318| Type | Description | 319| ---------------- | ------------------------------------------------------ | 320| 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.| 321 322**Example** 323 324```ts 325import featureAbility from '@ohos.ability.featureAbility'; 326let DAHelper = featureAbility.acquireDataAbilityHelper( 327 'dataability:///com.example.DataAbility' 328); 329DAHelper.normalizeUri('dataability:///com.example.DataAbility',).then((data) => { 330 console.info('=================>normalizeUriCallback=======================>'); 331}); 332``` 333 334## DataAbilityHelper.denormalizeUri 335 336denormalizeUri(uri: string, callback: AsyncCallback\<string>): void 337 338Converts 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. 339 340**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 341 342**Parameters** 343 344| Name | Type | Mandatory| Description | 345| -------- | ---------------------- | ---- | --------------------------------------------------- | 346| uri | string | Yes | URI object to denormalize. | 347| callback | AsyncCallback\<string> | Yes | Callback used to return the denormalized URI object.| 348 349**Example** 350 351```ts 352import featureAbility from '@ohos.ability.featureAbility'; 353let DAHelper = featureAbility.acquireDataAbilityHelper( 354 'dataability:///com.example.DataAbility' 355); 356DAHelper.denormalizeUri('dataability:///com.example.DataAbility', (err, data) => { 357 console.info('==========================>Called=======================>'); 358}); 359``` 360 361 362 363## DataAbilityHelper.denormalizeUri 364 365denormalizeUri(uri: string): Promise\<string> 366 367Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string)** to a denormalized one. This API uses a promise to return the result. 368 369**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 370 371**Parameters** 372 373| Name| Type | Mandatory| Description | 374| ---- | ------ | ---- | ----------------------- | 375| uri | string | Yes | URI object to normalize.| 376 377**Return value** 378 379| Type | Description | 380| ---------------- | ----------------------------------------- | 381| Promise\<string> | Promise used to return the denormalized URI object.| 382 383**Example** 384 385```ts 386import featureAbility from '@ohos.ability.featureAbility'; 387let DAHelper = featureAbility.acquireDataAbilityHelper( 388 'dataability:///com.example.DataAbility' 389); 390DAHelper.denormalizeUri('dataability:///com.example.DataAbility',).then((data) => { 391 console.info('===============>denormalizeUriCallback=======================>'); 392}); 393``` 394 395## DataAbilityHelper.notifyChange 396 397notifyChange(uri: string, callback: AsyncCallback\<void>): void 398 399Notifies the registered observer of a change to the data specified by the URI. This API uses an asynchronous callback to return the result. 400 401**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 402 403**Parameters** 404 405| Name | Type | Mandatory| Description | 406| -------- | -------------------- | ---- | ------------------------ | 407| uri | string | Yes | URI of the data that changes.| 408| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 409 410**Example** 411 412```ts 413import featureAbility from '@ohos.ability.featureAbility'; 414let helper = featureAbility.acquireDataAbilityHelper( 415 'dataability:///com.example.DataAbility' 416); 417helper.notifyChange('dataability:///com.example.DataAbility', (err) => { 418 console.info('==========================>Called=======================>'); 419}); 420``` 421 422## DataAbilityHelper.notifyChange 423 424notifyChange(uri: string): Promise\<void> 425 426Notifies the registered observer of a change to the data specified by the URI. This API uses a promise to return the result. 427 428**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 429 430**Parameters** 431 432| Name| Type | Mandatory| Description | 433| ---- | ------ | ---- | ------------------------ | 434| uri | string | Yes | URI of the data that changes.| 435 436**Return value** 437 438| Type | Description | 439| -------------- | --------------------- | 440| Promise\<void> | Promise used to return the result.| 441 442**Example** 443 444```ts 445import featureAbility from '@ohos.ability.featureAbility'; 446let DAHelper = featureAbility.acquireDataAbilityHelper( 447 'dataability:///com.example.DataAbility' 448); 449DAHelper.notifyChange('dataability:///com.example.DataAbility').then(() => { 450 console.info('================>notifyChangeCallback================>'); 451}); 452``` 453 454## DataAbilityHelper.insert 455 456insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\<number>): void 457 458Inserts a single data record into the database. This API uses an asynchronous callback to return the result. 459 460**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 461 462**Parameters** 463 464| Name | Type | Mandatory| Description | 465| ------------ | ---------------------- | ---- | ------------------------------------------------------ | 466| uri | string | Yes | URI of the data to insert. | 467| valuesBucket | rdb.ValuesBucket | Yes | Data record to insert. If this parameter is **null**, a blank row will be inserted.| 468| callback | AsyncCallback\<number> | Yes | Callback used to return the index of the inserted data record. | 469 470**Example** 471 472```ts 473import featureAbility from '@ohos.ability.featureAbility'; 474let DAHelper = featureAbility.acquireDataAbilityHelper( 475 'dataability:///com.example.DataAbility' 476); 477const valueBucket = { 478 'name': 'rose', 479 'age': 22, 480 'salary': 200.5, 481 'blobType': 'u8', 482}; 483DAHelper.insert('dataability:///com.example.DataAbility', valueBucket, 484 (err, data) => { 485 console.info('==========================>Called=======================>'); 486}); 487``` 488 489## DataAbilityHelper.insert 490 491insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\<number> 492 493Inserts a single data record into the database. This API uses a promise to return the result. 494 495**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 496 497**Parameters** 498 499| Name | Type | Mandatory| Description | 500| ------------ | ---------------- | ---- | ------------------------------------------------------ | 501| uri | string | Yes | URI of the data to insert. | 502| valuesBucket | rdb.ValuesBucket | Yes | Data record to insert. If this parameter is **null**, a blank row will be inserted.| 503 504**Return value** 505 506| Type | Description | 507| ---------------- | ------------------------ | 508| Promise\<number> | Promise used to return the index of the inserted data record.| 509 510**Example** 511 512```ts 513import featureAbility from '@ohos.ability.featureAbility'; 514let DAHelper = featureAbility.acquireDataAbilityHelper( 515 'dataability:///com.example.DataAbility' 516); 517const valueBucket = { 518 'name': 'rose1', 519 'age': 221, 520 'salary': 20.5, 521 'blobType': 'u8', 522}; 523DAHelper.insert('dataability:///com.example.DataAbility', valueBucket).then((data) => { 524 console.info('====================>insertCallback=======================>'); 525}); 526``` 527 528## DataAbilityHelper.batchInsert 529 530batchInsert(uri: string, valuesBuckets: Array\<rdb.ValuesBucket>, callback: AsyncCallback\<number>): void 531 532Inserts multiple data records into the database. This API uses an asynchronous callback to return the result. 533 534**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 535 536**Parameters** 537 538| Name | Type | Mandatory| Description | 539| ------------ | ----------------------- | ---- | -------------------------------- | 540| uri | string | Yes | URI of the data to insert. | 541| valuesBucket | Array\<rdb.ValuesBucket> | Yes | Data records to insert. | 542| callback | AsyncCallback\<number> | Yes | Callback used to return the number of inserted data records.| 543 544**Example** 545 546```ts 547import featureAbility from '@ohos.ability.featureAbility'; 548let DAHelper = featureAbility.acquireDataAbilityHelper( 549 'dataability:///com.example.DataAbility' 550); 551let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',}, 552 {'name': 'roe12', 'age': 21, 'salary': 20.5, 'blobType': 'u8',}, 553 {'name': 'roe13', 'age': 21, 'salary': 20.5, 'blobType': 'u8',}); 554DAHelper.batchInsert('dataability:///com.example.DataAbility', cars, 555 (err, data) => { 556 console.info('==========================>Called=======================>'); 557}); 558``` 559 560## DataAbilityHelper.batchInsert 561 562batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise\<number> 563 564Inserts multiple data records into the database. This API uses a promise to return the result. 565 566**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 567 568**Parameters** 569 570| Name | Type | Mandatory| Description | 571| ------------ | ----------------------- | ---- | ------------------------ | 572| uri | string | Yes | URI of the data to insert.| 573| valuesBucket | Array<rdb.ValuesBucket> | Yes | Data records to insert. | 574 575**Return value** 576 577| Type | Description | 578| ---------------- | ---------------------- | 579| Promise\<number> | Promise used to return the number of inserted data records.| 580 581**Example** 582 583```ts 584import featureAbility from '@ohos.ability.featureAbility'; 585let DAHelper = featureAbility.acquireDataAbilityHelper( 586 'dataability:///com.example.DataAbility' 587); 588let cars = new Array({'name': 'roe11', 'age': 21, 'salary': 20.5, 'blobType': 'u8',}, 589 {'name': 'roe12', 'age': 21, 'salary': 20.5, 'blobType': 'u8',}, 590 {'name': 'roe13', 'age': 21, 'salary': 20.5, 'blobType': 'u8',}); 591DAHelper.batchInsert('dataability:///com.example.DataAbility', cars).then((data) => { 592 console.info('==================>batchInsertCallback=======================>'); 593}); 594``` 595 596## DataAbilityHelper.delete 597 598delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void 599 600Deletes one or more data records from the database. This API uses an asynchronous callback to return the result. 601 602**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 603 604**Parameters** 605 606| Name | Type | Mandatory| Description | 607| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 608| uri | string | Yes | URI of the data to delete. | 609| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.| 610| callback | AsyncCallback\<number> | Yes | Callback used to return the number of deleted data records. | 611 612**Example** 613 614```ts 615import featureAbility from '@ohos.ability.featureAbility'; 616import ohos_data_ability from '@ohos.data.dataAbility'; 617let DAHelper = featureAbility.acquireDataAbilityHelper( 618 'dataability:///com.example.DataAbility' 619); 620let da = new ohos_data_ability.DataAbilityPredicates(); 621DAHelper.delete('dataability:///com.example.DataAbility', da, 622 (err, data) => { 623 console.info('==========================>Called=======================>'); 624}); 625``` 626 627## DataAbilityHelper.delete 628 629delete(uri: string, predicates?: dataAbility.DataAbilityPredicates): Promise\<number>; 630 631Deletes one or more data records from the database. This API uses a promise to return the result. 632 633**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 634 635**Parameters** 636 637| Name | Type | Mandatory| Description | 638| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 639| uri | string | Yes | URI of the data to delete. | 640| predicates | dataAbility.DataAbilityPredicates | No | Filter criteria. You should define the processing logic when this parameter is **null**.| 641 642**Return value** 643 644| Type | Description | 645| ---------------- | ------------------------ | 646| Promise\<number> | Promise used to return the number of deleted data records.| 647 648**Example** 649 650```ts 651import featureAbility from '@ohos.ability.featureAbility'; 652import ohos_data_ability from '@ohos.data.dataAbility'; 653let DAHelper = featureAbility.acquireDataAbilityHelper( 654 'dataability:///com.example.DataAbility' 655); 656let da = new ohos_data_ability.DataAbilityPredicates(); 657DAHelper.delete('dataability:///com.example.DataAbility', da).then((data) => { 658 console.info('==========================>deleteCallback=======================>'); 659}); 660``` 661 662## DataAbilityHelper.update 663 664update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void 665 666Updates data records in the database. This API uses an asynchronous callback to return the result. 667 668**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 669 670**Parameters** 671 672| Name | Type | Mandatory| Description | 673| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 674| uri | string | Yes | URI of the data to update. | 675| valuesBucket | rdb.ValuesBucket | Yes | New values. | 676| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.| 677| callback | AsyncCallback\<number> | Yes | Callback used to return the number of updated data records. | 678 679**Example** 680 681```ts 682import featureAbility from '@ohos.ability.featureAbility'; 683import ohos_data_ability from '@ohos.data.dataAbility'; 684let DAHelper = featureAbility.acquireDataAbilityHelper( 685 'dataability:///com.example.DataAbility' 686); 687const va = { 688 'name': 'roe1', 689 'age': 21, 690 'salary': 20.5, 691 'blobType': 'u8', 692}; 693let da = new ohos_data_ability.DataAbilityPredicates(); 694DAHelper.update('dataability:///com.example.DataAbility', va, da, (err, data) => { 695 console.info('==========================>Called=======================>'); 696}); 697``` 698 699## DataAbilityHelper.update 700 701update(uri: string, valuesBucket: rdb.ValuesBucket, predicates?: dataAbility.DataAbilityPredicates): Promise\<number>; 702 703Updates data records in the database. This API uses a promise to return the result. 704 705**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 706 707**Parameters** 708 709| Name | Type | Mandatory| Description | 710| ------------ | --------------------------------- | ---- | ------------------------------------------------ | 711| uri | string | Yes | URI of the data to update. | 712| valuesBucket | rdb.ValuesBucket | Yes | New values. | 713| predicates | dataAbility.DataAbilityPredicates | No | Filter criteria. You should define the processing logic when this parameter is **null**.| 714 715**Return value** 716 717| Type | Description | 718| ---------------- | -------------------------------------------- | 719| Promise\<number> | Promise used to return the number of updated data records. | 720 721**Example** 722 723```ts 724import featureAbility from '@ohos.ability.featureAbility'; 725import ohos_data_ability from '@ohos.data.dataAbility'; 726let DAHelper = featureAbility.acquireDataAbilityHelper( 727 'dataability:///com.example.DataAbility' 728); 729const va = { 730 'name': 'roe1', 731 'age': 21, 732 'salary': 20.5, 733 'blobType': 'u8', 734}; 735let da = new ohos_data_ability.DataAbilityPredicates(); 736DAHelper.update('dataability:///com.example.DataAbility', va, da).then((data) => { 737 console.info('==========================>updateCallback=======================>'); 738}); 739``` 740 741## DataAbilityHelper.query 742 743query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>): void 744 745Queries data in the database. This API uses an asynchronous callback to return the result. 746 747**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 748 749**Parameters** 750 751| Name | Type | Mandatory| Description | 752| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 753| uri | string | Yes | URI of the data to query. | 754| columns | Array\<string> | Yes | Columns to query. If this parameter is **null**, all columns will be queried. | 755| predicates | dataAbility.DataAbilityPredicates | Yes | Filter criteria. You should define the processing logic when this parameter is **null**.| 756| callback | AsyncCallback\<ResultSet> | Yes | Callback used to return the data queried. | 757 758**Example** 759 760```ts 761import featureAbility from '@ohos.ability.featureAbility'; 762import ohos_data_ability from '@ohos.data.dataAbility'; 763let DAHelper = featureAbility.acquireDataAbilityHelper( 764 'dataability:///com.example.DataAbility' 765); 766let cars=new Array('value1', 'value2', 'value3', 'value4'); 767let da = new ohos_data_ability.DataAbilityPredicates(); 768DAHelper.query('dataability:///com.example.DataAbility', cars, da, (err, data) => { 769 console.info('==========================>Called=======================>'); 770}); 771``` 772 773 774 775## DataAbilityHelper.query 776 777query(uri: string, columns?: Array\<string>, predicates?: dataAbility.DataAbilityPredicates): Promise\<ResultSet>; 778 779Queries data in the database. This API uses a promise to return the result. 780 781**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 782 783**Parameters** 784 785| Name | Type | Mandatory| Description | 786| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 787| uri | string | Yes | URI of the data to query. | 788| columns | Array\<string> | No | Columns to query. If this parameter is **null**, all columns will be queried. | 789| predicates | dataAbility.DataAbilityPredicates | No | Filter criteria. You should define the processing logic when this parameter is **null**.| 790 791**Return value** 792 793| Type | Description | 794| ------------------- | -------------- | 795| Promise\<ResultSet> | Promise used to return the data queried.| 796 797**Example** 798 799```ts 800import featureAbility from '@ohos.ability.featureAbility'; 801import ohos_data_ability from '@ohos.data.dataAbility'; 802let DAHelper = featureAbility.acquireDataAbilityHelper( 803 'dataability:///com.example.DataAbility' 804); 805let cars = new Array('value1', 'value2', 'value3', 'value4'); 806let da = new ohos_data_ability.DataAbilityPredicates(); 807DAHelper.query('dataability:///com.example.DataAbility', cars, da).then((data) => { 808 console.info('==========================>queryCallback=======================>'); 809}); 810``` 811 812## DataAbilityHelper.call 813 814call(uri: string, method: string, arg: string, extras: PacMap): Promise\<PacMap> 815 816Calls an extended API of the DataAbility. This API uses a promise to return the result. 817 818**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 819 820**Parameters** 821 822| Name | Type | Mandatory| Description | 823| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 824| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. | 825| method | string | Yes | Name of the API to call. | 826| arg | string | Yes | Parameter to pass in. | 827| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. | 828 829**Return value** 830 831| Type| Description| 832|------ | ------- | 833|Promise\<[PacMap](#pacmap)> | Promise used to return the result.| 834 835**Example** 836 837```ts 838import featureAbility from '@ohos.ability.featureAbility'; 839 840let dataAbilityHelper = featureAbility.acquireDataAbilityHelper( 841 'dataability:///com.example.jsapidemo.UserDataAbility'); 842dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility', 843 'method', 'arg', {'key1':'value1'}).then((data) => { 844 console.info('Operation succeeded: ' + data); 845}).catch((error) => { 846 console.error('Operation failed. Cause: ' + error); 847}); 848``` 849 850## DataAbilityHelper.call 851 852call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback\<PacMap>): void 853 854Calls an extended API of the DataAbility. This API uses an asynchronous callback to return the result. 855 856**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 857 858**Parameters** 859 860| Name | Type | Mandatory| Description | 861| ---------- | --------------------------------- | ---- | ------------------------------------------------ | 862| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. | 863| method | string | Yes | Name of the API to call. | 864| arg | string | Yes | Parameter to pass in. | 865| extras | [PacMap](#pacmap) | Yes | Key-value pair parameter. | 866| callback | AsyncCallback\<[PacMap](#pacmap)> | Yes | Callback used to return the result. | 867 868**Example** 869 870```ts 871import featureAbility from '@ohos.ability.featureAbility'; 872 873let dataAbilityHelper = featureAbility.acquireDataAbilityHelper( 874 'dataability:///com.example.jsapidemo.UserDataAbility'); 875dataAbilityHelper.call('dataability:///com.example.jsapidemo.UserDataAbility', 876 'method', 'arg', {'key1':'value1'}, (err, data) => { 877 if (err) { 878 console.error('Operation failed. Cause: ' + err); 879 return; 880 } 881 console.info('Operation succeeded: ' + data); 882}); 883``` 884 885## DataAbilityHelper.executeBatch 886 887executeBatch(uri: string, operations: Array\<DataAbilityOperation>, callback: AsyncCallback\<Array\<DataAbilityResult>>): void; 888 889Operates data in the database in batches. This API uses an asynchronous callback to return the result. 890 891**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 892 893**Parameters** 894 895| Name | Type | Mandatory| Description | 896| ----------| ---------------------------------| ---- | ------------------------------------------------ | 897| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.| 898| operations | Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)> | Yes | An array holding the data operations on the database. | 899| callback | AsyncCallback\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>> | Yes | Callback used to return the result of each operation in the **DataAbilityResult** array. | 900 901**Example** 902 903```ts 904import featureAbility from '@ohos.ability.featureAbility'; 905 906// Select the operations to be performed on the database according to the DataAbilityOperation array. 907let op=new Array(); 908let dataAbilityHelper = featureAbility.acquireDataAbilityHelper( 909 'dataability:///com.example.jsapidemo.UserDataAbility'); 910dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', 911 op, (err, data) => { 912 if (err) { 913 console.error('Operation failed. Cause: ' + err); 914 return; 915 } 916 console.info('Operation succeeded: ' + data); 917}); 918``` 919 920## DataAbilityHelper.executeBatch 921 922executeBatch(uri: string, operations: Array\<DataAbilityOperation>): Promise\<Array\<DataAbilityResult>>; 923 924Operates data in the database in batches. This API uses a promise to return the result. 925 926**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 927 928**Parameters** 929 930| Name | Type | Mandatory| Description | 931| ---------- | -------------------------------| ---- | ------------------------------------------------ | 932| uri | string | Yes | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'.| 933| operations | Array\<[DataAbilityOperation](js-apis-inner-ability-dataAbilityOperation.md)> | Yes | An array holding the data operations on the database. | 934 935**Return value** 936 937| Type| Description| 938|------ | ------- | 939|Promise\<Array\<[DataAbilityResult](js-apis-inner-ability-dataAbilityResult.md)>> | Promise used to return the result of each operation in the **DataAbilityResult** array.| 940 941**Example** 942 943```ts 944import featureAbility from '@ohos.ability.featureAbility'; 945 946// Select the operations to be performed on the database according to the DataAbilityOperation array. 947let op=new Array(); 948let dataAbilityHelper = featureAbility.acquireDataAbilityHelper( 949 'dataability:///com.example.jsapidemo.UserDataAbility'); 950dataAbilityHelper.executeBatch('dataability:///com.example.jsapidemo.UserDataAbility', 951 op).then((data) => { 952 console.info('Operation succeeded: ' + data); 953}).catch((error) => { 954 console.error('Operation failed. Cause: ' + error); 955}); 956 957``` 958 959## PacMap 960 961[key: string]: number | string | boolean | Array\<string | number | boolean> | null; 962 963**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel 964 965| Name| Type| Mandatory| Description| 966| ------ | ------ | ------ | ------ | 967| [key: string] | number \| string \| boolean \| Array\<string \| number \| boolean\> \| null | Yes| Data stored in key-value pairs.| 968