1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import {AsyncCallback, Callback} from './basic'; 17 18/** 19 * Providers interfaces to creat a {@link KVManager} instance. 20 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 21 * @since 7 22 * @deprecated since 9 23 * @useinstead ohos.data.distributedKVStore 24 */ 25declare namespace distributedData { 26 /** 27 * Provides configuration information for {@link KVManager} instances, 28 * including the caller's package name and distributed network type. 29 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 30 * @since 7 31 * @deprecated since 9 32 * @useinstead ohos.data.distributedKVStore.KVManagerConfig 33 */ 34 interface KVManagerConfig { 35 /** 36 * Indicates the user information 37 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 38 * @since 7 39 * @deprecated since 9 40 */ 41 userInfo: UserInfo; 42 43 /** 44 * Indicates the bundleName 45 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 46 * @since 7 47 * @deprecated since 9 48 * @useinstead ohos.data.distributedKVStore.KVManagerConfig#bundleName 49 */ 50 bundleName: string; 51 } 52 53 /** 54 * Manages user information. 55 * 56 * <p>This class provides methods for obtaining the user ID and type, setting the user ID and type, 57 * and checking whether two users are the same. 58 * 59 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 60 * @since 7 61 * @deprecated since 9 62 */ 63 interface UserInfo { 64 /** 65 * Indicates the user ID to set 66 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 67 * @since 7 68 * @deprecated since 9 69 */ 70 userId?: string; 71 72 /** 73 * Indicates the user type to set 74 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 75 * @since 7 76 * @deprecated since 9 77 */ 78 userType?: UserType; 79 } 80 81 /** 82 * Enumerates user types. 83 * 84 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 85 * @since 7 86 * @deprecated since 9 87 */ 88 enum UserType { 89 /** 90 * Indicates a user that logs in to different devices using the same account. 91 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 92 * @since 7 93 * @deprecated since 9 94 */ 95 SAME_USER_ID = 0 96 } 97 98 /** 99 * KVStore constants 100 * 101 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 102 * @since 7 103 * @deprecated since 9 104 * @useinstead ohos.data.distributedKVStore.Constants 105 */ 106 namespace Constants { 107 /** 108 * max key length. 109 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 110 * @since 7 111 * @deprecated since 9 112 * @useinstead ohos.data.distributedKVStore.Constants#MAX_KEY_LENGTH 113 */ 114 const MAX_KEY_LENGTH = 1024; 115 116 /** 117 * max value length. 118 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 119 * @since 7 120 * @deprecated since 9 121 * @useinstead ohos.data.distributedKVStore.Constants#MAX_VALUE_LENGTH 122 */ 123 const MAX_VALUE_LENGTH = 4194303; 124 125 /** 126 * max device coordinate key length. 127 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 128 * @since 7 129 * @deprecated since 9 130 * @useinstead ohos.data.distributedKVStore.Constants#MAX_KEY_LENGTH_DEVICEs 131 */ 132 const MAX_KEY_LENGTH_DEVICE = 896; 133 134 /** 135 * max store id length. 136 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 137 * @since 7 138 * @deprecated since 9 139 * @useinstead ohos.data.distributedKVStore.Constants#MAX_STORE_ID_LENGTH 140 */ 141 const MAX_STORE_ID_LENGTH = 128; 142 143 /** 144 * max query length. 145 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 146 * @since 7 147 * @deprecated since 9 148 * @useinstead ohos.data.distributedKVStore.Constants#MAX_QUERY_LENGTH 149 */ 150 const MAX_QUERY_LENGTH = 512000; 151 152 /** 153 * max batch operation size. 154 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 155 * @since 7 156 * @deprecated since 9 157 * @useinstead ohos.data.distributedKVStore.Constants#MAX_BATCH_SIZE 158 */ 159 const MAX_BATCH_SIZE = 128; 160 } 161 162 /** 163 * Indicates the {@code ValueType}. 164 * 165 * <p>{@code ValueType} is obtained based on the value. 166 * 167 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 168 * @since 7 169 * @deprecated since 9 170 * @useinstead ohos.data.distributedKVStore.ValueType 171 */ 172 enum ValueType { 173 /** 174 * Indicates that the value type is string. 175 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 176 * @since 7 177 * @deprecated since 9 178 * @useinstead ohos.data.distributedKVStore.ValueType#STRING 179 */ 180 STRING = 0, 181 182 /** 183 * Indicates that the value type is int. 184 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 185 * @since 7 186 * @deprecated since 9 187 * @useinstead ohos.data.distributedKVStore.ValueType#INTEGER 188 */ 189 INTEGER = 1, 190 191 /** 192 * Indicates that the value type is float. 193 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 194 * @since 7 195 * @deprecated since 9 196 * @useinstead ohos.data.distributedKVStore.ValueType#FLOAT 197 */ 198 FLOAT = 2, 199 200 /** 201 * Indicates that the value type is byte array. 202 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 203 * @since 7 204 * @deprecated since 9 205 * @useinstead ohos.data.distributedKVStore.ValueType#BYTE_ARRAY 206 * */ 207 BYTE_ARRAY = 3, 208 209 /** 210 * Indicates that the value type is boolean. 211 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 212 * @since 7 213 * @deprecated since 9 214 * @useinstead ohos.data.distributedKVStore.ValueType#BOOLEAN 215 * */ 216 BOOLEAN = 4, 217 218 /** 219 * Indicates that the value type is double. 220 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 221 * @since 7 222 * @deprecated since 9 223 * @useinstead ohos.data.distributedKVStore.ValueType#DOUBLE 224 */ 225 DOUBLE = 5 226 } 227 228 /** 229 * Obtains {@code Value} objects stored in a {@link KVStore} database. 230 * 231 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 232 * @since 7 233 * @deprecated since 9 234 * @useinstead ohos.data.distributedKVStore.Value 235 */ 236 interface Value { 237 /** 238 * Indicates value type 239 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 240 * @see ValueType 241 * @type {number} 242 * @memberof Value 243 * @since 7 244 * @deprecated since 9 245 * @useinstead ohos.data.distributedKVStore.Value#type 246 */ 247 type: ValueType; 248 /** 249 * Indicates value 250 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 251 * @since 7 252 * @deprecated since 9 253 * @useinstead ohos.data.distributedKVStore.Value#value 254 */ 255 value: Uint8Array | string | number | boolean; 256 } 257 258 /** 259 * Provides key-value pairs stored in the distributed database. 260 * 261 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 262 * @since 7 263 * @deprecated since 9 264 * @useinstead ohos.data.distributedKVStore.Entry 265 */ 266 interface Entry { 267 /** 268 * Indicates key 269 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 270 * @since 7 271 * @deprecated since 9 272 * @useinstead ohos.data.distributedKVStore.Entry#key 273 */ 274 key: string; 275 /** 276 * Indicates value 277 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 278 * @since 7 279 * @deprecated since 9 280 * @useinstead ohos.data.distributedKVStore.Entry#value 281 */ 282 value: Value; 283 } 284 285 /** 286 * Receives notifications of all data changes, including data insertion, update, and deletion. 287 * 288 * <p>If you have subscribed to {@code KVStore}, you will receive data change notifications and obtain the changed data 289 * from the parameters in callback methods upon data insertion, update, or deletion. 290 * 291 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 292 * @since 7 293 * @deprecated since 9 294 * @useinstead ohos.data.distributedKVStore.ChangeNotification 295 */ 296 interface ChangeNotification { 297 /** 298 * Indicates data addition records. 299 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 300 * @since 7 301 * @deprecated since 9 302 * @useinstead ohos.data.distributedKVStore.ChangeNotification#insertEntries 303 */ 304 insertEntries: Entry[]; 305 /** 306 * Indicates data update records. 307 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 308 * @since 7 309 * @deprecated since 9 310 * @useinstead ohos.data.distributedKVStore.ChangeNotification#updateEntries 311 */ 312 updateEntries: Entry[]; 313 /** 314 * Indicates data deletion records. 315 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 316 * @since 7 317 * @deprecated since 9 318 * @useinstead ohos.data.distributedKVStore.ChangeNotification#deleteEntries 319 */ 320 deleteEntries: Entry[]; 321 /** 322 * Indicates from device id. 323 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 324 * @since 7 325 * @deprecated since 9 326 * @useinstead ohos.data.distributedKVStore.ChangeNotification#deviceId 327 */ 328 deviceId: string; 329 } 330 331 /** 332 * Indicates the database synchronization mode. 333 * 334 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 335 * @since 7 336 * @deprecated since 9 337 * @useinstead ohos.data.distributedKVStore.SyncMode 338 */ 339 enum SyncMode { 340 /** 341 * Indicates that data is only pulled from the remote end. 342 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 343 * @since 7 344 * @deprecated since 9 345 * @useinstead ohos.data.distributedKVStore.SyncMode#PULL_ONLY 346 */ 347 PULL_ONLY = 0, 348 /** 349 * Indicates that data is only pushed from the local end. 350 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 351 * @since 7 352 * @deprecated since 9 353 * @useinstead ohos.data.distributedKVStore.SyncMode#PUSH_ONLY 354 */ 355 PUSH_ONLY = 1, 356 /** 357 * Indicates that data is pushed from the local end, and then pulled from the remote end. 358 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 359 * @since 7 360 * @deprecated since 9 361 * @useinstead ohos.data.distributedKVStore.SyncMode#PUSH_PULL 362 */ 363 PUSH_PULL = 2 364 } 365 366 /** 367 * Describes the subscription type. 368 * 369 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 370 * @since 7 371 * @deprecated since 9 372 * @useinstead ohos.data.distributedKVStore.SubscribeType 373 */ 374 enum SubscribeType { 375 /** 376 * Subscription to local data changes 377 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 378 * @since 7 379 * @deprecated since 9 380 * @useinstead ohos.data.distributedKVStore.SubscribeType#SUBSCRIBE_TYPE_LOCAL 381 */ 382 SUBSCRIBE_TYPE_LOCAL = 0, 383 384 /** 385 * Subscription to remote data changes 386 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 387 * @since 7 388 * @deprecated since 9 389 * @useinstead ohos.data.distributedKVStore.SubscribeType#SUBSCRIBE_TYPE_REMOTE 390 */ 391 SUBSCRIBE_TYPE_REMOTE = 1, 392 393 /** 394 * Subscription to both local and remote data changes 395 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 396 * @since 7 397 * @deprecated since 9 398 * @useinstead ohos.data.distributedKVStore.SubscribeType#SUBSCRIBE_TYPE_ALL 399 */ 400 SUBSCRIBE_TYPE_ALL = 2, 401 } 402 403 /** 404 * Describes the {@code KVStore} type. 405 * 406 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 407 * @since 7 408 * @deprecated since 9 409 * @useinstead ohos.data.distributedKVStore.KVStoreType 410 */ 411 enum KVStoreType { 412 /** 413 * Device-collaboration database, as specified by {@code DeviceKVStore} 414 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 415 * @since 7 416 * @deprecated since 9 417 * @useinstead ohos.data.distributedKVStore.KVStoreType#DEVICE_COLLABORATION 418 */ 419 DEVICE_COLLABORATION = 0, 420 421 /** 422 * Single-version database, as specified by {@code SingleKVStore} 423 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 424 * @since 7 425 * @deprecated since 9 426 * @useinstead ohos.data.distributedKVStore.KVStoreType#SINGLE_VERSION 427 */ 428 SINGLE_VERSION = 1, 429 430 /** 431 * Multi-version database, as specified by {@code MultiKVStore} 432 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 433 * @since 7 434 * @deprecated since 9 435 */ 436 MULTI_VERSION = 2, 437 } 438 439 /** 440 * Describes the {@code KVStore} type. 441 * 442 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 443 * @since 7 444 * @deprecated since 9 445 * @useinstead ohos.data.distributedKVStore.SecurityLevel 446 */ 447 enum SecurityLevel { 448 /** 449 * NO_LEVEL: mains not set the security level. 450 * 451 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 452 * @since 7 453 * @deprecated since 9 454 */ 455 NO_LEVEL = 0, 456 457 /** 458 * S0: mains the db is public. 459 * There is no impact even if the data is leaked. 460 * 461 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 462 * @since 7 463 * @deprecated since 9 464 */ 465 S0 = 1, 466 467 /** 468 * S1: mains the db is low level security 469 * There are some low impact, when the data is leaked. 470 * 471 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 472 * @since 7 473 * @deprecated since 9 474 * @useinstead ohos.data.distributedKVStore.SecurityLevel#S1 475 */ 476 S1 = 2, 477 478 /** 479 * S2: mains the db is middle level security 480 * There are some major impact, when the data is leaked. 481 * 482 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 483 * @since 7 484 * @deprecated since 9 485 * @useinstead ohos.data.distributedKVStore.SecurityLevel#S2 486 */ 487 S2 = 3, 488 489 /** 490 * S3: mains the db is high level security 491 * There are some severity impact, when the data is leaked. 492 * 493 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 494 * @since 7 495 * @deprecated since 9 496 * @useinstead ohos.data.distributedKVStore.SecurityLevel#S3 497 */ 498 S3 = 5, 499 500 /** 501 * S4: mains the db is critical level security 502 * There are some critical impact, when the data is leaked. 503 * 504 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 505 * @since 7 506 * @deprecated since 9 507 * @useinstead ohos.data.distributedKVStore.SecurityLevel#S4 508 */ 509 S4 = 6, 510 } 511 512 /** 513 * Provides configuration options for creating a {@code KVStore}. 514 * 515 * <p>You can determine whether to create another database if a {@code KVStore} database is missing, 516 * whether to encrypt the database, and the database type. 517 * 518 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 519 * @since 7 520 * @deprecated since 9 521 * @useinstead ohos.data.distributedKVStore.Options 522 */ 523 interface Options { 524 /** 525 * Indicates whether to create a database when the database file does not exist 526 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 527 * @since 7 528 * @deprecated since 9 529 * @useinstead ohos.data.distributedKVStore.Options#createIfMissing 530 */ 531 createIfMissing?: boolean; 532 /** 533 * Indicates setting whether database files are encrypted 534 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 535 * @since 7 536 * @deprecated since 9 537 * @useinstead ohos.data.distributedKVStore.Options#encrypt 538 */ 539 encrypt?: boolean; 540 /** 541 * Indicates setting whether to back up database files 542 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 543 * @since 7 544 * @deprecated since 9 545 * @useinstead ohos.data.distributedKVStore.Options#backup 546 */ 547 backup?: boolean; 548 /** 549 * Indicates setting whether database files are automatically synchronized 550 * @permission ohos.permission.DISTRIBUTED_DATASYNC 551 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 552 * @since 7 553 * @deprecated since 9 554 * @useinstead ohos.data.distributedKVStore.Options#autoSync 555 */ 556 autoSync?: boolean; 557 /** 558 * Indicates setting the database type 559 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 560 * @since 7 561 * @deprecated since 9 562 * @useinstead ohos.data.distributedKVStore.Options#kvStoreType 563 */ 564 kvStoreType?: KVStoreType; 565 /** 566 * Indicates setting the database security level 567 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 568 * @since 7 569 * @deprecated since 9 570 * @useinstead ohos.data.distributedKVStore.Options#securityLevel 571 */ 572 securityLevel?: SecurityLevel; 573 /** 574 * Indicates schema object 575 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 576 * @since 8 577 * @deprecated since 9 578 * @useinstead ohos.data.distributedKVStore.Options#schema 579 */ 580 schema?: Schema; 581 } 582 583 /** 584 * Represents the database schema. 585 * 586 * You can create Schema objects and put them in Options when creating or opening the database. 587 * 588 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 589 * @since 8 590 * @deprecated since 9 591 * @useinstead ohos.data.distributedKVStore.Schema 592 */ 593 class Schema { 594 /** 595 * A constructor used to create a Schema instance. 596 * 597 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 598 * @since 8 599 * @deprecated since 9 600 * @useinstead ohos.data.distributedKVStore.Schema#constructor 601 */ 602 constructor() 603 604 /** 605 * Indicates the root json object. 606 * 607 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 608 * @since 8 609 * @deprecated since 9 610 * @useinstead ohos.data.distributedKVStore.Schema#root 611 */ 612 root: FieldNode; 613 /** 614 * Indicates the string array of json. 615 * 616 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 617 * @since 8 618 * @deprecated since 9 619 * @useinstead ohos.data.distributedKVStore.Schema#indexes 620 */ 621 indexes: Array<string>; 622 /** 623 * Indicates the mode of schema. 624 * 625 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 626 * @since 8 627 * @deprecated since 9 628 * @useinstead ohos.data.distributedKVStore.Schema#mode 629 */ 630 mode: number; 631 /** 632 * Indicates the skip size of schema. 633 * 634 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 635 * @since 8 636 * @deprecated since 9 637 * @useinstead ohos.data.distributedKVStore.Schema#skip 638 */ 639 skip: number; 640 } 641 642 /** 643 * Represents a node of a {@link Schema} instance. 644 * 645 * <p>Through the {@link Schema} instance, you can define the fields contained in the values stored in a database. 646 * 647 * <p>A FieldNode of the {@link Schema} instance is either a leaf or a non-leaf node. 648 * 649 * <p>The leaf node must have a value; the non-leaf node must have a child {@code FieldNode}. 650 * 651 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 652 * @since 8 653 * @deprecated since 9 654 * @useinstead ohos.data.distributedKVStore.FieldNode 655 */ 656 class FieldNode { 657 /** 658 * A constructor used to create a FieldNode instance with the specified field. 659 * name Indicates the field node name. 660 * 661 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 662 * @since 8 663 * @deprecated since 9 664 * @useinstead ohos.data.distributedKVStore.FieldNode#constructor 665 */ 666 constructor(name: string) 667 668 /** 669 * Adds a child node to this {@code FieldNode}. 670 * 671 * <p>Adding a child node makes this node a non-leaf node. Field value will be ignored if it has child node. 672 * 673 * @param child The field node to append. 674 * @returns Returns true if the child node is successfully added to this {@code FieldNode}; returns false otherwise. 675 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 676 * @since 8 677 * @deprecated since 9 678 * @useinstead ohos.data.distributedKVStore.FieldNode#appendChild 679 */ 680 appendChild(child: FieldNode): boolean; 681 682 /** 683 * Indicates the default value of field node. 684 * 685 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 686 * @since 8 687 * @deprecated since 9 688 * @useinstead ohos.data.distributedKVStore.FieldNode#default 689 */ 690 default: string; 691 /** 692 * Indicates the nullable of database field. 693 * 694 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 695 * @since 8 696 * @deprecated since 9 697 * @useinstead ohos.data.distributedKVStore.FieldNode#nullable 698 */ 699 nullable: boolean; 700 /** 701 * Indicates the type of value. 702 * 703 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 704 * @since 8 705 * @deprecated since 9 706 * @useinstead ohos.data.distributedKVStore.FieldNode#type 707 */ 708 type: number; 709 } 710 711 /** 712 * Provide methods to obtain the result set of the {@code KvStore} database. 713 * 714 * <p>The result set is created by using the {@code getResultSet} method in the {@code DeviceKVStore} class. This interface also provides 715 * methods for moving the data read position in the result set. 716 * 717 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 718 * @since 7 719 * @deprecated since 9 720 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet 721 */ 722 interface KvStoreResultSet { 723 /** 724 * Obtains the number of lines in a result set. 725 * 726 * @returns Returns the number of lines. 727 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 728 * @since 8 729 * @deprecated since 9 730 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#getCount 731 */ 732 getCount(): number; 733 734 /** 735 * Obtains the current read position in a result set. 736 * 737 * @returns Returns the current read position. The read position starts with 0. 738 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 739 * @since 8 740 * @deprecated since 9 741 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#getPosition 742 */ 743 getPosition(): number; 744 745 /** 746 * Moves the read position to the first line. 747 * 748 * <p>If the result set is empty, false is returned. 749 * 750 * @returns Returns true if the operation succeeds; return false otherwise. 751 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 752 * @since 8 753 * @deprecated since 9 754 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#moveToFirst 755 */ 756 moveToFirst(): boolean; 757 758 /** 759 * Moves the read position to the last line. 760 * 761 * <p>If the result set is empty, false is returned. 762 * 763 * @returns Returns true if the operation succeeds; return false otherwise. 764 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 765 * @since 8 766 * @deprecated since 9 767 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#moveToLast 768 */ 769 moveToLast(): boolean; 770 771 /** 772 * Moves the read position to the next line. 773 * 774 * <p>If the result set is empty or the data in the last line is being read, false is returned. 775 * 776 * @returns Returns true if the operation succeeds; return false otherwise. 777 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 778 * @since 8 779 * @deprecated since 9 780 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#moveToNext 781 */ 782 moveToNext(): boolean; 783 784 /** 785 * Moves the read position to the previous line. 786 * 787 * <p>If the result set is empty or the data in the first line is being read, false is returned. 788 * 789 * @returns Returns true if the operation succeeds; return false otherwise. 790 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 791 * @since 8 792 * @deprecated since 9 793 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#moveToPrevious 794 */ 795 moveToPrevious(): boolean; 796 797 /** 798 * Moves the read position by a relative offset to the current position. 799 * 800 * @param offset Indicates the relative offset to the current position. A negative offset indicates moving backwards, and a 801 * positive offset indicates moving forwards. For example, if the current position is entry 1 and this offset is 2, 802 * the destination position will be entry 3; if the current position is entry 3 and this offset is -2, 803 * the destination position will be entry 1. The valid final position after moving forwards starts with 0. If the 804 * final position is invalid, false will be returned. 805 * @returns Returns true if the operation succeeds; return false otherwise. 806 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 807 * @since 8 808 * @deprecated since 9 809 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#move 810 */ 811 move(offset: number): boolean; 812 813 /** 814 * Moves the read position from 0 to an absolute position. 815 * 816 * @param position Indicates the absolute position. 817 * @returns Returns true if the operation succeeds; return false otherwise. 818 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 819 * @since 8 820 * @deprecated since 9 821 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#moveToPosition 822 */ 823 moveToPosition(position: number): boolean; 824 825 /** 826 * Checks whether the read position is the first line. 827 * 828 * @returns Returns true if the read position is the first line; returns false otherwise. 829 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 830 * @since 8 831 * @deprecated since 9 832 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#isFirst 833 */ 834 isFirst(): boolean; 835 836 /** 837 * Checks whether the read position is the last line. 838 * 839 * @returns Returns true if the read position is the last line; returns false otherwise. 840 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 841 * @since 8 842 * @deprecated since 9 843 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#isLast 844 */ 845 isLast(): boolean; 846 847 /** 848 * Checks whether the read position is before the last line. 849 * 850 * @returns Returns true if the read position is before the first line; returns false otherwise. 851 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 852 * @since 8 853 * @deprecated since 9 854 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#isBeforeFirst 855 */ 856 isBeforeFirst(): boolean; 857 858 /** 859 * Checks whether the read position is after the last line. 860 * 861 * @returns Returns true if the read position is after the last line; returns false otherwise. 862 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 863 * @since 8 864 * @deprecated since 9 865 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#isAfterLast 866 */ 867 isAfterLast(): boolean; 868 869 /** 870 * Obtains a key-value pair. 871 * 872 * @returns Returns a key-value pair. 873 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 874 * @since 8 875 * @deprecated since 9 876 * @useinstead ohos.data.distributedKVStore.KVStoreResultSet#getEntry 877 */ 878 getEntry(): Entry; 879 } 880 881 /** 882 * Represents a database query using a predicate. 883 * 884 * <p>This class provides a constructor used to create a {@code Query} instance, which is used to query data matching specified 885 * conditions in the database. 886 * 887 * <p>This class also provides methods for adding predicates to the {@code Query} instance. 888 * 889 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 890 * @since 8 891 * @deprecated since 9 892 * @useinstead ohos.data.distributedKVStore.Query 893 */ 894 class Query { 895 /** 896 * A constructor used to create a Query instance. 897 * 898 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 899 * @since 8 900 * @deprecated since 9 901 * @useinstead ohos.data.distributedKVStore.Query#constructor 902 */ 903 constructor() 904 905 /** 906 * Resets this {@code Query} object. 907 * 908 * @returns Returns the reset {@code Query} object. 909 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 910 * @since 8 911 * @deprecated since 9 912 * @useinstead ohos.data.distributedKVStore.Query#reset 913 */ 914 reset(): Query; 915 916 /** 917 * Constructs a {@code Query} object to query entries with the specified field whose value is equal to the specified long value. 918 * 919 * @param field Indicates the field, which must start with $. and cannot contain ^. 920 * @param value IIndicates the long value. 921 * @returns Returns the {@coed Query} object. 922 * @throws Throws this exception if input is invalid. 923 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 924 * @since 8 925 * @deprecated since 9 926 * @useinstead ohos.data.distributedKVStore.Query#equalTo 927 */ 928 equalTo(field: string, value: number | string | boolean): Query; 929 930 /** 931 * Constructs a {@code Query} object to query entries with the specified field whose value is not equal to the specified int value. 932 * 933 * @param field Indicates the field, which must start with $. and cannot contain ^. 934 * @param value Indicates the int value. 935 * @returns Returns the {@coed Query} object. 936 * @throws Throws this exception if input is invalid. 937 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 938 * @since 8 939 * @deprecated since 9 940 * @useinstead ohos.data.distributedKVStore.Query#notEqualTo 941 */ 942 notEqualTo(field: string, value: number | string | boolean): Query; 943 944 /** 945 * Constructs a {@code Query} object to query entries with the specified field whose value is greater than or equal to the 946 * specified int value. 947 * 948 * @param field Indicates the field, which must start with $. and cannot contain ^. 949 * @param value Indicates the int value. 950 * @returns Returns the {@coed Query} object. 951 * @throws Throws this exception if input is invalid. 952 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 953 * @since 8 954 * @deprecated since 9 955 * @useinstead ohos.data.distributedKVStore.Query#greaterThan 956 */ 957 greaterThan(field: string, value: number | string | boolean): Query; 958 959 /** 960 * Constructs a {@code Query} object to query entries with the specified field whose value is less than the specified int value. 961 * 962 * @param field Indicates the field, which must start with $. and cannot contain ^. 963 * @param value Indicates the int value. 964 * @returns Returns the {@coed Query} object. 965 * @throws Throws this exception if input is invalid. 966 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 967 * @since 8 968 * @deprecated since 9 969 * @useinstead ohos.data.distributedKVStore.Query#lessThan 970 */ 971 lessThan(field: string, value: number | string): Query; 972 973 /** 974 * Constructs a {@code Query} object to query entries with the specified field whose value is greater than or equal to the 975 * specified int value. 976 * 977 * @param field Indicates the field, which must start with $. and cannot contain ^. 978 * @param value Indicates the int value. 979 * @returns Returns the {@coed Query} object. 980 * @throws Throws this exception if input is invalid. 981 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 982 * @since 8 983 * @deprecated since 9 984 * @useinstead ohos.data.distributedKVStore.Query#greaterThanOrEqualTo 985 */ 986 greaterThanOrEqualTo(field: string, value: number | string): Query; 987 988 /** 989 * Constructs a {@code Query} object to query entries with the specified field whose value is less than or equal to the 990 * specified int value. 991 * 992 * @param field Indicates the field, which must start with $. and cannot contain ^. 993 * @param value Indicates the int value. 994 * @returns Returns the {@coed Query} object. 995 * @throws Throws this exception if input is invalid. 996 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 997 * @since 8 998 * @deprecated since 9 999 * @useinstead ohos.data.distributedKVStore.Query#lessThanOrEqualTo 1000 */ 1001 lessThanOrEqualTo(field: string, value: number | string): Query; 1002 1003 /** 1004 * Constructs a {@code Query} object to query entries with the specified field whose value is null. 1005 * 1006 * @param field Indicates the field, which must start with $. and cannot contain ^. 1007 * @returns Returns the {@coed Query} object. 1008 * @throws Throws this exception if input is invalid. 1009 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1010 * @since 8 1011 * @deprecated since 9 1012 * @useinstead ohos.data.distributedKVStore.Query#isNull 1013 */ 1014 isNull(field: string): Query; 1015 1016 /** 1017 * Constructs a {@code Query} object to query entries with the specified field whose value is within the specified int value list. 1018 * 1019 * @param field Indicates the field, which must start with $. and cannot contain ^. 1020 * @param valueList Indicates the int value list. 1021 * @returns Returns the {@coed Query} object. 1022 * @throws Throws this exception if input is invalid. 1023 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1024 * @since 8 1025 * @deprecated since 9 1026 * @useinstead ohos.data.distributedKVStore.Query#inNumber 1027 */ 1028 inNumber(field: string, valueList: number[]): Query; 1029 1030 /** 1031 * Constructs a {@code Query} object to query entries with the specified field whose value is within the specified string value list. 1032 * 1033 * @param field Indicates the field, which must start with $. and cannot contain ^. 1034 * @param valueList Indicates the string value list. 1035 * @returns Returns the {@coed Query} object. 1036 * @throws Throws this exception if input is invalid. 1037 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1038 * @since 8 1039 * @deprecated since 9 1040 * @useinstead ohos.data.distributedKVStore.Query#inString 1041 */ 1042 inString(field: string, valueList: string[]): Query; 1043 1044 /** 1045 * Constructs a {@code Query} object to query entries with the specified field whose value is not within the specified int value list. 1046 * 1047 * @param field Indicates the field, which must start with $. and cannot contain ^. 1048 * @param valueList Indicates the int value list. 1049 * @returns Returns the {@coed Query} object. 1050 * @throws Throws this exception if input is invalid. 1051 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1052 * @since 8 1053 * @deprecated since 9 1054 * @useinstead ohos.data.distributedKVStore.Query#notInNumber 1055 */ 1056 notInNumber(field: string, valueList: number[]): Query; 1057 1058 /** 1059 * Constructs a {@code Query} object to query entries with the specified field whose value is not within the specified string value list. 1060 * 1061 * @param field Indicates the field, which must start with $. and cannot contain ^. 1062 * @param valueList Indicates the string value list. 1063 * @returns Returns the {@coed Query} object. 1064 * @throws Throws this exception if input is invalid. 1065 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1066 * @since 8 1067 * @deprecated since 9 1068 * @useinstead ohos.data.distributedKVStore.Query#notInString 1069 */ 1070 notInString(field: string, valueList: string[]): Query; 1071 1072 /** 1073 * Constructs a {@code Query} object to query entries with the specified field whose value is similar to the specified string value. 1074 * 1075 * @param field Indicates the field, which must start with $. and cannot contain ^. 1076 * @param value Indicates the string value. 1077 * @returns Returns the {@coed Query} object. 1078 * @throws Throws this exception if input is invalid. 1079 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1080 * @since 8 1081 * @deprecated since 9 1082 * @useinstead ohos.data.distributedKVStore.Query#like 1083 */ 1084 like(field: string, value: string): Query; 1085 1086 /** 1087 * Constructs a {@code Query} object to query entries with the specified field whose value is not similar to the specified string value. 1088 * 1089 * @param field Indicates the field, which must start with $. and cannot contain ^. 1090 * @param value Indicates the string value. 1091 * @returns Returns the {@coed Query} object. 1092 * @throws Throws this exception if input is invalid. 1093 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1094 * @since 8 1095 * @deprecated since 9 1096 * @useinstead ohos.data.distributedKVStore.Query#unlike 1097 */ 1098 unlike(field: string, value: string): Query; 1099 1100 /** 1101 * Constructs a {@code Query} object with the and condition. 1102 * 1103 * <p>Multiple predicates should be connected using the and or or condition. 1104 * 1105 * @returns Returns the {@coed Query} object. 1106 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1107 * @since 8 1108 * @deprecated since 9 1109 * @useinstead ohos.data.distributedKVStore.Query#and 1110 */ 1111 and(): Query; 1112 1113 /** 1114 * Constructs a {@code Query} object with the or condition. 1115 * 1116 * <p>Multiple predicates should be connected using the and or or condition. 1117 * 1118 * @returns Returns the {@coed Query} object. 1119 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1120 * @since 8 1121 * @deprecated since 9 1122 * @useinstead ohos.data.distributedKVStore.Query#or 1123 */ 1124 or(): Query; 1125 1126 /** 1127 * Constructs a {@code Query} object to sort the query results in ascending order. 1128 * 1129 * @param field Indicates the field, which must start with $. and cannot contain ^. 1130 * @returns Returns the {@coed Query} object. 1131 * @throws Throws this exception if input is invalid. 1132 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1133 * @since 8 1134 * @deprecated since 9 1135 * @useinstead ohos.data.distributedKVStore.Query#orderByAsc 1136 */ 1137 orderByAsc(field: string): Query; 1138 1139 /** 1140 * Constructs a {@code Query} object to sort the query results in descending order. 1141 * 1142 * @param field Indicates the field, which must start with $. and cannot contain ^. 1143 * @returns Returns the {@coed Query} object. 1144 * @throws Throws this exception if input is invalid. 1145 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1146 * @since 8 1147 * @deprecated since 9 1148 * @useinstead ohos.data.distributedKVStore.Query#orderByDesc 1149 */ 1150 orderByDesc(field: string): Query; 1151 1152 /** 1153 * Constructs a {@code Query} object to specify the number of results and the start position. 1154 * 1155 * @param total Indicates the number of results. 1156 * @param offset Indicates the start position. 1157 * @returns Returns the {@coed Query} object. 1158 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1159 * @since 8 1160 * @deprecated since 9 1161 * @useinstead ohos.data.distributedKVStore.Query#limit 1162 */ 1163 limit(total: number, offset: number): Query; 1164 1165 /** 1166 * Creates a {@code query} condition with a specified field that is not null. 1167 * 1168 * @param field Indicates the specified field. 1169 * @returns Returns the {@coed Query} object. 1170 * @throws Throws this exception if input is invalid. 1171 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1172 * @since 8 1173 * @deprecated since 9 1174 * @useinstead ohos.data.distributedKVStore.Query#isNotNull 1175 */ 1176 isNotNull(field: string): Query; 1177 1178 /** 1179 * Creates a query condition group with a left bracket. 1180 * 1181 * <p>Multiple query conditions in an {@code Query} object can be grouped. The query conditions in a group can be used as a 1182 * whole to combine with other query conditions. 1183 * 1184 * @returns Returns the {@coed Query} object. 1185 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1186 * @since 8 1187 * @deprecated since 9 1188 * @useinstead ohos.data.distributedKVStore.Query#beginGroup 1189 */ 1190 beginGroup(): Query; 1191 1192 /** 1193 * Creates a query condition group with a right bracket. 1194 * 1195 * <p>Multiple query conditions in an {@code Query} object can be grouped. The query conditions in a group can be used as a 1196 * whole to combine with other query conditions. 1197 * 1198 * @returns Returns the {@coed Query} object. 1199 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1200 * @since 8 1201 * @deprecated since 9 1202 * @useinstead ohos.data.distributedKVStore.Query#endGroup 1203 */ 1204 endGroup(): Query; 1205 1206 /** 1207 * Creates a query condition with a specified key prefix. 1208 * 1209 * @param prefix Indicates the specified key prefix. 1210 * @returns Returns the {@coed Query} object. 1211 * @throws Throws this exception if input is invalid. 1212 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1213 * @since 8 1214 * @deprecated since 9 1215 * @useinstead ohos.data.distributedKVStore.Query#prefixKey 1216 */ 1217 prefixKey(prefix: string): Query; 1218 1219 /** 1220 * Sets a specified index that will be preferentially used for query. 1221 * 1222 * @param index Indicates the index to set. 1223 * @returns Returns the {@coed Query} object. 1224 * @throws Throws this exception if input is invalid. 1225 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1226 * @since 8 1227 * @deprecated since 9 1228 * @useinstead ohos.data.distributedKVStore.Query#setSuggestIndex 1229 */ 1230 setSuggestIndex(index: string): Query; 1231 1232 /** 1233 * Add device ID key prefix.Used by {@code DeviceKVStore}. 1234 * 1235 * @param deviceId Specify device id to query from. 1236 * @returns Returns the {@code Query} object with device ID prefix added. 1237 * @throws Throws this exception if input is invalid. 1238 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1239 * @since 8 1240 * @deprecated since 9 1241 * @useinstead ohos.data.distributedKVStore.Query#deviceId 1242 */ 1243 deviceId(deviceId: string): Query; 1244 1245 /** 1246 * Get a String that represents this {@code Query}. 1247 * 1248 * <p>The String would be parsed to DB query format. 1249 * The String length should be no longer than 500kb. 1250 * 1251 * @returns String representing this {@code Query}. 1252 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1253 * @since 8 1254 * @deprecated since 9 1255 * @useinstead ohos.data.distributedKVStore.Query#getSqlLike 1256 */ 1257 getSqlLike(): string; 1258 } 1259 1260 /** 1261 * Represents a key-value distributed database and provides methods for adding, deleting, modifying, querying, 1262 * and subscribing to distributed data. 1263 * 1264 * <p>You can create distributed databases of different types by {@link KVManager#getKVStore (Options, String)} 1265 * with input parameter {@code Options}. Distributed database types are defined in {@code KVStoreType}, 1266 * including {@code SingleKVStore}. 1267 * 1268 * 1269 * @version 1 1270 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1271 * @since 7 1272 * @deprecated since 9 1273 * @useinstead ohos.data.distributedKVStore.SingleKVStore 1274 */ 1275 interface KVStore { 1276 /** 1277 * Writes a key-value pair of the string type into the {@code KvStore} database. 1278 * 1279 * <p>If you do not want to synchronize this key-value pair to other devices, set the write option in the local database. 1280 * 1281 * @param key Indicates the key. The length must be less than {@code MAX_KEY_LENGTH}. 1282 * Spaces before and after the key will be cleared. 1283 * @param value Indicates the string value, which must be less than 4 MB as a UTF-8 byte array. 1284 * @throws Throws this exception if any of the following errors 1285 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1286 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1287 * @since 7 1288 * @deprecated since 9 1289 * @useinstead ohos.data.distributedKVStore.SingleKVStore#put 1290 */ 1291 put(key: string, value: Uint8Array | string | number | boolean, callback: AsyncCallback<void>): void; 1292 put(key: string, value: Uint8Array | string | number | boolean): Promise<void>; 1293 1294 /** 1295 * Deletes the key-value pair based on a specified key. 1296 * 1297 * @param key Indicates the key. The length must be less than {@code MAX_KEY_LENGTH}. 1298 * Spaces before and after the key will be cleared. 1299 * @throws Throws this exception if any of the following errors 1300 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and 1301 * {@code DB_ERROR}, and {@code KEY_NOT_FOUND}. 1302 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1303 * @since 7 1304 * @deprecated since 9 1305 * @useinstead ohos.data.distributedKVStore.SingleKVStore#delete 1306 */ 1307 delete(key: string, callback: AsyncCallback<void>): void; 1308 delete(key: string): Promise<void>; 1309 1310 /** 1311 * Registers a {@code KvStoreObserver} for the database. When data in the distributed database changes, the callback in 1312 * {@code KvStoreObserver} will be invoked. 1313 * 1314 * @param type Indicates the subscription type, which is defined in {@code SubscribeType}. 1315 * @param listener Indicates the observer of data change events in the distributed database. 1316 * @throws Throws this exception if any of the following errors 1317 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, 1318 * {@code DB_ERROR}, and {@code STORE_ALREADY_SUBSCRIBE}. 1319 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1320 * @since 7 1321 * @deprecated since 9 1322 * @useinstead ohos.data.distributedKVStore.SingleKVStore#on 1323 */ 1324 on(event: 'dataChange', type: SubscribeType, listener: Callback<ChangeNotification>): void; 1325 1326 /** 1327 * Subscribe the {@code KvStore} database based on the specified subscribeType and {@code KvStoreObserver}. 1328 * 1329 * @throws Throws this exception if any of the following errors 1330 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, 1331 * {@code DB_ERROR}, and {@code STORE_ALREADY_SUBSCRIBE}. 1332 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1333 * @since 7 1334 * @deprecated since 9 1335 * @useinstead ohos.data.distributedKVStore.SingleKVStore#on 1336 */ 1337 on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void; 1338 1339 /** 1340 * Unsubscribe the {@code KvStore} database based on the specified subscribeType and {@code KvStoreObserver}. 1341 * 1342 * @param listener Indicates the data change observer registered by {#subscribe(SubscribeType, KvStoreObserver)}. 1343 * @throws Throws this exception if any of the following errors 1344 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, 1345 * {@code DB_ERROR}, and {@code STORE_ALREADY_SUBSCRIBE}. 1346 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1347 * @since 8 1348 * @deprecated since 9 1349 * @useinstead ohos.data.distributedKVStore.SingleKVStore#off 1350 */ 1351 off(event: 'dataChange', listener?: Callback<ChangeNotification>): void; 1352 1353 /** 1354 * UnRegister the {@code KvStore} database synchronization callback. 1355 * 1356 * @param syncCallback Indicates the callback used to send the synchronization result to caller. 1357 * @throws Throws this exception if any of the following errors 1358 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, 1359 * {@code DB_ERROR}, and {@code STORE_ALREADY_SUBSCRIBE}. 1360 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1361 * @since 8 1362 * @deprecated since 9 1363 * @useinstead ohos.data.distributedKVStore.SingleKVStore#off 1364 */ 1365 off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]>>): void; 1366 1367 /** 1368 * Inserts key-value pairs into the {@code KvStore} database in batches. 1369 * 1370 * @param entries Indicates the key-value pairs to be inserted in batches. 1371 * @throws Throws this exception if a database error occurs. 1372 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1373 * @since 8 1374 * @deprecated since 9 1375 * @useinstead ohos.data.distributedKVStore.SingleKVStore#putBatch 1376 */ 1377 putBatch(entries: Entry[], callback: AsyncCallback<void>): void; 1378 putBatch(entries: Entry[]): Promise<void>; 1379 1380 /** 1381 * Deletes key-value pairs in batches from the {@code KvStore} database. 1382 * 1383 * @param keys Indicates the key-value pairs to be deleted in batches. 1384 * @throws Throws this exception if a database error occurs. 1385 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1386 * @since 8 1387 * @deprecated since 9 1388 * @useinstead ohos.data.distributedKVStore.SingleKVStore#deleteBatch 1389 */ 1390 deleteBatch(keys: string[], callback: AsyncCallback<void>): void; 1391 deleteBatch(keys: string[]): Promise<void>; 1392 1393 /** 1394 * Starts a transaction operation in the {@code KvStore} database. 1395 * 1396 * <p>After the database transaction is started, you can submit or roll back the operation. 1397 * 1398 * @throws Throws this exception if a database error occurs. 1399 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1400 * @since 8 1401 * @deprecated since 9 1402 * @useinstead ohos.data.distributedKVStore.SingleKVStore#startTransaction 1403 */ 1404 startTransaction(callback: AsyncCallback<void>): void; 1405 startTransaction(): Promise<void>; 1406 1407 /** 1408 * Submits a transaction operation in the {@code KvStore} database. 1409 * 1410 * @param callback 1411 * @throws Throws this exception if a database error occurs. 1412 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1413 * @since 8 1414 * @deprecated since 9 1415 * @useinstead ohos.data.distributedKVStore.SingleKVStore#commit 1416 */ 1417 commit(callback: AsyncCallback<void>): void; 1418 commit(): Promise<void>; 1419 1420 /** 1421 * Rolls back a transaction operation in the {@code KvStore} database. 1422 * 1423 * @throws Throws this exception if a database error occurs. 1424 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1425 * @since 8 1426 * @deprecated since 9 1427 * @useinstead ohos.data.distributedKVStore.SingleKVStore#rollback 1428 */ 1429 rollback(callback: AsyncCallback<void>): void; 1430 rollback(): Promise<void>; 1431 1432 /** 1433 * Sets whether to enable synchronization. 1434 * 1435 * @param enabled Specifies whether to enable synchronization. The value true means to enable 1436 * synchronization, and false means the opposite. 1437 * @throws Throws this exception if an internal service error occurs. 1438 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1439 * @since 8 1440 * @deprecated since 9 1441 * @useinstead ohos.data.distributedKVStore.SingleKVStore#enableSync 1442 */ 1443 enableSync(enabled: boolean, callback: AsyncCallback<void>): void; 1444 enableSync(enabled: boolean): Promise<void>; 1445 1446 /** 1447 * Sets synchronization range labels. 1448 * 1449 * <p>The labels determine the devices with which data will be synchronized. 1450 * 1451 * @param localLabels Indicates the synchronization labels of the local device. 1452 * @param remoteSupportLabels Indicates the labels of the devices with which data will be synchronized. 1453 * @throws Throws this exception if an internal service error occurs. 1454 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1455 * @since 8 1456 * @deprecated since 9 1457 * @useinstead ohos.data.distributedKVStore.SingleKVStore#setSyncRange 1458 */ 1459 setSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: AsyncCallback<void>): void; 1460 setSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise<void>; 1461 } 1462 1463 /** 1464 * Provides methods related to single-version distributed databases. 1465 * 1466 * <p>To create a {@code SingleKVStore} database, 1467 * you can use the {@link data.distributed.common.KVManager#getKVStore(Options, String)} method 1468 * with {@code KVStoreType} set to {@code SINGLE_VERSION} for the input parameter {@code Options}. 1469 * This database synchronizes data to other databases in time sequence. 1470 * The {@code SingleKVStore} database does not support 1471 * synchronous transactions, or data search using snapshots. 1472 * 1473 * @version 1 1474 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1475 * @since 7 1476 * @deprecated since 9 1477 * @useinstead ohos.data.distributedKVStore.SingleKVStore 1478 */ 1479 interface SingleKVStore extends KVStore { 1480 /** 1481 * Obtains the {@code String} value of a specified key. 1482 * 1483 * @param key Indicates the key of the boolean value to be queried. 1484 * @throws Throws this exception if any of the following errors occurs:{@code INVALID_ARGUMENT}, 1485 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}, and {@code KEY_NOT_FOUND}. 1486 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1487 * @since 7 1488 * @deprecated since 9 1489 * @useinstead ohos.data.distributedKVStore.SingleKVStore#get 1490 */ 1491 get(key: string, callback: AsyncCallback<Uint8Array | string | boolean | number>): void; 1492 get(key: string): Promise<Uint8Array | string | boolean | number>; 1493 1494 /** 1495 * Obtains all key-value pairs that match a specified key prefix. 1496 * 1497 * @param keyPrefix Indicates the key prefix to match. 1498 * @returns Returns the list of all key-value pairs that match the specified key prefix. 1499 * @throws Throws this exception if any of the following errors occurs:{@code INVALID_ARGUMENT}, 1500 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1501 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1502 * @since 8 1503 * @deprecated since 9 1504 * @useinstead ohos.data.distributedKVStore.SingleKVStore#getEntries 1505 */ 1506 getEntries(keyPrefix: string, callback: AsyncCallback<Entry[]>): void; 1507 getEntries(keyPrefix: string): Promise<Entry[]>; 1508 1509 /** 1510 * Obtains the list of key-value pairs matching the specified {@code Query} object. 1511 * 1512 * @param query Indicates the {@code Query} object. 1513 * @returns Returns the list of key-value pairs matching the specified {@code Query} object. 1514 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1515 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1516 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1517 * @since 8 1518 * @deprecated since 9 1519 * @useinstead ohos.data.distributedKVStore.SingleKVStore#getEntries 1520 */ 1521 getEntries(query: Query, callback: AsyncCallback<Entry[]>): void; 1522 getEntries(query: Query): Promise<Entry[]>; 1523 1524 /** 1525 * Obtains the result sets with a specified prefix from a {@code KvStore} database. The {@code KvStoreResultSet} object can be used to 1526 * query all key-value pairs that meet the search criteria. Each {@code KvStore} instance can have a maximum of four 1527 * {@code KvStoreResultSet} objects at the same time. If you have created four objects, calling this method will return a 1528 * failure. Therefore, you are advised to call the closeResultSet method to close unnecessary {@code KvStoreResultSet} objects 1529 * in a timely manner. 1530 * 1531 * @param keyPrefix Indicates the key prefix to match. 1532 * @throws Throws this exception if any of the following errors occurs:{@code INVALID_ARGUMENT}, 1533 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1534 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1535 * @since 8 1536 * @deprecated since 9 1537 * @useinstead ohos.data.distributedKVStore.SingleKVStore#getResultSet 1538 */ 1539 getResultSet(keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void; 1540 getResultSet(keyPrefix: string): Promise<KvStoreResultSet>; 1541 1542 /** 1543 * Obtains the {@code KvStoreResultSet} object matching the specified {@code Query} object. 1544 * 1545 * @param query Indicates the {@code Query} object. 1546 * @throws Throws this exception if any of the following errors occurs:{@code INVALID_ARGUMENT}, 1547 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1548 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1549 * @since 8 1550 * @deprecated since 9 1551 * @useinstead ohos.data.distributedKVStore.SingleKVStore#getResultSet 1552 */ 1553 getResultSet(query: Query, callback: AsyncCallback<KvStoreResultSet>): void; 1554 getResultSet(query: Query): Promise<KvStoreResultSet>; 1555 1556 /** 1557 * Closes a {@code KvStoreResultSet} object returned by getResultSet. 1558 * 1559 * @param resultSet Indicates the {@code KvStoreResultSet} object to close. 1560 * @throws Throws this exception if any of the following errors occurs:{@code INVALID_ARGUMENT}, 1561 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1562 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1563 * @since 8 1564 * @deprecated since 9 1565 * @useinstead ohos.data.distributedKVStore.SingleKVStore#closeResultSet 1566 */ 1567 closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback<void>): void; 1568 closeResultSet(resultSet: KvStoreResultSet): Promise<void>; 1569 1570 /** 1571 * Obtains the number of results matching the specified {@code Query} object. 1572 * 1573 * @param query Indicates the {@code Query} object. 1574 * @returns Returns the number of results matching the specified {@code Query} object. 1575 * @throws Throws this exception if any of the following errors occurs:{@code INVALID_ARGUMENT}, 1576 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1577 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1578 * @since 8 1579 * @deprecated since 9 1580 * @useinstead ohos.data.distributedKVStore.SingleKVStore#getResultSize 1581 */ 1582 getResultSize(query: Query, callback: AsyncCallback<number>): void; 1583 getResultSize(query: Query): Promise<number>; 1584 1585 /** 1586 * void removeDeviceData({@link String} deviceId) throws {@link KvStoreException} 1587 * 1588 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1589 * @since 8 1590 * @deprecated since 9 1591 * @useinstead ohos.data.distributedKVStore.SingleKVStore#removeDeviceData 1592 */ 1593 removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void; 1594 removeDeviceData(deviceId: string): Promise<void>; 1595 1596 /** 1597 * Synchronize the database to the specified devices with the specified delay allowed. 1598 * 1599 * @param deviceIds Indicates the list of devices to which to synchronize the database. 1600 * @param mode Indicates the synchronization mode. The value can be {@code PUSH}, {@code PULL}, or {@code PUSH_PULL}. 1601 * @param delayMs Indicates the delay allowed for the synchronization, in milliseconds. 1602 * @throws Throws this exception if any of the following errors 1603 * @permission ohos.permission.DISTRIBUTED_DATASYNC 1604 * occurs: {@code INVALID_ARGUMENT}, 1605 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1606 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1607 * @since 7 1608 * @deprecated since 9 1609 * @useinstead ohos.data.distributedKVStore.SingleKVStore#sync 1610 */ 1611 sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void; 1612 1613 /** 1614 * Register a {@code KvStoreObserver} for the database. When data in the distributed database changes, the callback 1615 * in the {@code KvStoreObserver} will be invoked. 1616 * 1617 * @param type Indicates the subscription type, which is defined in {@code SubscribeType}. 1618 * @param listener Indicates the observer of data change events in the distributed database. 1619 * @throws Throws this exception if no {@code SingleKvStore} database is available. 1620 * {@code DB_ERROR}, and {@code STORE_ALREADY_SUBSCRIBE}. 1621 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1622 * @since 8 1623 * @deprecated since 9 1624 * @useinstead ohos.data.distributedKVStore.SingleKVStore#on 1625 */ 1626 on(event: 'dataChange', type: SubscribeType, listener: Callback<ChangeNotification>): void; 1627 1628 /** 1629 * Register a SingleKvStore database synchronization callback. 1630 * <p> Sync result is returned through asynchronous callback. 1631 * 1632 * @param syncCallback Indicates the callback used to send the synchronization result to the caller. 1633 * @throws Throws this exception if no {@code SingleKvStore} database is available. 1634 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1635 * @since 8 1636 * @deprecated since 9 1637 * @useinstead ohos.data.distributedKVStore.SingleKVStore#on 1638 */ 1639 on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void; 1640 1641 /** 1642 * Unsubscribe the SingleKvStore database based on the specified subscribeType and {@code KvStoreObserver}. 1643 * 1644 * @param listener Indicates the data change observer registered by {#subscribe(SubscribeType, KvStoreObserver)}. 1645 * @throws Throws this exception if any of the following errors 1646 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, 1647 * {@code DB_ERROR}, and {@code STORE_ALREADY_SUBSCRIBE}. 1648 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1649 * @since 8 1650 * @deprecated since 9 1651 * @useinstead ohos.data.distributedKVStore.SingleKVStore#off 1652 */ 1653 off(event: 'dataChange', listener?: Callback<ChangeNotification>): void; 1654 1655 /** 1656 * UnRegister the SingleKvStore database synchronization callback. 1657 * 1658 * @throws Throws this exception if no {@code SingleKvStore} database is available. 1659 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1660 * @since 8 1661 * @deprecated since 9 1662 * @useinstead ohos.data.distributedKVStore.SingleKVStore#off 1663 */ 1664 off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]>>): void; 1665 1666 /** 1667 * Sets the default delay allowed for database synchronization 1668 * 1669 * @param defaultAllowedDelayMs Indicates the default delay allowed for the database synchronization, in milliseconds. 1670 * @throws Throws this exception if any of the following errors occurs:{@code INVALID_ARGUMENT}, 1671 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, and {@code DB_ERROR}. 1672 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1673 * @since 8 1674 * @deprecated since 9 1675 * @useinstead ohos.data.distributedKVStore.SingleKVStore#setSyncParam 1676 */ 1677 setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback<void>): void; 1678 setSyncParam(defaultAllowedDelayMs: number): Promise<void>; 1679 1680 /** 1681 * Get the security level of the database. 1682 * 1683 * @returns SecurityLevel {@code SecurityLevel} the security level of the database. 1684 * @throws Throws this exception if any of the following errors occurs:{@code SERVER_UNAVAILABLE}, 1685 * {@code IPC_ERROR}, and {@code DB_ERROR}. 1686 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1687 * @since 8 1688 * @deprecated since 9 1689 * @useinstead ohos.data.distributedKVStore.SingleKVStore#getSecurityLevel 1690 */ 1691 getSecurityLevel(callback: AsyncCallback<SecurityLevel>): void; 1692 getSecurityLevel(): Promise<SecurityLevel>; 1693 } 1694 1695 /** 1696 * Manages distributed data by device in a distributed system. 1697 * 1698 * <p>To create a {@code DeviceKVStore} database, you can use the {@link data.distributed.common.KVManager.getKvStore(Options, String)} 1699 * method with {@code KvStoreType} set to {@code DEVICE_COLLABORATION} for the input parameter Options. This database manages distributed 1700 * data by device, and cannot modify data synchronized from remote devices. When an application writes a key-value pair entry 1701 * into the database, the system automatically adds the ID of the device running the application to the key. 1702 * 1703 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1704 * @since 8 1705 * @deprecated since 9 1706 * @useinstead ohos.data.distributedKVStore.DeviceKVStore 1707 */ 1708 interface DeviceKVStore extends KVStore { 1709 /** 1710 * Obtains the {@code String} value matching a specified device ID and key. 1711 * 1712 * @param deviceId Indicates the device to be queried. 1713 * @param key Indicates the key of the value to be queried. 1714 * @returns Returns the value matching the given criteria. 1715 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1716 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}, and {@code KEY_NOT_FOUND}. 1717 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1718 * @since 8 1719 * @deprecated since 9 1720 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#get 1721 */ 1722 get(deviceId: string, key: string, callback: AsyncCallback<boolean | string | number | Uint8Array>): void; 1723 get(deviceId: string, key: string): Promise<boolean | string | number | Uint8Array>; 1724 1725 /** 1726 * Obtains all key-value pairs matching a specified device ID and key prefix. 1727 * 1728 * @param deviceId Identifies the device whose data is to be queried. 1729 * @param keyPrefix Indicates the key prefix to match. 1730 * @returns Returns the list of all key-value pairs meeting the given criteria. 1731 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1732 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}. 1733 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1734 * @since 8 1735 * @deprecated since 9 1736 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#getEntries 1737 */ 1738 getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback<Entry[]>): void; 1739 getEntries(deviceId: string, keyPrefix: string): Promise<Entry[]>; 1740 1741 /** 1742 * Obtains the list of key-value pairs matching the specified {@code Query} object. 1743 * 1744 * @param query Indicates the {@code Query} object. 1745 * @returns Returns the list of key-value pairs matching the specified {@code Query} object. 1746 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1747 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}. 1748 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1749 * @since 8 1750 * @deprecated since 9 1751 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#getEntries 1752 */ 1753 getEntries(query: Query, callback: AsyncCallback<Entry[]>): void; 1754 getEntries(query: Query): Promise<Entry[]>; 1755 1756 /** 1757 * Obtains the list of key-value pairs matching a specified device ID and {@code Query} object. 1758 * 1759 * @param deviceId Indicates the ID of the device to which the key-value pairs belong. 1760 * @param query Indicates the {@code Query} object. 1761 * @returns Returns the list of key-value pairs matching the specified {@code Query} object. 1762 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1763 * @since 8 1764 * @deprecated since 9 1765 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#getEntries 1766 */ 1767 getEntries(deviceId: string, query: Query, callback: AsyncCallback<Entry[]>): void; 1768 getEntries(deviceId: string, query: Query): Promise<Entry[]>; 1769 1770 /** 1771 * Obtains the {@code KvStoreResultSet} object matching the specified device ID and key prefix. 1772 * 1773 * <p>The {@code KvStoreResultSet} object can be used to query all key-value pairs that meet the search criteria. Each {@code KvStore} 1774 * instance can have a maximum of four {@code KvStoreResultSet} objects at the same time. If you have created four objects, 1775 * calling this method will return a failure. Therefore, you are advised to call the closeResultSet method to close unnecessary 1776 * {@code KvStoreResultSet} objects in a timely manner. 1777 * 1778 * @param deviceId Identifies the device whose data is to be queried. 1779 * @param keyPrefix Indicates the key prefix to match. 1780 * @returns Returns the {@code KvStoreResultSet} objects. 1781 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1782 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}. 1783 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1784 * @since 8 1785 * @deprecated since 9 1786 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#getResultSet 1787 */ 1788 getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void; 1789 getResultSet(deviceId: string, keyPrefix: string): Promise<KvStoreResultSet>; 1790 1791 /** 1792 * Obtains the {@code KvStoreResultSet} object matching the specified {@code Query} object. 1793 * 1794 * @param query Indicates the {@code Query} object. 1795 * @returns Returns the {@code KvStoreResultSet} object matching the specified {@code Query} object. 1796 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1797 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}. 1798 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1799 * @since 8 1800 * @deprecated since 9 1801 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#getResultSet 1802 */ 1803 getResultSet(query: Query, callback: AsyncCallback<KvStoreResultSet>): void; 1804 getResultSet(query: Query): Promise<KvStoreResultSet>; 1805 1806 /** 1807 * Obtains the {@code KvStoreResultSet} object matching a specified device ID and {@code Query} object. 1808 * 1809 * @param deviceId Indicates the ID of the device to which the {@code KvStoreResultSet} object belongs. 1810 * @param query Indicates the {@code Query} object. 1811 * @returns Returns the {@code KvStoreResultSet} object matching the specified {@code Query} object. 1812 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1813 * @since 8 1814 * @deprecated since 9 1815 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#getResultSet 1816 */ 1817 getResultSet(deviceId: string, query: Query, callback: AsyncCallback<KvStoreResultSet>): void; 1818 getResultSet(deviceId: string, query: Query): Promise<KvStoreResultSet>; 1819 1820 /** 1821 * Closes a {@code KvStoreResultSet} object returned by getResultSet. 1822 * 1823 * @param resultSet Indicates the {@code KvStoreResultSet} object to close. 1824 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1825 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}. 1826 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1827 * @since 8 1828 * @deprecated since 9 1829 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#closeResultSet 1830 */ 1831 closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback<void>): void; 1832 closeResultSet(resultSet: KvStoreResultSet): Promise<void>; 1833 1834 /** 1835 * Obtains the number of results matching the specified {@code Query} object. 1836 * 1837 * @param query Indicates the {@code Query} object. 1838 * @returns Returns the number of results matching the specified {@code Query} object. 1839 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1840 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}. 1841 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1842 * @since 8 1843 * @deprecated since 9 1844 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#getResultSize 1845 */ 1846 getResultSize(query: Query, callback: AsyncCallback<number>): void; 1847 getResultSize(query: Query): Promise<number>; 1848 1849 /** 1850 * Obtains the number of results matching a specified device ID and {@code Query} object. 1851 * 1852 * @param deviceId Indicates the ID of the device to which the results belong. 1853 * @param query Indicates the {@code Query} object. 1854 * @returns Returns the number of results matching the specified {@code Query} object. 1855 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1856 * @since 8 1857 * @deprecated since 9 1858 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#getResultSize 1859 */ 1860 getResultSize(deviceId: string, query: Query, callback: AsyncCallback<number>): void; 1861 getResultSize(deviceId: string, query: Query): Promise<number>; 1862 1863 /** 1864 * Removes data of a specified device from the current database. This method is used to remove only the data 1865 * synchronized from remote devices. This operation does not synchronize data to other databases or affect 1866 * subsequent data synchronization. 1867 * 1868 * @param deviceId Identifies the device whose data is to be removed. The value cannot be the current device ID. 1869 * @throws Throws this exception if any of the following errors occurs: {@code INVALID_ARGUMENT}, 1870 * {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, {@code DB_ERROR}. 1871 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 1872 * @since 8 1873 * @deprecated since 9 1874 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#removeDeviceData 1875 */ 1876 removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void; 1877 removeDeviceData(deviceId: string): Promise<void>; 1878 1879 /** 1880 * Synchronize the {@code DeviceKVStore} databases. 1881 * 1882 * <p>This method returns immediately and sync result will be returned through asynchronous callback. 1883 * 1884 * @permission ohos.permission.DISTRIBUTED_DATASYNC 1885 * @param deviceIds Indicates the list of IDs of devices whose 1886 * @param delayMs Indicates the delay allowed for the synchronization, in milliseconds. 1887 * {@code DeviceKVStore} databases are to be synchronized. 1888 * @param mode Indicates the synchronization mode, {@code PUSH}, {@code PULL}, or 1889 * {@code PUSH_PULL}. 1890 * @throws Throws this exception if no DeviceKVStore database is available. 1891 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1892 * @since 8 1893 * @deprecated since 9 1894 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#sync 1895 */ 1896 sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void; 1897 1898 /** 1899 * Register a {@code KvStoreObserver} for the database. When data in the distributed database changes, the 1900 * callback in the {@code KvStoreObserver} will be invoked. 1901 * 1902 * @param type Indicates the subscription type, which is defined in {@code SubscribeType}. 1903 * @param listener Indicates the observer of data change events in the distributed database. 1904 * @throws Throws this exception if any of the following errors 1905 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, 1906 * {@code DB_ERROR}, and {@code STORE_ALREADY_SUBSCRIBE}. 1907 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1908 * @since 8 1909 * @deprecated since 9 1910 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#on 1911 */ 1912 on(event: 'dataChange', type: SubscribeType, listener: Callback<ChangeNotification>): void; 1913 1914 1915 /** 1916 * Register a DeviceKVStore database synchronization callback. 1917 * 1918 * <p>Sync result is returned through asynchronous callback. 1919 * 1920 * @param syncCallback Indicates the callback used to send the synchronization result to the caller. 1921 * @throws Throws this exception if no DeviceKVStore database is available. 1922 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1923 * @since 8 1924 * @deprecated since 9 1925 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#on 1926 */ 1927 on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void; 1928 1929 /** 1930 * Unsubscribe the DeviceKVStore database based on the specified subscribeType and {@code KvStoreObserver}. 1931 * 1932 * @param listener Indicates the data change observer registered by {#subscribe(SubscribeType, KvStoreObserver)}. 1933 * @throws Throws this exception if any of the following errors 1934 * occurs: {@code SERVER_UNAVAILABLE}, {@code IPC_ERROR}, 1935 * {@code DB_ERROR}, and {@code STORE_ALREADY_SUBSCRIBE}. 1936 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1937 * @since 8 1938 * @deprecated since 9 1939 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#off 1940 */ 1941 off(event: 'dataChange', listener?: Callback<ChangeNotification>): void; 1942 1943 /** 1944 * UnRegister the DeviceKVStore database synchronization callback. 1945 * 1946 * @throws Throws this exception if no DeviceKVStore database is available. 1947 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1948 * @since 8 1949 * @deprecated since 9 1950 * @useinstead ohos.data.distributedKVStore.DeviceKVStore#off 1951 */ 1952 off(event: 'syncComplete', syncCallback?: Callback<Array<[string, number]>>): void; 1953 } 1954 1955 /** 1956 * Creates a {@link KVManager} instance based on the configuration information. 1957 * 1958 * <p>You must pass {@link KVManagerConfig} to provide configuration information 1959 * for creating the {@link KVManager} instance. 1960 * 1961 * @param config Indicates the {@link KVStore} configuration information, 1962 * including the user information and package name. 1963 * @returns Returns the {@code KVManager} instance. 1964 * @throws Throws exception if input is invalid. 1965 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1966 * @since 7 1967 * @deprecated since 9 1968 * @useinstead ohos.data.distributedKVStore#createKVManager 1969 */ 1970 function createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager>): void; 1971 function createKVManager(config: KVManagerConfig): Promise<KVManager>; 1972 1973 /** 1974 * Provides interfaces to manage a {@code KVStore} database, including obtaining, closing, and deleting the {@code KVStore}. 1975 * 1976 * @version 1 1977 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1978 * @since 7 1979 * @deprecated since 9 1980 * @useinstead ohos.data.distributedKVStore.KVManager 1981 */ 1982 interface KVManager { 1983 /** 1984 * Creates and obtains a {@code KVStore} database by specifying {@code Options} and {@code storeId}. 1985 * 1986 * @param options Indicates the options used for creating and obtaining the {@code KVStore} database, 1987 * including {@code isCreateIfMissing}, {@code isEncrypt}, and {@code KVStoreType}. 1988 * @param storeId Identifies the {@code KVStore} database. 1989 * The value of this parameter must be unique for the same application, 1990 * and different applications can share the same value. 1991 * @returns Returns a {@code KVStore}, or {@code SingleKVStore}. 1992 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 1993 * @since 7 1994 * @deprecated since 9 1995 * @useinstead ohos.data.distributedKVStore.KVManager#getKVStore 1996 */ 1997 getKVStore<T extends KVStore>(storeId: string, options: Options): Promise<T>; 1998 getKVStore<T extends KVStore>(storeId: string, options: Options, callback: AsyncCallback<T>): void; 1999 2000 /** 2001 * Closes the {@code KvStore} database. 2002 * 2003 * <p>Warning: This method is not thread-safe. If you call this method to stop a KvStore database that is running, your 2004 * thread may crash. 2005 * 2006 * <p>The {@code KvStore} database to close must be an object created by using the {@code getKvStore} method. Before using this 2007 * method, release the resources created for the database, for example, {@code KvStoreResultSet} for {@code SingleKvStore}, 2008 * otherwise closing the database will fail. If you are attempting to close a database that is already closed, an error 2009 * will be returned. 2010 * 2011 * @param kvStore Indicates the {@code KvStore} database to close. 2012 * @throws Throws this exception if any of the following errors 2013 * occurs:{@code INVALID_ARGUMENT}, {@code SERVER_UNAVAILABLE}, 2014 * {@code STORE_NOT_OPEN}, {@code STORE_NOT_FOUND}, {@code DB_ERROR}, 2015 * {@code PERMISSION_DENIED}, and {@code IPC_ERROR}. 2016 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 2017 * @since 8 2018 * @deprecated since 9 2019 * @useinstead ohos.data.distributedKVStore.KVManager#closeKVStore 2020 */ 2021 closeKVStore(appId: string, storeId: string, kvStore: KVStore, callback: AsyncCallback<void>): void; 2022 closeKVStore(appId: string, storeId: string, kvStore: KVStore): Promise<void>; 2023 2024 /** 2025 * Deletes the {@code KvStore} database identified by storeId. 2026 * 2027 * <p>Before using this method, close all {@code KvStore} instances in use that are identified by the same storeId. 2028 * 2029 * <p>You can use this method to delete a {@code KvStore} database not in use. After the database is deleted, all its data will be 2030 * lost. 2031 * 2032 * @param storeId Identifies the {@code KvStore} database to delete. 2033 * @throws Throws this exception if any of the following errors 2034 * occurs: {@code INVALID_ARGUMENT}, 2035 * {@code SERVER_UNAVAILABLE}, {@code STORE_NOT_FOUND}, 2036 * {@code DB_ERROR}, {@code PERMISSION_DENIED}, and {@code IPC_ERROR}. 2037 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 2038 * @since 8 2039 * @deprecated since 9 2040 * @useinstead ohos.data.distributedKVStore.KVManager#deleteKVStore 2041 */ 2042 deleteKVStore(appId: string, storeId: string, callback: AsyncCallback<void>): void; 2043 deleteKVStore(appId: string, storeId: string): Promise<void>; 2044 2045 /** 2046 * Obtains the storeId of all {@code KvStore} databases that are created by using the {@code getKvStore} method and not deleted by 2047 * calling the {@code deleteKvStore} method. 2048 * 2049 * @returns Returns the storeId of all created {@code KvStore} databases. 2050 * @throws Throws this exception if any of the following errors 2051 * occurs: {@code SERVER_UNAVAILABLE}, {@code DB_ERROR}, 2052 * {@code PERMISSION_DENIED}, and {@code IPC_ERROR}. 2053 * @syscap SystemCapability.DistributedDataManager.KVStore.Core 2054 * @since 8 2055 * @deprecated since 9 2056 * @useinstead ohos.data.distributedKVStore.KVManager#getAllKVStoreId 2057 */ 2058 getAllKVStoreId(appId: string, callback: AsyncCallback<string[]>): void; 2059 getAllKVStoreId(appId: string): Promise<string[]>; 2060 2061 /** 2062 * register DeviceChangeCallback to get notification when device's status changed 2063 * 2064 * @param deathCallback device change callback {@code DeviceChangeCallback} 2065 * @throws exception maybe occurs. 2066 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 2067 * @since 8 2068 * @deprecated since 9 2069 * @useinstead ohos.data.distributedKVStore.KVManager#on 2070 */ 2071 on(event: 'distributedDataServiceDie', deathCallback: Callback<void>): void; 2072 2073 /** 2074 * unRegister DeviceChangeCallback and can not receive notification 2075 * 2076 * @param deathCallback device change callback {@code DeviceChangeCallback} which has been registered. 2077 * @throws exception maybe occurs. 2078 * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore 2079 * @since 8 2080 * @deprecated since 9 2081 * @useinstead ohos.data.distributedKVStore.KVManager#off 2082 */ 2083 off(event: 'distributedDataServiceDie', deathCallback?: Callback<void>): void; 2084 } 2085} 2086 2087export default distributedData;