diff --git a/en/application-dev/reference/apis/js-apis-data-rdb.md b/en/application-dev/reference/apis/js-apis-data-rdb.md new file mode 100644 index 0000000000000000000000000000000000000000..6c109a2b54656472881cd2d2f3f3eb671cc49512 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-data-rdb.md @@ -0,0 +1,2642 @@ +# Relational Database + +>**NOTE:** +>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +## Modules to Import + +``` +import dataRdb from '@ohos.data.rdb' +``` + +## Required Permissions + +None + +## dataRdb.getRdbStore + +getRdbStore\(config: StoreConfig, version: number, callback: AsyncCallback\): void + +Obtains a relational database \(RDB\) store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a callback to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

config

+

StoreConfig

+

Yes

+

Configuration of the RDB store.

+

version

+

number

+

Yes

+

RDB store version.

+

callback

+

AsyncCallback<RdbStore>

+

Yes

+

Callback invoked to return the RDB store.

+
+ +- Example + + ``` + import dataRdb from '@ohos.data.rdb' + const STORE_CONFIG = { name: "RdbTest.db"} + const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" + dataRdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { + rdbStore.executeSql(SQL_CREATE_TABLE) + console.info(TAG + 'create table done.') + }) + ``` + + +## dataRdb.getRdbStore + +getRdbStore\(config: StoreConfig, version: number\): Promise + +Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a promise to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

config

+

StoreConfig

+

Yes

+

Configuration of the RDB store.

+

version

+

number

+

Yes

+

RDB store version.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<RdbStore>

+

Promise used to return the RDB store.

+
+ +- Example + + ``` + import dataRdb from '@ohos.data.rdb' + const STORE_CONFIG = { name: "RdbTest.db" } + const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" + let promise = dataRdb.getRdbStore(STORE_CONFIG, 1); + promise.then(async (rdbStore) => { + await rdbStore.executeSql(SQL_CREATE_TABLE, null) + }).catch((err) => { + expect(null).assertFail(); + }) + ``` + + +## dataRdb.deleteRdbStore + +deleteRdbStore\(name: string, callback: AsyncCallback\): void + +Deletes an RDB store. This method uses a callback to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Name of the RDB store to delete.

+

callback

+

AsyncCallback<void>

+

Yes

+

Callback invoked to return the result. If the RDB store is deleted, true will be returned. Otherwise, false will be returned.

+
+ +- Example + + ``` + import dataRdb from '@ohos.data.rdb' + dataRdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) { + console.info(TAG + 'delete store done.')}) + ``` + + +## dataRdb.deleteRdbStore + +deleteRdbStore\(name: string\): Promise + +Deletes an RDB store. This method uses a promise to return the result. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Name of the RDB store to delete.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<void>

+

Promise used to return the result. If the RDB store is deleted, true will be returned. Otherwise, false will be returned.

+
+ +- Example + + ``` + import dataRdb from '@ohos.data.rdb' + let promise = dataRdb.deleteRdbStore("RdbTest.db") + promise.then(()=>{ + console.info(TAG + 'delete store done.') + }) + ``` + + +## RdbPredicates + +Defines predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false. + +### constructor + +constructor\(name: string\) + +A constructor used to create an **RdbPredicates** object. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Database table name.

+
+ +- Example + + ``` + import dataRdb from '@ohos.data.rdb' + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + ``` + + +### equalTo + +equalTo\(field: string, value: ValueType\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

ValueType

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "lisi") + ``` + + +### notEqualTo + +notEqualTo\(field: string, value: ValueType\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

ValueType

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.notEqualTo("NAME", "lisi") + ``` + + +### beginWrap + +beginWrap\(\): RdbPredicates + +Adds a left parenthesis to the **RdbPredicates**. + +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates with a left parenthesis.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "lisi") + .beginWrap() + .equalTo("AGE", 18) + .or() + .equalTo("SALARY", 200.5) + .endWrap() + ``` + + +### endWrap + +endWrap\(\): RdbPredicates + +Adds a right parenthesis to the **RdbPredicates**. + +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates with a right parenthesis.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "lisi") + .beginWrap() + .equalTo("AGE", 18) + .or() + .equalTo("SALARY", 200.5) + .endWrap() + ``` + + +### or + +or\(\): RdbPredicates + +Adds the OR condition to the **RdbPredicates**. + +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates with the OR condition.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Lisa") + .or() + .equalTo("NAME", "Rose") + ``` + + +### and + +and\(\): RdbPredicates + +Adds the AND condition to the **RdbPredicates**. + +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates with the AND condition.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Lisa") + .and() + .equalTo("SALARY", 200.5) + ``` + + +### contains + +contains\(field: string, value: string\): RdbPredicat + +Sets the **RdbPredicates** to match a string containing the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

string

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.contains("NAME", "os") + ``` + + +### beginsWith + +beginsWith\(field: string, value: string\): RdbPredicates + +Sets the **RdbPredicates** to match a string that starts with the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

string

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.beginsWith("NAME", "os") + ``` + + +### endsWith + +endsWith\(field: string, value: string\): RdbPredicates + +Sets the **RdbPredicates** to match a string that ends with the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

string

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.endsWith("NAME", "se") + ``` + + +### isNull + +isNull\(field: string\): RdbPredicates + +Sets the **RdbPredicates** to match the field whose value is **null**. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.isNull("NAME") + ``` + + +### isNotNull + +isNotNull\(field: string\): RdbPredicates + +Sets the **RdbPredicates** to match the field whose value is not **null**. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.isNotNull("NAME") + ``` + + +### like + +like\(field: string, value: string\): RdbPredicates + +Sets the **RdbPredicates** to match a string that is similar to the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

string

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.like("NAME", "%os%") + ``` + + +### glob + +glob\(field: string, value: string\): RdbPredicates + +Sets the **RdbPredicates** to match the specified string. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

string

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.glob("NAME", "?h*g") + ``` + + +### between + +between\(field: string, low: ValueType, high: ValueType\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **ValueType** and value within the specified range. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

low

+

ValueType

+

Yes

+

Minimum value to match the RdbPredicates.

+

high

+

ValueType

+

Yes

+

Maximum value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.between("AGE", 10, 50) + ``` + + +### notBetween + +notBetween\(field: string, low: ValueType, high: ValueType\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

low

+

ValueType

+

Yes

+

Minimum value to match the RdbPredicates.

+

high

+

ValueType

+

Yes

+

Maximum value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.notBetween("AGE", 10, 50) + ``` + + +### greaterThan + +greaterThan\(field: string, value: ValueType\): RdbPredicatesgr + +Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

ValueType

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.greaterThan("AGE", 18) + ``` + + +### lessThan + +lessThan\(field: string, value: ValueType\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

ValueType

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.lessThan("AGE", 20) + ``` + + +### greaterThanOrEqualTo + +greaterThanOrEqualTo\(field: string, value: ValueType\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

ValueType

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.greaterThanOrEqualTo("AGE", 18) + ``` + + +### lessThanOrEqualTo + +lessThanOrEqualTo\(field: string, value: ValueType\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

ValueType

+

Yes

+

Value to match the RdbPredicates.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.lessThanOrEqualTo("AGE", 20) + ``` + + +### orderByAsc + +orderByAsc\(field: string\): RdbPredicates + +Sets the **RdbPredicates** to match the column with values sorted in ascending order. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the column with values sorted in the specified order.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.orderByAsc("NAME") + ``` + + +### orderByDesc + +orderByDesc\(field: string\): RdbPredicates + +Sets the **RdbPredicates** to match the column with values sorted in descending order. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the column with values sorted in the specified order.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.orderByDesc("AGE") + ``` + + +### distinct + +distinct\(\): RdbPredicates + +Sets the **RdbPredicates** to filter out duplicate records. + +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that can filter out duplicate records.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Rose").distinct("NAME") + let resultSet = await rdbStore.query(predicates, ["NAME"]) + ``` + + +### limitAs + +limitAs\(value: number\): RdbPredicates + +Sets the **RdbPredicates** to specify the maximum number of records. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

value

+

number

+

Yes

+

Maximum number of records.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that specifies the maximum number of records.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Rose").limitAs(3) + ``` + + +### offsetAs + +offsetAs\(rowOffset: number\): RdbPredicates + +Sets the **RdbPredicates** to specify the start position of the returned result. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

rowOffset

+

number

+

Yes

+

Number of rows to offset from the beginning. The value is a positive integer.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that specifies the start position of the returned result.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Rose").offsetAs(3) + ``` + + +### groupBy + +groupBy\(fields: Array\): RdbPredicates + +Sets the **RdbPredicates** to group rows that have the same value into summary rows. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

fields

+

Array<string>

+

Yes

+

Names of columns to group.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that groups rows with the same value.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.groupBy(["AGE", "NAME"]) + ``` + + +### indexedBy + +indexedBy\(indexName: string\): RdbPredicates + +Sets the **RdbPredicates** object to specify the index column. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

indexName

+

string

+

Yes

+

Name of the index column.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that specifies the index column.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.indexedBy("SALARY_INDEX") + ``` + + +### in + +in\(field: string, value: Array\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **Array** and value within the specified range. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

Array<ValueType>

+

Yes

+

Array of ValueType to match.

+
+ + +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.in("AGE", [18, 20]) + ``` + + +### notIn + +notIn\(field: string, value: Array\): RdbPredicates + +Sets the **RdbPredicates** to match the field with data type **Array** and value out of the specified range. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

field

+

string

+

Yes

+

Column name in the database table.

+

value

+

Array<ValueType>

+

Yes

+

Array of ValueType to match.

+
+ + +- Return values + + + + + + + + + + +

Type

+

Description

+

RdbPredicates

+

RdbPredicates object that matches the specified field.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.notIn("NAME", ["Lisa", "Rose"]) + ``` + + +## RdbStore + +Provides methods to manage an RDB store. + +### insert + +insert\(name: string, values: ValuesBucket, callback: AsyncCallback\):void + +Inserts a row of data into a table. This method uses a callback to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Name of the target table.

+

values

+

ValuesBucket

+

Yes

+

Row of data to insert.

+

callback

+

AsyncCallback<number>

+

Yes

+

Callback invoked to return the result. If the operation is successful, the row ID will be returned. If the operation fails, -1 will be returned.

+
+ +- Example + + ``` + const valueBucket = { + "NAME": "Lisa", + "AGE": 18, + "SALARY": 100.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), + } + rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) { + expect(1).assertEqual(ret) + console.log(TAG + "insert first done: " + ret)}) + ``` + + +### insert + +insert\(name: string, values: ValuesBucket\):Promise + +Inserts a row of data into a table. This method uses a promise to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Name of the target table.

+

values

+

ValuesBucket

+

Yes

+

Row of data to insert.

+
+ + +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<number>

+

Promise used to return the result. If the operation is successful, the row ID will be returned. If the operation fails, -1 will be returned.

+
+ +- Example + + ``` + const valueBucket = { + "NAME": "Lisa", + "AGE": 18, + "SALARY": 100.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), + } + let promise = rdbStore.insert("EMPLOYEE", valueBucket) + promise.then(async (ret) => { + await console.log(TAG + "insert first done: " + ret) + }).catch((err) => {}) + ``` + + +### update + +update\(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback\):void + +Updates data in the database based on the specified **RdbPredicates** object. This method uses a callback to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

values

+

ValuesBucket

+

Yes

+

Data to update. The value specifies the row of data to be updated in the database. The key-value pair is associated with the column name in the target table.

+

rdbPredicates

+

RdbPredicates

+

Yes

+

Row of data to insert.

+

callback

+

AsyncCallback<number>

+

Yes

+

Callback used to return the number of rows updated.

+
+ +- Example + + ``` + const valueBucket = { + "NAME": "Rose", + "AGE": 22, + "SALARY": 200.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), + } + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Lisa") + rdbStore.update(valueBucket, predicates, function (err, ret) { + console.log(TAG + "updated row count: " + changedRows)}) + ``` + + +### update + +update\(values: ValuesBucket, rdbPredicates: RdbPredicates\):Promise + +Updates data in the database based on the specified **RdbPredicates** object. This method uses a promise to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

values

+

ValuesBucket

+

Yes

+

Data to update. The value specifies the row of data to be updated in the database. The key-value pair is associated with the column name in the target table.

+

rdbPredicates

+

RdbPredicates

+

Yes

+

Row of data to insert.

+
+ + +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<number>

+

Promise used to return the number of rows updated.

+
+ +- Example + + ``` + const valueBucket = { + "NAME": "Rose", + "AGE": 22, + "SALARY": 200.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), + } + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Lisa") + let promise = rdbStore.update(valueBucket, predicates) + promise.then(async (ret) => { + await console.log(TAG + "updated row count: " + changedRows) + }).catch((err) => {}) + ``` + + +### delete + +delete\(rdbPredicates: RdbPredicates, callback: AsyncCallback\):void + +Deletes data from the database based on the specified **RdbPredicates** object. This method uses a callback to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

rdbPredicates

+

RdbPredicates

+

Yes

+

Conditions specified for deleting data.

+

callback

+

AsyncCallback<number>

+

Yes

+

Callback invoked to return the number of rows deleted.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Lisa") + rdbStore.delete(predicates, function (err, rows) { + console.log(TAG + "delete rows: " + rows)}) + ``` + + +### delete + +delete\(rdbPredicates: RdbPredicates\):Promise + +Deletes data from the database based on the specified **RdbPredicates** object. This method uses a promise to return the result. + +- Parameters + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

rdbPredicates

+

RdbPredicates

+

Yes

+

Conditions specified for deleting data.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<number>

+

Promise used to return the number of rows deleted.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Lisa") + let promise = rdbStore.delete(predicates) + promise.then((rows) => { + console.log(TAG + "delete rows: " + rows) + }).catch((err) => {}) + ``` + + +### query + +query\(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback\):void + +Queries data in the database based on specified conditions. This method uses a callback to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

rdbPredicates

+

RdbPredicates

+

Yes

+

Query conditions specified by the RdbPredicates object.

+

columns

+

Array<string>

+

Yes

+

Columns to query. If this parameter is not specified, the query applies to all columns.

+

callback

+

AsyncCallback<../nottoctopics/en-us_topic_0000001185510506.md#section12882825611>

+

Yes

+

Callback invoked to return the result. If the operation is successful, a ResultSet object will be returned.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Rose") + rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { + console.log(TAG + "resultSet column names:" + resultSet.columnNames) + console.log(TAG + "resultSet column count:" + resultSet.columnCount)}) + ``` + + +### query + +query\(rdbPredicates: RdbPredicates, columns: Array\):Promise + +Queries data in the database based on specified conditions. This method uses a promise to return the result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

rdbPredicates

+

RdbPredicates

+

Yes

+

Query conditions specified by the RdbPredicates object.

+

columns

+

Array<string>

+

Yes

+

Columns to query. If this parameter is not specified, the query applies to all columns.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<ResultSet>

+

Promise used to return the result. If the operation is successful, a ResultSet object will be returned.

+
+ +- Example + + ``` + let predicates = new dataRdb.RdbPredicates("EMPLOYEE") + predicates.equalTo("NAME", "Rose") + let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) + promise.then((resultSet) => { + console.log(TAG + "resultSet column names:" + resultSet.columnNames) + console.log(TAG + "resultSet column count:" + resultSet.columnCount)}) + ``` + + +### executeSql + +executeSql\(sql: string, bindArgs: Array, callback: AsyncCallback\):void + +Runs the SQL statement that contains the specified parameters but does not return a value. This method uses a callback to return the execution result. + +- Parameters + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

sql

+

string

+

Yes

+

SQL statement to run.

+

bindArgs

+

Array<ValueType>

+

Yes

+

Values of the parameters in the SQL statement.

+

callback

+

AsyncCallback<void>

+

Yes

+

Callback invoked to return the result.

+
+ + +- Example + + ``` + rdbStore.executeSql("DELETE FROM EMPLOYEE", function () { + console.info(TAG + 'delete done.')}) + ``` + + +### executeSql + +executeSql\(sql: string, bindArgs: Array\):Promise + +Runs the SQL statement that contains the specified parameters but does not return a value. This method uses a promise to return the execution result. + +- Parameters + + + + + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

sql

+

string

+

Yes

+

SQL statement to run.

+

bindArgs

+

Array<ValueType>

+

Yes

+

Values of the parameters in the SQL statement.

+
+ +- Return values + + + + + + + + + + +

Type

+

Description

+

Promise<void>

+

Promise used to return the result.

+
+ +- Example + + ``` + let promise = rdbStore.executeSql("DELETE FROM EMPLOYEE") + promise.then(() => { + console.info(TAG + 'delete done.')}) + ``` + +## StoreConfig + +Manages the configuration of an RDB store. + + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

name

+

string

+

Yes

+

Database file name.

+
+ +## ValueType + +Defines the data types allowed. + + + + + + + + + + + + + + + + +

Name

+

Description

+

number

+

Number.

+

string

+

String.

+

boolean

+

Boolean.

+
+ +## ValuesBucket + +Defines a bucket to store key-value pairs. + + + + + + + + + + + + + + +

Name

+

Type

+

Mandatory

+

Description

+

[key: string]

+

ValueType| Uint8Array | null

+

Yes

+

Key-value pairs stored.

+
+