openharmony 鸿蒙 js-apis-data-dataSharePredicates

2025-06-12 浏览 (1)

@ohos.data.dataSharePredicates (DataShare Predicates)

DataSharePredicates provides a filter object to query data in a database by using DataShare APIs. It is often used to update, delete, and query 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 '@kit.ArkData';

DataSharePredicates

Provides APIs 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 it.

equalTo10+

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

Creates a DataSharePredicates object to search for the records in the specified column that are equal to the given 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")

and10+

and(): DataSharePredicates

Creates a DataSharePredicates object to add the AND condition.

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)

orderByAsc10+

orderByAsc(field: string): DataSharePredicates

Creates a DataSharePredicates object that sorts records 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

Creates 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")

limit10+

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

Creates a DataSharePredicates object to specify the number of records in the result 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 records. The value should be a positive integer. If a value less than or equal to 0 is specified, the number of records is not limited.
offsetnumberYesStart position. The value should be a positive integer. If a value less than or equal to 0 is specified, the query result is returned from the first element.

Return value

TypeDescription
DataSharePredicatesDataSharePredicates object created.

Example

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

in10+

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

Creates a DataSharePredicates object to search for the records in the specified column that are within the specified range.

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])

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkData (ArkData Management)

harmony 鸿蒙Data

harmony 鸿蒙OH_Cursor

harmony 鸿蒙OH_Predicates

harmony 鸿蒙OH_Rdb_Config

harmony 鸿蒙OH_Rdb_Store

harmony 鸿蒙OH_VBucket

harmony 鸿蒙OH_VObject

harmony 鸿蒙Preferences

harmony 鸿蒙_r_d_b

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