harmony 鸿蒙@ohos.data.dataSharePredicates (Data Share Predicates)

2022-08-09 浏览 (793)

@ohos.data.dataSharePredicates (Data Share Predicates)

You can use DataSharePredicates to specify conditions for updating, deleting, and querying data when DataShare is used to manage data.

The APIs provided by DataSharePredicates correspond to the filter criteria of the database. Before using the APIs, you need to have basic database knowledge.

NOTE

  • The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The APIs of this module can be used only in the stage model.

Modules to Import

import dataSharePredicates from '@ohos.data.dataSharePredicates';

DataSharePredicates

Provides methods for setting different DataSharePredicates objects. This type is not multi-thread safe. If a DataSharePredicates instance is operated by multiple threads at the same time in an application, use a lock for the instance.

equalTo10+

equalTo(field: string, value: ValueType): DataSharePredicates

Sets a DataSharePredicates object to match the data that is equal to the specified value.

Currently, only the relational database (RDB) and key-value database (KVDB, schema) support this DataSharePredicates object.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valueValueTypeYesValue to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose")

notEqualTo

notEqualTo(field: string, value: ValueType): DataSharePredicates

Sets a DataSharePredicates object to match the data that is not equal to the specified value.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valueValueTypeYesValue to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.notEqualTo("NAME", "Rose")

beginWrap

beginWrap(): DataSharePredicates

Adds a left parenthesis to this DataSharePredicates.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object with a left parenthesis.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()

endWrap

endWrap(): DataSharePredicates

Adds a right parenthesis to this DataSharePredicates object.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object with a right parenthesis.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()

or

or(): DataSharePredicates

Adds the OR condition to this DataSharePredicates object.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object with the OR condition.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "lisi")
    .or()
    .equalTo("NAME", "Rose")

and10+

and(): DataSharePredicates

Adds the AND condition to this DataSharePredicates object.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object with the AND condition.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "lisi")
    .and()
    .equalTo("SALARY", 200.5)

contains

contains(field: string, value: string): DataSharePredicates

Sets a DataSharePredicates object to match the data that contains the specified value.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valuestringYesValue to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.contains("NAME", "os")

beginsWith

beginsWith(field: string, value: string): DataSharePredicates

Sets a DataSharePredicates object to match the data that begins with the specified value.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valuestringYesStart value to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.beginsWith("NAME", "os")

endsWith

endsWith(field: string, value: string): DataSharePredicates

Sets a DataSharePredicates object to match the data that ends with the specified value.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valuestringYesEnd value to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.endsWith("NAME", "os")

isNull

isNull(field: string): DataSharePredicates

Sets a DataSharePredicates object to match the data whose value is null.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.isNull("NAME")

isNotNull

isNotNull(field: string): DataSharePredicates

Sets a DataSharePredicates object to match the data whose value is not null.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.isNotNull("NAME")

like

like(field: string, value: string): DataSharePredicates

Sets a DataSharePredicates object to match the data that matches the specified wildcard expression.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valuestringYesWildcard expression to match.
In the expression, '%' represents zero, one, or more digits or characters, and '_' represents a single digit or character. It is case insensitive.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.like("NAME", "%os%")

unlike

unlike(field: string, value: string): DataSharePredicates

Sets a DataSharePredicates object to match the data that does not match the specified wildcard expression.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valuestringYesWildcard expression to match.
In the expression, '%' represents zero, one, or more digits or characters, and '_' represents a single digit or character. It is case insensitive.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.unlike("NAME", "%os%")

glob

glob(field: string, value: string): DataSharePredicates

Sets a DataSharePredicates object to match the data that matches the specified wildcard expression.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valuestringYesWildcard expression to match.
In the expression, '*' represents zero, one, or more digits or characters, and '?' represents a single digit or character. It is case sensitive.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.glob("NAME", "?h*g")

between

between(field: string, low: ValueType, high: ValueType): DataSharePredicates

Sets a DataSharePredicates object to match the data that is within the specified range, including the start and end values.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
lowValueTypeYesThe lowest value of the range.
highValueTypeYesThe highest value of the range.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.between("AGE", 10, 50)

notBetween

notBetween(field: string, low: ValueType, high: ValueType): DataSharePredicates

Sets a DataSharePredicates object to match the data that is out of the specified range, excluding the start and end values.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
lowValueTypeYesThe lowest value of the range.
highValueTypeYesThe highest value of the range.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.notBetween("AGE", 10, 50)

greaterThan

greaterThan(field: string, value: ValueType): DataSharePredicates

Sets a DataSharePredicates object to match the data that is greater than the specified value.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valueValueTypeYesValue to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.greaterThan("AGE", 10)

lessThan

lessThan(field: string, value: ValueType): DataSharePredicates

Sets a DataSharePredicates object to match the data that is less than the specified value.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valueValueTypeYesValue to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.lessThan("AGE", 50)

greaterThanOrEqualTo

greaterThanOrEqualTo(field: string, value: ValueType): DataSharePredicates

Sets a DataSharePredicates object to match the data that is greater than or equal to the specified value.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valueValueTypeYesValue to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.greaterThanOrEqualTo("AGE", 10)

lessThanOrEqualTo

lessThanOrEqualTo(field: string, value: ValueType): DataSharePredicates

Sets a DataSharePredicates object to match the data that is less than or equal to the specified value.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valueValueTypeYesValue to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.lessThanOrEqualTo("AGE", 50)

orderByAsc10+

orderByAsc(field: string): DataSharePredicates

Sets a DataSharePredicates object that sorts data in ascending order.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.orderByAsc("AGE")

orderByDesc10+

orderByDesc(field: string): DataSharePredicates

Sets a DataSharePredicates object that sorts data in descending order.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.orderByDesc("AGE")

distinct

distinct(): DataSharePredicates

Sets a DataSharePredicates object to filter out duplicate data records.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose").distinct()

limit10+

limit(total: number, offset: number): DataSharePredicates

Sets a DataSharePredicates object to specify the number of results and the start position.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
totalnumberYesNumber of results.
offsetnumberYesStart position.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose").limit(10, 3)

groupBy

groupBy(fields: Array<string>): DataSharePredicates

Sets a DataSharePredicates object group the records according to the specified fields.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldsArray<string>YesNames of the columns by which the records are grouped.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.groupBy(["AGE", "NAME"])

indexedBy

indexedBy(field: string): DataSharePredicates

Sets a DataSharePredicates object to list data by the specified index.

Currently, only the RDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesName of the index column.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.indexedBy("SALARY_INDEX")

in10+

in(field: string, value: Array<ValueType>): DataSharePredicates

Sets a DataSharePredicates object to match the data that is within the specified value.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valueArray<ValueType>YesArray of the values to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.in("AGE", [18, 20])

notIn

notIn(field: string, value: Array<ValueType>): DataSharePredicates

Sets a DataSharePredicates object to match the data that is not in the specified value.

Currently, only the RDB and KVDB (schema) support this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
fieldstringYesColumn name in the database table.
valueArray<ValueType>YesArray of the values to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.notIn("NAME", ["Lisa", "Rose"])

prefixKey

prefixKey(prefix: string): DataSharePredicates

Sets a DataSharePredicates object to match the data with the specified key prefix.

Currently, only the KVDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
prefixstringYesKey prefix to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.prefixKey("NAME")

inKeys

inKeys(keys: Array<string>): DataSharePredicates

Sets a DataSharePredicates object to match the data whose keys are within the given range.

Currently, only the KVDB supports this DataSharePredicates object.

System API: This is a system API.

System capability: SystemCapability.DistributedDataManager.DataShare.Core

Parameters

NameTypeMandatoryDescription
inKeysArray<string>YesArray of the keys to match.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

let predicates = new dataSharePredicates.DataSharePredicates()
predicates.inKeys(["Lisa", "Rose"])

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/7cace1b87b344276b41d270b664522b0