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