/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import {AsyncCallback, Callback} from './basic'; import {ValuesBucket} from './@ohos.data.ValuesBucket'; import dataSharePredicates from './@ohos.data.dataSharePredicates'; import Context from './application/Context'; /** * Provider interfaces to create a {@link KVManager} instance. * @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore * @since 9 */ declare namespace distributedKVStore { /** * Provides configuration information to create a {@link KVManager} instance, * which includes the caller's package name and ability or hap context. * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ interface KVManagerConfig { /** * Indicates the bundleName * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ bundleName: string; /** * Indicates the ability or hap context * @syscap SystemCapability.DistributedDataManager.KVStore.Core * if swap the area, you should close all the KV store and use the new Context to create the KVManager * @since 9 */ context: Context; } /** * KVStore constants * * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ interface Constants { /** * Max key length is 1024. * @constant {number} * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ readonly MAX_KEY_LENGTH: number; /** * Max value length is 4194303. * @constant {number} * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ readonly MAX_VALUE_LENGTH: number; /** * Max device coordinate key length is 896. * @constant {number} * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ readonly MAX_KEY_LENGTH_DEVICE: number; /** * Max store id length is 128. * @constant {number} * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ readonly MAX_STORE_ID_LENGTH: number; /** * Max query length is 512000. * @constant {number} * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ readonly MAX_QUERY_LENGTH: number; /** * Max batch operation size is 128. * @constant {number} * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ readonly MAX_BATCH_SIZE: number; } /** * Indicates the {@code ValueType}. * *
{@code ValueType} is obtained based on the value. * * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ enum ValueType { /** * Indicates that the value type is string. * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ STRING, /** * Indicates that the value type is int. * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ INTEGER, /** * Indicates that the value type is float. * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ FLOAT, /** * Indicates that the value type is byte array. * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 * */ BYTE_ARRAY, /** * Indicates that the value type is boolean. * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 * */ BOOLEAN, /** * Indicates that the value type is double. * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ DOUBLE, } /** * Obtains {@code Value} objects stored in a {@link SingleKVStore} or {@link DeviceKVStore} database. * * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ interface Value { /** * Indicates the value type * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @see ValueType * @since 9 */ type: ValueType; /** * Indicates the value * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ value: Uint8Array | string | number | boolean; } /** * Provides key-value pairs stored in the distributedKVStore. * * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ interface Entry { /** * Indicates the key * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ key: string; /** * Indicates the value * @syscap SystemCapability.DistributedDataManager.KVStore.Core * @since 9 */ value: Value; } /** * Receive notifications of all data changes, including data insertion, update, and deletion. * *
If you have subscribed to {@code SingleKVStore} or {@code DeviceKVStore}, you will receive
* data change notifications and obtain the changed data from the parameters in callback methods
* upon data insertion, update or deletion.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
interface ChangeNotification {
/**
* Indicates data insertion records.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
insertEntries: Entry[];
/**
* Indicates data update records.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
updateEntries: Entry[];
/**
* Indicates data deletion records.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
deleteEntries: Entry[];
/**
* Indicates the device id which brings the data change.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
deviceId: string;
}
/**
* Indicates the database synchronization mode.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
enum SyncMode {
/**
* Indicates that data is only pulled from the remote end.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
PULL_ONLY,
/**
* Indicates that data is only pushed from the local end.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
PUSH_ONLY,
/**
* Indicates that data is pushed from the local end, and then pulled from the remote end.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
PUSH_PULL,
}
/**
* Describes the subscription type.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
enum SubscribeType {
/**
* Subscription to local data changes
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
SUBSCRIBE_TYPE_LOCAL,
/**
* Subscription to remote data changes
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
SUBSCRIBE_TYPE_REMOTE,
/**
* Subscription to both local and remote data changes
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
SUBSCRIBE_TYPE_ALL,
}
/**
* Describes the KVStore type.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
enum KVStoreType {
/**
* Device-collaboration database, as specified by {@code DeviceKVStore}
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
DEVICE_COLLABORATION,
/**
* Single-version database, as specified by {@code SingleKVStore}
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
SINGLE_VERSION,
}
/**
* Describes the KVStore security level.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
enum SecurityLevel {
/**
* S1: means the db is in the low security level
* There are some low impact when the data is leaked.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
S1,
/**
* S2: means the db is in the middle security level
* There are some major impact when the data is leaked.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
S2,
/**
* S3: means the db is in the high security level
* There are some severity impact when the data is leaked.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
S3,
/**
* S4: means the db is in the critical security level
* There are some critical impact when the data is leaked.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
S4,
}
/**
* Provides configuration options to create a {@code SingleKVStore} or {@code DeviceKVStore}.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
interface Options {
/**
* Indicates whether to create a database when the database file does not exist
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
createIfMissing?: boolean;
/**
* Indicates whether database files to be encrypted
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
encrypt?: boolean;
/**
* Indicates whether to back up database files
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
backup?: boolean;
/**
* Indicates whether database files are automatically synchronized
* @permission ohos.permission.DISTRIBUTED_DATASYNC
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
autoSync?: boolean;
/**
* Indicates the database type
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
kvStoreType?: KVStoreType;
/**
* Indicates the database security level
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
securityLevel: SecurityLevel;
/**
* Indicates the database schema
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
schema?: Schema;
}
/**
* Represents the database schema.
*
* You can set the schema object in options when create or open the database.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
class Schema {
/**
* A constructor used to create a Schema instance.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
constructor()
/**
* Indicates the root json object.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
root: FieldNode;
/**
* Indicates the string array of json.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
indexes: Array With a {@link Schema} instance, you can define the value fields which stored in the database.
*
* A FieldNode of the {@link Schema} instance is either a leaf or a non-leaf node.
*
* The leaf node must have a value; the non-leaf node must have a child {@code FieldNode}.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
class FieldNode {
/**
* A constructor used to create a FieldNode instance with the specified field.
* name Indicates the field node name.
*
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
constructor(name: string)
/**
* Adds a child node to this {@code FieldNode}.
*
* Add a child node to makes this node a non-leaf node and field value will be ignored if it has a child node.
*
* @param {FieldNode} child - The field node to append.
* @returns Returns true if the child node is successfully added to this {@code FieldNode} and false otherwise.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
appendChild(child: FieldNode): boolean;
/**
* Indicates the default value of field node.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
default: string;
/**
* Indicates the nullable of database field.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
nullable: boolean;
/**
* Indicates the type of value.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
type: number;
}
/**
* Provides methods to operate the result set of the {@code SingleKVStore} or {@code DeviceKVStore} database.
*
* The result set is created by using the {@code getResultSet} method in the {@code SingleKVStore} or
* {@code DeviceKVStore} class. This interface also provides methods to move the data read
* position in the result set.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
interface KVStoreResultSet {
/**
* Obtains the number of lines in a result set.
*
* @returns Returns the number of lines.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
getCount(): number;
/**
* Obtains the current read position in a result set.
*
* @returns Returns the current read position. The read position starts with 0.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
getPosition(): number;
/**
* Moves the read position to the first line.
*
* If the result set is empty, false is returned.
*
* @returns Returns true if the operation succeeds; return false otherwise.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
moveToFirst(): boolean;
/**
* Moves the read position to the last line.
*
* If the result set is empty, false is returned.
*
* @returns Returns true if the operation succeeds; return false otherwise.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
moveToLast(): boolean;
/**
* Moves the read position to the next line.
*
* If the result set is empty or the data in the last line is being read, false is returned.
*
* @returns Returns true if the operation succeeds; return false otherwise.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
moveToNext(): boolean;
/**
* Moves the read position to the previous line.
*
* If the result set is empty or the data in the first line is being read, false is returned.
*
* @returns Returns true if the operation succeeds; return false otherwise.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
moveToPrevious(): boolean;
/**
* Moves the read position by a relative offset to the current position.
*
* @param {number} offset - Indicates the relative offset to the current position. A negative offset indicates moving
* backwards, and a positive offset indicates moving forwards. For example, if the current position is entry 1 and
* this offset is 2, the destination position will be entry 3; if the current position is entry 3 and this offset is -2,
* the destination position will be entry 1. The valid final position after moving forwards starts with 0. If the
* final position is invalid, false will be returned.
* @returns Returns true if the operation succeeds; return false otherwise.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
move(offset: number): boolean;
/**
* Moves the read position from 0 to an absolute position.
*
* @param {number} position - Indicates the absolute position.
* @returns Returns true if the operation succeeds; return false otherwise.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
moveToPosition(position: number): boolean;
/**
* Checks whether the read position is the first line.
*
* @returns Returns true if the read position is the first line; returns false otherwise.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
isFirst(): boolean;
/**
* Checks whether the read position is the last line.
*
* @returns Returns true if the read position is the last line; returns false otherwise.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
isLast(): boolean;
/**
* Checks whether the read position is before the last line.
*
* @returns Returns true if the read position is before the first line; returns false otherwise.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
isBeforeFirst(): boolean;
/**
* Checks whether the read position is after the last line.
*
* @returns Returns true if the read position is after the last line; returns false otherwise.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
isAfterLast(): boolean;
/**
* Obtains a key-value pair.
*
* @returns Returns a key-value pair.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
getEntry(): Entry;
}
/**
* Represents a database query using predicates.
*
* This class provides a constructor used to create a {@code Query} instance, which is used to query data
* matching specified conditions in the database.
*
* This class also provides methods to add predicates to the {@code Query} instance.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
class Query {
/**
* A constructor used to create a Query instance.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
constructor()
/**
* Resets this {@code Query} object.
*
* @returns Returns the reset {@code Query} object.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
reset(): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is equal to the specified long value.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {number|string|boolean} value - Indicates the value to be compared.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
equalTo(field: string, value: number | string | boolean): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is not equal to the specified int value.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {number|string|boolean} value - Indicates the value to be compared.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
notEqualTo(field: string, value: number | string | boolean): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is greater than or equal to the
* specified int value.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {number|string|boolean} value - Indicates the value to be compared.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
greaterThan(field: string, value: number | string | boolean): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is less than the specified int value.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {number|string} value - Indicates the value to be compared.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
lessThan(field: string, value: number | string): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is greater than or
* equal to the specified int value.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {number|string} value - Indicates the value to be compared.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
greaterThanOrEqualTo(field: string, value: number | string): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is less than or equal to the
* specified int value.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {number|string} value - Indicates the value to be compared.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
lessThanOrEqualTo(field: string, value: number | string): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is null.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
isNull(field: string): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is within the specified int value list.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {number[]} valueList - Indicates the int value list.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
inNumber(field: string, valueList: number[]): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is within the specified string value list.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {string[]} valueList - Indicates the string value list.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
inString(field: string, valueList: string[]): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is not within the specified int value list.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {number[]} valueList - Indicates the int value list.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
notInNumber(field: string, valueList: number[]): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is not within the specified string value list.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {string[]} valueList - Indicates the string value list.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
notInString(field: string, valueList: string[]): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is similar to the specified string value.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {string} value - Indicates the string value.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
like(field: string, value: string): Query;
/**
* Constructs a {@code Query} object to query entries with the specified field whose value is not similar to the specified string value.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @param {string} value - Indicates the string value.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
unlike(field: string, value: string): Query;
/**
* Constructs a {@code Query} object with the and condition.
*
* Multiple predicates should be connected using the and or or condition.
*
* @returns Returns the {@coed Query} object.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
and(): Query;
/**
* Constructs a {@code Query} object with the or condition.
*
* Multiple predicates should be connected using the and or or condition.
*
* @returns Returns the {@coed Query} object.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
or(): Query;
/**
* Constructs a {@code Query} object to sort the query results in ascending order.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
orderByAsc(field: string): Query;
/**
* Constructs a {@code Query} object to sort the query results in descending order.
*
* @param {string} field - Indicates the field, which must start with $. and cannot contain ^.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
orderByDesc(field: string): Query;
/**
* Constructs a {@code Query} object to specify the number of results and the start position.
*
* @param {number} total - Indicates the number of results.
* @param {number} offset - Indicates the start position.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
limit(total: number, offset: number): Query;
/**
* Creates a {@code Query} condition with a specified field that is not null.
*
* @param {string} field - Indicates the specified field.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
isNotNull(field: string): Query;
/**
* Creates a query condition group with a left bracket.
*
* Multiple query conditions in an {@code Query} object can be grouped. The query conditions in a group can be used as a
* whole to combine with other query conditions.
*
* @returns Returns the {@coed Query} object.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
beginGroup(): Query;
/**
* Creates a query condition group with a right bracket.
*
* Multiple query conditions in an {@code Query} object can be grouped. The query conditions in a group can be used as a
* whole to combine with other query conditions.
*
* @returns Returns the {@coed Query} object.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
endGroup(): Query;
/**
* Creates a query condition with a specified key prefix.
*
* @param {string} prefix - Indicates the specified key prefix.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
prefixKey(prefix: string): Query;
/**
* Sets a specified index that will be preferentially used for query.
*
* @param {string} index - Indicates the index to set.
* @returns Returns the {@coed Query} object.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
setSuggestIndex(index: string): Query;
/**
* Add device ID key prefix.Used by {@code DeviceKVStore}.
*
* @param {string} deviceId - Specify device id to query from.
* @returns Returns the {@code Query} object with device ID prefix added.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
deviceId(deviceId: string): Query;
/**
* Get a String that represents this {@code Query}.
*
* The String would be parsed to DB query format.
* The String length should be no longer than 500kb.
*
* @returns String representing this {@code Query}.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
getSqlLike(): string;
}
/**
* Provides methods related to single-version distributed databases.
*
* To create a {@code SingleKVStore} database,
* you can use the {@link data.distributed.common.KVManager#getKVStore(Options, String)} method
* with {@code KVStoreType} set to {@code SINGLE_VERSION} for the input parameter {@code Options}.
* This database synchronizes data to other databases in time sequence.
* The {@code SingleKVStore} database does not support
* synchronous transactions, or data search using snapshots.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
interface SingleKVStore {
/**
* Writes a key-value pair of the string type into the {@code SingleKVStore} database.
*
* If you do not want to synchronize this key-value pair to other devices, set the write option in the local database.
*
* @param {string} key - Indicates the key. Length must be less than {@code MAX_KEY_LENGTH}.
* Spaces before and after the key will be cleared.
* @param {Uint8Array|string|number|boolean} value - Indicates the value to be inserted.
* @param {AsyncCallback If you do not want to synchronize this key-value pair to other devices, set the write option in the local database.
*
* @param {string} key - Indicates the key. Length must be less than {@code MAX_KEY_LENGTH}.
* Spaces before and after the key will be cleared.
* @param {Uint8Array|string|number|boolean} value - Indicates the value to be inserted.
* @returns {Promise After the database transaction is started, you can submit or roll back the operation.
*
* @param {AsyncCallback After the database transaction is started, you can submit or roll back the operation.
*
* @returns {Promise The labels determine the devices with which data will be synchronized.
*
* @param {string[]} localLabels - Indicates the synchronization labels of the local device.
* @param {string[]} remoteSupportLabels - Indicates the labels of the devices with which
* data will be synchronized.
* @param {AsyncCallback The labels determine the devices with which data will be synchronized.
*
* @param {string[]} localLabels - Indicates the synchronization labels of the local device.
* @param {string[]} remoteSupportLabels - Indicates the labels of the devices with which
* data will be synchronized.
* @returns {Promise Sync result is returned through asynchronous callback.
*
* @param {Callback To create a {@code DeviceKVStore} database, you can use the {@link data.distributed.common.KVManager.getKVStore(Options, String)}
* method with {@code KVStoreType} set to {@code DEVICE_COLLABORATION} for the input parameter Options. This database manages distributed
* data by device, and cannot modify data synchronized from remote devices. When an application writes a key-value pair entry
* into the database, the system automatically adds the ID of the device running the application to the key.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
* @since 9
*/
interface DeviceKVStore extends SingleKVStore {
/**
* Obtains the value matching the local device ID and specified key.
*
* @param {string} key - Indicates the key. The length must be less than {@code MAX_KEY_LENGTH}.
* @param {AsyncCallback The {@code KVStoreResultSet} object can be used to query all key-value pairs that meet the search criteria. Each {@code DeviceKVStore}
* instance can have a maximum of four {@code KVStoreResultSet} objects at the same time. If you have created four objects,
* calling this method will return a failure. Therefore, you are advised to call the closeResultSet method to close unnecessary
* {@code KVStoreResultSet} objects in a timely manner.
*
* @param {string} deviceId - Identifies the device whose data is to be queried.
* @param {string} keyPrefix - Indicates the key prefix to match.
* @param {AsyncCallback The {@code KVStoreResultSet} object can be used to query all key-value pairs that meet the search criteria. Each {@code DeviceKVStore}
* instance can have a maximum of four {@code KVStoreResultSet} objects at the same time. If you have created four objects,
* calling this method will return a failure. Therefore, you are advised to call the closeResultSet method to close unnecessary
* {@code KVStoreResultSet} objects in a timely manner.
*
* @param {string} deviceId - Identifies the device whose data is to be queried.
* @param {string} keyPrefix - Indicates the key prefix to match.
* @returns {Promise You must pass {@link KVManagerConfig} to provide configuration information
* to create a {@link KVManager} instance.
*
* @param {KVManagerConfig} config - Indicates the KVStore configuration information,
* including the package name and context.
* @returns {KVManager}: the {@code KVManager} instance.
* @throws {BusinessError} 401 - if parameter check failed.
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
function createKVManager(config: KVManagerConfig): KVManager;
/**
* Provides interfaces to manage a {@code SingleKVStore} database, including obtaining, closing, and deleting the {@code SingleKVStore}.
*
* @syscap SystemCapability.DistributedDataManager.KVStore.Core
* @since 9
*/
interface KVManager {
/**
* Creates and obtains a KVStore database by specifying {@code Options} and {@code storeId}.
*
* @param {string} storeId - Identifies the KVStore database. The value of this parameter must be unique
* for the same application, and different applications can share the same value.
* @param {Options} options - Indicates the {@code Options} object used for creating and
* obtaining the KVStore database.
* @param {AsyncCallback Warning: This method is not thread-safe. If you call this method to stop a KVStore database that is running, your
* thread may crash.
*
* The KVStore database to close must be an object created by using the {@code getKVStore} method. Before using this
* method, release the resources created for the database, for example, {@code KVStoreResultSet} for KVStore, otherwise
* closing the database will fail.
*
* @param {string} appId - Identifies the application that the database belong to.
* @param {string} storeId - Identifies the KVStore database to close.
* @param {AsyncCallback Warning: This method is not thread-safe. If you call this method to stop a KVStore database that is running, your
* thread may crash.
*
* The KVStore database to close must be an object created by using the {@code getKVStore} method. Before using this
* method, release the resources created for the database, for example, {@code KVStoreResultSet} for KVStore, otherwise
* closing the database will fail.
*
* @param {string} appId - Identifies the application that the database belong to.
* @param {string} storeId - Identifies the KVStore database to close.
* @returns {Promise Before using this method, close all KVStore instances in use that are identified by the same storeId.
*
* You can use this method to delete a KVStore database not in use. After the database is deleted, all its data will be
* lost.
*
* @param {string} appId - Identifies the application that the database belong to.
* @param {string} storeId - Identifies the KVStore database to delete.
* @param {AsyncCallback Before using this method, close all KVStore instances in use that are identified by the same storeId.
*
* You can use this method to delete a KVStore database not in use. After the database is deleted, all its data will be
* lost.
*
* @param {string} appId - Identifies the application that the database belong to.
* @param {string} storeId - Identifies the KVStore database to delete.
* @returns {Promise If the data manager service is terminated,you need to re-subscribe to data change notifications and synchronization
* completion notifications, and calling the sync method will return a failure.
*
* @param {Callback The unregistered death callback must be a registered death callback of the database. If no death callback parameter
* is passed, all database death callbacks will be unregistered.
*
* @param {Callback