diff --git a/en/application-dev/database/database-relational-guidelines.md b/en/application-dev/database/database-relational-guidelines.md
index df633d8449281b12557bb3d39f333f97148af1a4..da675bed88bcb465310432e9844ab90b6313dc6f 100644
--- a/en/application-dev/database/database-relational-guidelines.md
+++ b/en/application-dev/database/database-relational-guidelines.md
@@ -2,7 +2,7 @@
## When to Use
-A relational database (RDB) store allows you to operate local data with or without native SQL statements based on SQLite.
+A relational database (RDB) store allows you to manage local data with or without native SQL statements based on SQLite.
## Available APIs
@@ -17,12 +17,12 @@ The following table describes the APIs for creating and deleting an RDB store.
| API | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
-| getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> | Obtains an **RdbStore** object. This API uses a promise to return the result. You can set parameters for the **RdbStore** object based on service requirements and use **RdbStore** APIs to perform data operations.
- **context**: application context.
- **config**: configuration of the RDB store.|
+| getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> | Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
- **context**: application context.
- **config**: configuration of the RDB store.|
| deleteRdbStore(context: Context, name: string): Promise<void> | Deletes an RDB store. This API uses a promise to return the result.
- **context**: application context.
- **name**: name of the RDB store to delete.|
### Managing Data in an RDB Store
-The RDB provides APIs for inserting, deleting, updating, and querying data in the local RDB store.
+The RDB provides APIs for inserting, deleting, updating, and querying data in a local RDB store.
- **Inserting Data**
@@ -37,14 +37,14 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
- **Updating Data**
- Call **update()** to update data based on the passed data and the conditions specified by **RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned.
+ Call **update()** to pass in new data and specify the update conditions by using **RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned.
**Table 3** API for updating data
| Class | API | Description |
| ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
- | RdbStore | update(values: ValuesBucket, predicates: RdbPredicates): Promise<number> | Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the number of rows updated.
- **values**: data to update, which is stored in **ValuesBucket**.
- **predicates**: conditions for updating data. |
+ | RdbStore | update(values: ValuesBucket, predicates: RdbPredicates): Promise<number> | Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the number of rows updated.
- **values**: data to update, which is stored in **ValuesBucket**.
- **predicates**: conditions for updating data.|
- **Deleting Data**
@@ -55,7 +55,7 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| Class | API | Description |
| ---------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
- | RdbStore | delete(predicates: RdbPredicates): Promise<number> | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the number of rows deleted.
- **predicates**: conditions for deleting data. |
+ | RdbStore | delete(predicates: RdbPredicates): Promise<number> | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the number of rows deleted.
- **predicates**: conditions for deleting data.|
- **Querying Data**
@@ -180,7 +180,7 @@ You can obtain the distributed table name for a remote device based on the local
### Transaction
-Table 15 Transaction APIs
+**Table 15** Transaction APIs
| Class | API | Description |
| -------- | ----------------------- | --------------------------------- |
@@ -201,40 +201,51 @@ Table 15 Transaction APIs
FA model:
```js
- import data_rdb from '@ohos.data.relationalStore'
- // Obtain the context.
+ import relationalStore from '@ohos.data.relationalStore'
import featureAbility from '@ohos.ability.featureAbility'
- let context = featureAbility.getContext()
- const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
+ var store;
- const STORE_CONFIG = { name: "RdbTest.db",
- securityLevel: data_rdb.SecurityLevel.S1}
- data_rdb.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
- rdbStore.executeSql(CREATE_TABLE_TEST)
- console.info('create table done.')
+ // Obtain the context.
+ let context = featureAbility.getContext();
+
+ const STORE_CONFIG = {
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+ };
+
+ relationalStore.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
+ store = rdbStore;
+ if (err) {
+ console.error(`Get RdbStore failed, err: ${err}`);
+ return;
+ }
+ console.info(`Get RdbStore successfully.`);
})
```
Stage model:
```ts
- import data_rdb from '@ohos.data.relationalStore'
- // Obtain the context.
- import UIAbility from '@ohos.app.ability.UIAbility';
- let context = null
+ import relationalStore from '@ohos.data.relationalStore'
+ import UIAbility from '@ohos.app.ability.UIAbility'
+
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
- context = this.context
+ var store;
+ const STORE_CONFIG = {
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+ };
+
+ relationalStore.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) {
+ store = rdbStore;
+ if (err) {
+ console.error(`Get RdbStore failed, err: ${err}`);
+ return;
+ }
+ console.info(`Get RdbStore successfully.`);
+ })
}
}
-
- const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
-
- const STORE_CONFIG = { name: "rdbstore.db",
- securityLevel: data_rdb.SecurityLevel.S1}
- data_rdb.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
- rdbStore.executeSql(CREATE_TABLE_TEST)
- console.info('create table done.')
- })
```
2. Insert data.
@@ -246,23 +257,24 @@ Table 15 Transaction APIs
The sample code is as follows:
```js
- let u8 = new Uint8Array([1, 2, 3])
- const valueBucket = { "name": "Tom", "age": 18, "salary": 100.5, "blobType": u8 }
- let insertPromise = rdbStore.insert("test", valueBucket)
+ let u8 = new Uint8Array([1, 2, 3]);
+ const valueBucket = { "name": "Tom", "age": 18, "salary": 100.5, "blobType": u8 };
+ let insertPromise = store.insert("test", valueBucket);
```
```js
// Use a transaction to insert data.
- beginTransaction()
try {
- let u8 = new Uint8Array([1, 2, 3])
- const valueBucket1 = { "name": "Tom", "age": 18, "salary": 100.5, "blobType": u8 }
- const valueBucket2 = { "name": "Jam", "age": 19, "salary": 200.5, "blobType": u8 }
- let insertPromise1 = rdbStore.insert("test", valueBucket1)
- let insertPromise2 = rdbStore.insert("test", valueBucket2)
- commit()
- } catch (e) {
- rollBack()
+ store.beginTransaction();
+ let u8 = new Uint8Array([1, 2, 3]);
+ const valueBucket = { "name": "Tom", "age": 18, "salary": 100.5, "blobType": u8 };
+ let promise = store.insert("test", valueBucket);
+ promise.then(() => {
+ store.commit();
+ })
+ } catch (err) {
+ console.error(`Transaction failed, err: ${err}`);
+ store.rollBack();
}
```
@@ -277,17 +289,17 @@ Table 15 Transaction APIs
The sample code is as follows:
```js
- let predicates = new data_rdb.RdbPredicates("test");
- predicates.equalTo("name", "Tom")
- let promisequery = rdbStore.query(predicates)
+ let predicates = new relationalStore.RdbPredicates("test");
+ predicates.equalTo("name", "Tom");
+ let promisequery = store.query(predicates);
promisequery.then((resultSet) => {
- resultSet.goToFirstRow()
- const id = resultSet.getLong(resultSet.getColumnIndex("id"))
- const name = resultSet.getString(resultSet.getColumnIndex("name"))
- const age = resultSet.getLong(resultSet.getColumnIndex("age"))
- const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
- const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
- resultSet.close()
+ resultSet.goToFirstRow();
+ const id = resultSet.getLong(resultSet.getColumnIndex("id"));
+ const name = resultSet.getString(resultSet.getColumnIndex("name"));
+ const age = resultSet.getLong(resultSet.getColumnIndex("age"));
+ const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"));
+ const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"));
+ resultSet.close();
})
```
@@ -297,9 +309,9 @@ Table 15 Transaction APIs
```json
"requestPermissions":
- {
- "name": "ohos.permission.DISTRIBUTED_DATASYNC"
- }
+ {
+ "name": "ohos.permission.DISTRIBUTED_DATASYNC"
+ }
```
(2) Obtain the required permissions.
@@ -313,13 +325,13 @@ Table 15 Transaction APIs
```js
let context = featureAbility.getContext();
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
- console.info(`result.requestCode=${result.requestCode}`)
+ console.info(`result.requestCode=${result.requestCode}`);
})
- let promise = rdbStore.setDistributedTables(["test"])
+ let promise = store.setDistributedTables(["test"]);
promise.then(() => {
- console.info("setDistributedTables success.")
+ console.info(`setDistributedTables success.`);
}).catch((err) => {
- console.info("setDistributedTables failed.")
+ console.error(`setDistributedTables failed, ${err}`);
})
```
@@ -334,16 +346,16 @@ Table 15 Transaction APIs
The sample code is as follows:
```js
- let predicate = new data_rdb.RdbPredicates('test')
- predicate.inDevices(['12345678abcde'])
- let promise = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicate)
+ let predicate = new relationalStore.RdbPredicates('test');
+ predicate.inDevices(['12345678abcde']);
+ let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicate);
promise.then((result) => {
- console.log('sync done.')
- for (let i = 0; i < result.length; i++) {
- console.log('device=' + result[i][0] + 'status=' + result[i][1])
- }
+ console.info(`sync done.`);
+ for (let i = 0; i < result.length; i++) {
+ console.info(`device=${result[i][0]}, status=${result[i][1]}`);
+ }
}).catch((err) => {
- console.log('sync failed')
+ console.error(`sync failed, err: ${err}`);
})
```
@@ -357,15 +369,15 @@ Table 15 Transaction APIs
```js
function storeObserver(devices) {
- for (let i = 0; i < devices.length; i++) {
- console.log('device=' + device[i] + 'data changed')
- }
+ for (let i = 0; i < devices.length; i++) {
+ console.info(`device= ${devices[i]} data changed`);
+ }
}
try {
- rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
+ store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
} catch (err) {
- console.log('register observer failed')
+ console.error(`register observer failed, err: ${err}`);
}
```
@@ -378,59 +390,75 @@ Table 15 Transaction APIs
The sample code is as follows:
```js
- let tableName = rdbStore.obtainDistributedTableName(deviceId, "test");
- let resultSet = rdbStore.querySql("SELECT * FROM " + tableName)
+ import deviceManager from '@ohos.distributedHardware.deviceManager'
+
+ let deviceIds = [];
+ deviceManager.createDeviceManager('bundleName', (err, value) => {
+ if (!err) {
+ let devManager = value;
+ if (devManager != null) {
+ // Obtain device IDs.
+ let devices = devManager.getTrustedDeviceListSync();
+ for (let i = 0; i < devices.length; i++) {
+ deviceIds[i] = devices[i].deviceId;
+ }
+ }
+ }
+ })
+
+ let tableName = store.obtainDistributedTableName(deviceIds[0], "test");
+ let resultSet = store.querySql("SELECT * FROM " + tableName);
```
8. Query data of a remote device.
-
(1) Construct a predicate object for querying distributed tables, and specify the remote distributed table name and the remote device.
(2) Call the resultSet() API to obtain the result.
The sample code is as follows:
-
- ```js
- let rdbPredicate = new data_rdb.RdbPredicates('employee')
- predicates.greaterThan("id", 0)
- let promiseQuery = rdbStore.remoteQuery('12345678abcde', 'employee', rdbPredicate)
+
+ ```js
+ let rdbPredicate = new relationalStore.RdbPredicates('employee');
+ predicates.greaterThan("id", 0) ;
+ let promiseQuery = store.remoteQuery('12345678abcde', 'employee', rdbPredicate);
promiseQuery.then((resultSet) => {
- while (resultSet.goToNextRow()) {
- let idx = resultSet.getLong(0);
- let name = resultSet.getString(1);
- let age = resultSet.getLong(2);
- console.info(idx + " " + name + " " + age);
- }
- resultSet.close();
+ while (resultSet.goToNextRow()) {
+ let idx = resultSet.getLong(0);
+ let name = resultSet.getString(1);
+ let age = resultSet.getLong(2);
+ console.info(`indx: ${idx}, name: ${name}, age: ${age}`);
+ }
+ resultSet.close();
}).catch((err) => {
- console.info("failed to remoteQuery, err: " + err)
+ console.error(`failed to remoteQuery, err: ${err}`);
})
- ```
-
+ ```
+
9. Back up and restore an RDB store.
(1) Back up the current RDB store.
- The sample code is as follows:
+ The sample code is as follows:
- ```js
- let promiseBackup = rdbStore.backup("dbBackup.db")
+ ```js
+ let promiseBackup = store.backup("dbBackup.db");
promiseBackup.then(() => {
- console.info('Backup success.')
+ console.info(`Backup success.`);
}).catch((err) => {
- console.info('Backup failed, err: ' + err)
+ console.error(`Backup failed, err: ${err}`);
})
- ```
- (2) Restore the RDB store using the backup file.
+ ```
- The sample code is as follows:
+ (2) Restore the RDB store using the backup file.
- ```js
- let promiseRestore = rdbStore.restore("dbBackup.db")
+ The sample code is as follows:
+
+ ```js
+ let promiseRestore = store.restore("dbBackup.db");
promiseRestore.then(() => {
- console.info('Restore success.')
+ console.info(`Restore success.`);
}).catch((err) => {
- console.info('Restore failed, err: ' + err)
+ console.error(`Restore failed, err: ${err}`);
})
- ```
+ ```
diff --git a/en/application-dev/reference/apis/js-apis-data-relationalStore.md b/en/application-dev/reference/apis/js-apis-data-relationalStore.md
index e832a479eb802d914d1ff0e818e09a61f2c5b58a..d2afe1626ac0b84e695ce9f3b3d12010c0ff6060 100644
--- a/en/application-dev/reference/apis/js-apis-data-relationalStore.md
+++ b/en/application-dev/reference/apis/js-apis-data-relationalStore.md
@@ -15,10 +15,10 @@ The **relationalStore** module provides the following functions:
## Modules to Import
```js
-import data_rdb from '@ohos.data.relationalStore';
+import relationalStore from '@ohos.data.relationalStore'
```
-## data_rdb.getRdbStore
+## relationalStore.getRdbStore
getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void
@@ -48,51 +48,55 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
FA model:
```js
-// Obtain the context.
+
import featureAbility from '@ohos.ability.featureAbility'
-let context = featureAbility.getContext()
-// Call getRdbStore.
+var store;
+
+// Obtain the context.
+let context = featureAbility.getContext();
+
const STORE_CONFIG = {
- name: "RdbTest.db",
- securityLevel: data_rdb.SecurityLevel.S1
-}
-data_rdb.getRdbStore(context, STORE_CONFIG, function (err, RdbStore) {
- if (err) {
- console.info("Failed to get RdbStore, err: " + err)
- return
- }
- console.log("Got RdbStore successfully.")
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+};
+
+relationalStore.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
+ store = rdbStore;
+ if (err) {
+ console.error(`Get RdbStore failed, err: ${err}`);
+ return;
+ }
+ console.info(`Get RdbStore successfully.`);
})
```
Stage model:
```ts
-// Obtain the context.
-import Ability from '@ohos.application.Ability'
-let context
-class MainAbility extends Ability{
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-
-// Call getRdbStore.
-const STORE_CONFIG = {
- name: "RdbTest.db",
- securityLevel: data_rdb.SecurityLevel.S1
+import UIAbility from '@ohos.app.ability.UIAbility'
+
+class EntryAbility extends UIAbility {
+ onWindowStageCreate(windowStage) {
+ var store;
+ const STORE_CONFIG = {
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+ };
+
+ relationalStore.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) {
+ store = rdbStore;
+ if (err) {
+ console.error(`Get RdbStore failed, err: ${err}`);
+ return;
+ }
+ console.info(`Get RdbStore successfully.`);
+ })
+ }
}
-data_rdb.getRdbStore(context, STORE_CONFIG, function (err, RdbStore) {
- if (err) {
- console.info("Failed to get RdbStore, err: " + err)
- return
- }
- console.log("Got RdbStore successfully.")
-})
```
-## data_rdb.getRdbStore
+## relationalStore.getRdbStore
getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore>
@@ -127,49 +131,52 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
FA model:
```js
-// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
-let context = featureAbility.getContext()
-// Call getRdbStore.
+var store;
+
+// Obtain the context.
+let context = featureAbility.getContext();
+
const STORE_CONFIG = {
- name: "RdbTest.db",
- securityLevel: data_rdb.SecurityLevel.S1
-}
-let promise = data_rdb.getRdbStore(context, STORE_CONFIG);
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+};
+
+let promise = relationalStore.getRdbStore(context, STORE_CONFIG);
promise.then(async (rdbStore) => {
- console.log("Got RdbStore successfully.")
+ store = rdbStore;
+ console.info(`Get RdbStore successfully.`);
}).catch((err) => {
- console.log("Failed to get RdbStore, err: " + err)
+ console.error(`Get RdbStore failed, err: ${err}`);
})
```
Stage model:
```ts
-// Obtain the context.
-import Ability from '@ohos.application.Ability'
-let context
-class MainAbility extends Ability{
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-
-// Call getRdbStore.
-const STORE_CONFIG = {
- name: "RdbTest.db",
- securityLevel: data_rdb.SecurityLevel.S1
+import UIAbility from '@ohos.app.ability.UIAbility'
+
+class EntryAbility extends UIAbility {
+ onWindowStageCreate(windowStage) {
+ var store;
+ const STORE_CONFIG = {
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+ };
+
+ let promise = relationalStore.getRdbStore(this.context, STORE_CONFIG);
+ promise.then(async (rdbStore) => {
+ store = rdbStore;
+ console.info(`Get RdbStore successfully.`)
+ }).catch((err) => {
+ console.error(`Get RdbStore failed, err: ${err}`);
+ })
+ }
}
-let promise = data_rdb.getRdbStore(context, STORE_CONFIG);
-promise.then(async (rdbStore) => {
- console.log("Got RdbStore successfully.")
-}).catch((err) => {
- console.log("Failed to get RdbStore, err: " + err)
-})
```
-## data_rdb.deleteRdbStore
+## relationalStore.deleteRdbStore
deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void
@@ -198,43 +205,39 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
FA model:
```js
-// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
+
+// Obtain the context.
let context = featureAbility.getContext()
-// Call deleteRdbStore.
-data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
- if (err) {
- console.info("Failed to delete RdbStore, err: " + err)
- return
- }
- console.log("Deleted RdbStore successfully.")
+relationalStore.deleteRdbStore(context, "RdbTest.db", function (err) {
+ if (err) {
+ console.error(`Delete RdbStore failed, err: ${err}`);
+ return;
+ }
+ console.info(`Delete RdbStore successfully.`);
})
```
Stage model:
```ts
-// Obtain the context.
-import Ability from '@ohos.application.Ability'
-let context
-class MainAbility extends Ability{
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
+import UIAbility from '@ohos.app.ability.UIAbility'
-// Call deleteRdbStore.
-data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
- if (err) {
- console.info("Failed to delete RdbStore, err: " + err)
- return
- }
- console.log("Deleted RdbStore successfully.")
-})
+class EntryAbility extends UIAbility {
+ onWindowStageCreate(windowStage){
+ relationalStore.deleteRdbStore(this.context, "RdbTest.db", function (err) {
+ if (err) {
+ console.error(`Delete RdbStore failed, err: ${err}`);
+ return;
+ }
+ console.info(`Delete RdbStore successfully.`);
+ })
+ }
+}
```
-## data_rdb.deleteRdbStore
+## relationalStore.deleteRdbStore
deleteRdbStore(context: Context, name: string): Promise<void>
@@ -268,38 +271,34 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
FA model:
```js
-// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
-let context = featureAbility.getContext()
-// Call deleteRdbStore.
-let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
+// Obtain the context.
+let context = featureAbility.getContext();
+
+let promise = relationalStore.deleteRdbStore(context, "RdbTest.db");
promise.then(()=>{
- console.log("Deleted RdbStore successfully.")
+ console.info(`Delete RdbStore successfully.`);
}).catch((err) => {
- console.info("Failed to delete RdbStore, err: " + err)
+ console.error(`Delete RdbStore failed, err: ${err}`);
})
```
Stage model:
```ts
-// Obtain the context.
-import Ability from '@ohos.application.Ability'
-let context
-class MainAbility extends Ability{
- onWindowStageCreate(windowStage){
- context = this.context
- }
+import UIAbility from '@ohos.app.ability.UIAbility'
+
+class EntryAbility extends UIAbility {
+ onWindowStageCreate(windowStage){
+ let promise = relationalStore.deleteRdbStore(this.context, "RdbTest.db");
+ promise.then(()=>{
+ console.info(`Delete RdbStore successfully.`);
+ }).catch((err) => {
+ console.error(`Delete RdbStore failed, err: ${err}`);
+ })
+ }
}
-
-// Call deleteRdbStore.
-let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
-promise.then(()=>{
- console.log("Deleted RdbStore successfully.")
-}).catch((err) => {
- console.info("Failed to delete RdbStore, err: " + err)
-})
```
## StoreConfig
@@ -391,7 +390,7 @@ A constructor used to create an **RdbPredicates** object.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
```
### inDevices
@@ -418,8 +417,8 @@ Sets an **RdbPredicates** to specify the remote devices to connect on the networ
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.inDevices(['12345678abcde'])
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.inDevices(['12345678abcde']);
```
### inAllDevices
@@ -440,8 +439,8 @@ Sets an **RdbPredicates** to specify all remote devices on the network to connec
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.inAllDevices()
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.inAllDevices();
```
### equalTo
@@ -469,8 +468,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "lisi")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "lisi");
```
@@ -499,8 +498,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.notEqualTo("NAME", "lisi")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.notEqualTo("NAME", "lisi");
```
@@ -522,7 +521,7 @@ Adds a left parenthesis to the **RdbPredicates**.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "lisi")
.beginWrap()
.equalTo("AGE", 18)
@@ -548,7 +547,7 @@ Adds a right parenthesis to the **RdbPredicates**.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "lisi")
.beginWrap()
.equalTo("AGE", 18)
@@ -574,7 +573,7 @@ Adds the OR condition to the **RdbPredicates**.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa")
.or()
.equalTo("NAME", "Rose")
@@ -597,7 +596,7 @@ Adds the AND condition to the **RdbPredicates**.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa")
.and()
.equalTo("SALARY", 200.5)
@@ -627,8 +626,8 @@ Sets an **RdbPredicates** to match a string containing the specified value.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.contains("NAME", "os")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.contains("NAME", "os");
```
### beginsWith
@@ -655,8 +654,8 @@ Sets an **RdbPredicates** to match a string that starts with the specified value
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.beginsWith("NAME", "os")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.beginsWith("NAME", "os");
```
### endsWith
@@ -683,8 +682,8 @@ Sets an **RdbPredicates** to match a string that ends with the specified value.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.endsWith("NAME", "se")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.endsWith("NAME", "se");
```
### isNull
@@ -710,8 +709,8 @@ Sets an **RdbPredicates** to match the field whose value is null.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.isNull("NAME")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.isNull("NAME");
```
### isNotNull
@@ -737,8 +736,8 @@ Sets an **RdbPredicates** to match the field whose value is not null.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.isNotNull("NAME")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.isNotNull("NAME");
```
### like
@@ -765,8 +764,8 @@ Sets an **RdbPredicates** to match a string that is similar to the specified val
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.like("NAME", "%os%")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.like("NAME", "%os%");
```
### glob
@@ -793,8 +792,8 @@ Sets an **RdbPredicates** to match the specified string.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.glob("NAME", "?h*g")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.glob("NAME", "?h*g");
```
### between
@@ -822,8 +821,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.between("AGE", 10, 50)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.between("AGE", 10, 50);
```
### notBetween
@@ -851,8 +850,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.notBetween("AGE", 10, 50)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.notBetween("AGE", 10, 50);
```
### greaterThan
@@ -879,8 +878,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.greaterThan("AGE", 18)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.greaterThan("AGE", 18);
```
### lessThan
@@ -907,8 +906,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.lessThan("AGE", 20)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.lessThan("AGE", 20);
```
### greaterThanOrEqualTo
@@ -935,8 +934,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.greaterThanOrEqualTo("AGE", 18)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.greaterThanOrEqualTo("AGE", 18);
```
### lessThanOrEqualTo
@@ -963,8 +962,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.lessThanOrEqualTo("AGE", 20)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.lessThanOrEqualTo("AGE", 20);
```
### orderByAsc
@@ -990,8 +989,8 @@ Sets an **RdbPredicates** to match the column with values sorted in ascending or
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.orderByAsc("NAME")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.orderByAsc("NAME");
```
### orderByDesc
@@ -1017,8 +1016,8 @@ Sets an **RdbPredicates** to match the column with values sorted in descending o
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.orderByDesc("AGE")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.orderByDesc("AGE");
```
### distinct
@@ -1038,8 +1037,8 @@ Sets an **RdbPredicates** to filter out duplicate records.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Rose").distinct()
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Rose").distinct();
```
### limitAs
@@ -1065,8 +1064,8 @@ Sets an **RdbPredicates** to specify the maximum number of records.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Rose").limitAs(3)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Rose").limitAs(3);
```
### offsetAs
@@ -1092,8 +1091,8 @@ Sets an **RdbPredicates** to specify the start position of the returned result.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Rose").offsetAs(3)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Rose").offsetAs(3);
```
### groupBy
@@ -1119,8 +1118,8 @@ Sets an **RdbPredicates** to group rows that have the same value into summary ro
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.groupBy(["AGE", "NAME"])
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.groupBy(["AGE", "NAME"]);
```
### indexedBy
@@ -1147,8 +1146,8 @@ Sets an **RdbPredicates** object to specify the index column.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.indexedBy("SALARY_INDEX")
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.indexedBy("SALARY_INDEX");
```
### in
@@ -1175,8 +1174,8 @@ Sets an **RdbPredicates** to match the field with data type **Array<ValueTyp
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.in("AGE", [18, 20])
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.in("AGE", [18, 20]);
```
### notIn
@@ -1203,8 +1202,8 @@ Sets an **RdbPredicates** to match the field with data type **Array<ValueTyp
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.notIn("NAME", ["Lisa", "Rose"])
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.notIn("NAME", ["Lisa", "Rose"]);
```
## RdbStore
@@ -1233,19 +1232,21 @@ Inserts a row of data into a table. This API uses an asynchronous callback to re
```js
const valueBucket = {
- "NAME": "Lisa",
- "AGE": 18,
- "SALARY": 100.5,
- "CODES": new Uint8Array([1, 2, 3, 4, 5]),
-}
-rdbStore.insert("EMPLOYEE", valueBucket, function (status, rowId) {
- if (status) {
- console.log("Failed to insert data");
- return;
- }
- console.log("Inserted data successfully, rowId = " + rowId);
+ "NAME": "Lisa",
+ "AGE": 18,
+ "SALARY": 100.5,
+ "CODES": new Uint8Array([1, 2, 3, 4, 5]),
+};
+store.insert("EMPLOYEE", valueBucket, function (err, rowId) {
+ if (err) {
+ console.error(`Insert is failed, err: ${err}`);
+ return;
+ }
+ console.info(`Insert is successful, rowId = ${rowId}`);
})
```
+
+
### insert
insert(table: string, values: ValuesBucket):Promise<number>
@@ -1271,19 +1272,20 @@ Inserts a row of data into a table. This API uses a promise to return the result
```js
const valueBucket = {
- "NAME": "Lisa",
- "AGE": 18,
- "SALARY": 100.5,
- "CODES": new Uint8Array([1, 2, 3, 4, 5]),
-}
-let promise = rdbStore.insert("EMPLOYEE", valueBucket)
+ "NAME": "Lisa",
+ "AGE": 18,
+ "SALARY": 100.5,
+ "CODES": new Uint8Array([1, 2, 3, 4, 5]),
+};
+let promise = store.insert("EMPLOYEE", valueBucket);
promise.then((rowId) => {
- console.log("Inserted data successfully, rowId = " + rowId);
-}).catch((status) => {
- console.log("Failed to insert data");
+ console.info(`Insert is successful, rowId = ${rowId}`);
+}).catch((err) => {
+ console.error(`Insert is failed, err: ${err}`);
})
```
+
### batchInsert
batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>):void
@@ -1304,31 +1306,31 @@ Batch inserts data into a table. This API uses an asynchronous callback to retur
```js
const valueBucket1 = {
- "NAME": "Lisa",
- "AGE": 18,
- "SALARY": 100.5,
- "CODES": new Uint8Array([1, 2, 3, 4, 5])
-}
+ "NAME": "Lisa",
+ "AGE": 18,
+ "SALARY": 100.5,
+ "CODES": new Uint8Array([1, 2, 3, 4, 5])
+};
const valueBucket2 = {
- "NAME": "Jack",
- "AGE": 19,
- "SALARY": 101.5,
- "CODES": new Uint8Array([6, 7, 8, 9, 10])
-}
+ "NAME": "Jack",
+ "AGE": 19,
+ "SALARY": 101.5,
+ "CODES": new Uint8Array([6, 7, 8, 9, 10])
+};
const valueBucket3 = {
- "NAME": "Tom",
- "AGE": 20,
- "SALARY": 102.5,
- "CODES": new Uint8Array([11, 12, 13, 14, 15])
-}
+ "NAME": "Tom",
+ "AGE": 20,
+ "SALARY": 102.5,
+ "CODES": new Uint8Array([11, 12, 13, 14, 15])
+};
let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
-rdbStore.batchInsert("EMPLOYEE", valueBuckets, function(status, insertNum) {
- if (status) {
- console.log("batchInsert is failed, status = " + status);
- return;
- }
- console.log("batchInsert is successful, the number of values that were inserted = " + insertNum);
+store.batchInsert("EMPLOYEE", valueBuckets, function(err, insertNum) {
+ if (err) {
+ console.error(`batchInsert is failed, err: ${err}`);
+ return;
+ }
+ console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
})
```
@@ -1357,30 +1359,30 @@ Batch inserts data into a table. This API uses a promise to return the result.
```js
const valueBucket1 = {
- "NAME": "Lisa",
- "AGE": 18,
- "SALARY": 100.5,
- "CODES": new Uint8Array([1, 2, 3, 4, 5])
-}
+ "NAME": "Lisa",
+ "AGE": 18,
+ "SALARY": 100.5,
+ "CODES": new Uint8Array([1, 2, 3, 4, 5])
+};
const valueBucket2 = {
- "NAME": "Jack",
- "AGE": 19,
- "SALARY": 101.5,
- "CODES": new Uint8Array([6, 7, 8, 9, 10])
-}
+ "NAME": "Jack",
+ "AGE": 19,
+ "SALARY": 101.5,
+ "CODES": new Uint8Array([6, 7, 8, 9, 10])
+};
const valueBucket3 = {
- "NAME": "Tom",
- "AGE": 20,
- "SALARY": 102.5,
- "CODES": new Uint8Array([11, 12, 13, 14, 15])
-}
+ "NAME": "Tom",
+ "AGE": 20,
+ "SALARY": 102.5,
+ "CODES": new Uint8Array([11, 12, 13, 14, 15])
+};
let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
-let promise = rdbStore.batchInsert("EMPLOYEE", valueBuckets);
+let promise = store.batchInsert("EMPLOYEE", valueBuckets);
promise.then((insertNum) => {
- console.log("batchInsert is successful, the number of values that were inserted = " + insertNum);
-}).catch((status) => {
- console.log("batchInsert is failed, status = " + status);
+ console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
+}).catch((err) => {
+ console.error(`batchInsert is failed, err: ${err}`);
})
```
@@ -1404,22 +1406,23 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T
```js
const valueBucket = {
- "NAME": "Rose",
- "AGE": 22,
- "SALARY": 200.5,
- "CODES": new Uint8Array([1, 2, 3, 4, 5]),
-}
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Lisa")
-rdbStore.update(valueBucket, predicates, function (err, rows) {
- if (err) {
- console.info("Failed to update data, err: " + err)
- return
- }
- console.log("Updated row count: " + rows)
+ "NAME": "Rose",
+ "AGE": 22,
+ "SALARY": 200.5,
+ "CODES": new Uint8Array([1, 2, 3, 4, 5]),
+};
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Lisa");
+store.update(valueBucket, predicates, function (err, rows) {
+ if (err) {
+ console.error(`Update failed, err: ${err}`);
+ return;
+ }
+ console.info(`Updated row count: ${rows}`);
})
```
+
### update
update(values: ValuesBucket, predicates: RdbPredicates):Promise<number>
@@ -1445,21 +1448,22 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr
```js
const valueBucket = {
- "NAME": "Rose",
- "AGE": 22,
- "SALARY": 200.5,
- "CODES": new Uint8Array([1, 2, 3, 4, 5]),
-}
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Lisa")
-let promise = rdbStore.update(valueBucket, predicates)
+ "NAME": "Rose",
+ "AGE": 22,
+ "SALARY": 200.5,
+ "CODES": new Uint8Array([1, 2, 3, 4, 5]),
+};
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Lisa");
+let promise = store.update(valueBucket, predicates);
promise.then(async (rows) => {
- console.log("Updated row count: " + rows)
+ console.info(`Updated row count: ${rows}`);
}).catch((err) => {
- console.info("Failed to update data, err: " + err)
+ console.error(`Update failed, err: ${err}`);
})
```
+
### update
update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):void
@@ -1488,15 +1492,15 @@ const valueBucket = {
"AGE": 22,
"SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]),
-}
-let predicates = new dataSharePredicates.DataSharePredicates()
-predicates.equalTo("NAME", "Lisa")
-rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, rows) {
- if (err) {
- console.info("Failed to update data, err: " + err)
- return
- }
- console.log("Updated row count: " + rows)
+};
+let predicates = new dataSharePredicates.DataSharePredicates();
+predicates.equalTo("NAME", "Lisa");
+store.update("EMPLOYEE", valueBucket, predicates, function (err, rows) {
+ if (err) {
+ console.error(`Update failed, err: ${err}`);
+ return;
+ }
+ console.info(`Updated row count: ${rows}`);
})
```
@@ -1529,18 +1533,18 @@ Updates data based on the specified **DataSharePredicates** object. This API use
```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
const valueBucket = {
- "NAME": "Rose",
- "AGE": 22,
- "SALARY": 200.5,
- "CODES": new Uint8Array([1, 2, 3, 4, 5]),
-}
-let predicates = new dataSharePredicates.DataSharePredicates()
-predicates.equalTo("NAME", "Lisa")
-let promise = rdbStore.update("EMPLOYEE", valueBucket, predicates)
+ "NAME": "Rose",
+ "AGE": 22,
+ "SALARY": 200.5,
+ "CODES": new Uint8Array([1, 2, 3, 4, 5]),
+};
+let predicates = new dataSharePredicates.DataSharePredicates();
+predicates.equalTo("NAME", "Lisa");
+let promise = store.update("EMPLOYEE", valueBucket, predicates);
promise.then(async (rows) => {
- console.log("Updated row count: " + rows)
+ console.info(`Updated row count: ${rows}`);
}).catch((err) => {
- console.info("Failed to update data, err: " + err)
+ console.error(`Updated failed, err: ${err}`);
})
```
@@ -1562,14 +1566,14 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Lisa")
-rdbStore.delete(predicates, function (err, rows) {
- if (err) {
- console.info("Failed to delete data, err: " + err)
- return
- }
- console.log("Deleted rows: " + rows)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Lisa");
+store.delete(predicates, function (err, rows) {
+ if (err) {
+ console.error(`Delete failed, err: ${err}`);
+ return;
+ }
+ console.info(`Delete rows: ${rows}`);
})
```
@@ -1596,13 +1600,13 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Lisa")
-let promise = rdbStore.delete(predicates)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Lisa");
+let promise = store.delete(predicates);
promise.then((rows) => {
- console.log("Deleted rows: " + rows)
+ console.info(`Delete rows: ${rows}`);
}).catch((err) => {
- console.info("Failed to delete data, err: " + err)
+ console.error(`Delete failed, err: ${err}`);
})
```
@@ -1628,14 +1632,14 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o
```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
-let predicates = new dataSharePredicates.DataSharePredicates()
-predicates.equalTo("NAME", "Lisa")
-rdbStore.delete("EMPLOYEE", predicates, function (err, rows) {
- if (err) {
- console.info("Failed to delete data, err: " + err)
- return
- }
- console.log("Deleted rows: " + rows)
+let predicates = new dataSharePredicates.DataSharePredicates();
+predicates.equalTo("NAME", "Lisa");
+store.delete("EMPLOYEE", predicates, function (err, rows) {
+ if (err) {
+ console.error(`Delete failed, err: ${err}`);
+ return;
+ }
+ console.info(`Delete rows: ${rows}`);
})
```
@@ -1666,13 +1670,13 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o
```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
-let predicates = new dataSharePredicates.DataSharePredicates()
-predicates.equalTo("NAME", "Lisa")
-let promise = rdbStore.delete("EMPLOYEE", predicates)
+let predicates = new dataSharePredicates.DataSharePredicates();
+predicates.equalTo("NAME", "Lisa");
+let promise = store.delete("EMPLOYEE", predicates);
promise.then((rows) => {
- console.log("Deleted rows: " + rows)
+ console.info(`Delete rows: ${rows}`);
}).catch((err) => {
- console.info("Failed to delete data, err: " + err)
+ console.error(`Delete failed, err: ${err}`);
})
```
@@ -1695,15 +1699,15 @@ Queries data from the RDB store based on specified conditions. This API uses an
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Rose")
-rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
- if (err) {
- console.info("Failed to query data, err: " + err)
- return
- }
- console.log("ResultSet column names: " + resultSet.columnNames)
- console.log("ResultSet column count: " + resultSet.columnCount)
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Rose");
+store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
+ if (err) {
+ console.error(`Query failed, err: ${err}`);
+ return;
+ }
+ console.info(`ResultSet column names: ${resultSet.columnNames}`);
+ console.info(`ResultSet column count: ${resultSet.columnCount}`);
})
```
@@ -1731,14 +1735,14 @@ Queries data from the RDB store based on specified conditions. This API uses a p
**Example**
```js
-let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
-predicates.equalTo("NAME", "Rose")
-let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+predicates.equalTo("NAME", "Rose");
+let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- console.log("ResultSet column names: " + resultSet.columnNames)
- console.log("ResultSet column count: " + resultSet.columnCount)
+ console.info(`ResultSet column names: ${resultSet.columnNames}`);
+ console.info(`ResultSet column count: ${resultSet.columnCount}`);
}).catch((err) => {
- console.info("Failed to query data, err: " + err)
+ console.error(`Query failed, err: ${err}`);
})
```
@@ -1765,15 +1769,15 @@ Queries data from the RDB store based on specified conditions. This API uses an
```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
-let predicates = new dataSharePredicates.DataSharePredicates()
-predicates.equalTo("NAME", "Rose")
-rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
- if (err) {
- console.info("Failed to query data, err: " + err)
- return
- }
- console.log("ResultSet column names: " + resultSet.columnNames)
- console.log("ResultSet column count: " + resultSet.columnCount)
+let predicates = new dataSharePredicates.DataSharePredicates();
+predicates.equalTo("NAME", "Rose");
+store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
+ if (err) {
+ console.error(`Query failed, err: ${err}`);
+ return;
+ }
+ console.info(`ResultSet column names: ${resultSet.columnNames}`);
+ console.info(`ResultSet column count: ${resultSet.columnCount}`);
})
```
@@ -1805,14 +1809,14 @@ Queries data from the RDB store based on specified conditions. This API uses a p
```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
-let predicates = new dataSharePredicates.DataSharePredicates()
-predicates.equalTo("NAME", "Rose")
-let promise = rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
+let predicates = new dataSharePredicates.DataSharePredicates();
+predicates.equalTo("NAME", "Rose");
+let promise = store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- console.log("ResultSet column names: " + resultSet.columnNames)
- console.log("ResultSet column count: " + resultSet.columnCount)
+ console.info(`ResultSet column names: ${resultSet.columnNames}`);
+ console.info(`ResultSet column count: ${resultSet.columnCount}`);
}).catch((err) => {
- console.info("Failed to query data, err: " + err)
+ console.error(`Query failed, err: ${err}`);
})
```
@@ -1837,17 +1841,18 @@ Queries data from the RDB store of a remote device based on specified conditions
**Example**
```js
-let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
-predicates.greaterThan("id", 0)
-rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
- function(err, resultSet){
+let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
+predicates.greaterThan("id", 0);
+store.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
+ function(err, resultSet) {
if (err) {
- console.info("Failed to remoteQuery, err: " + err)
- return
+ console.error(`Failed to remoteQuery, err: ${err}`);
+ return;
}
- console.info("ResultSet column names: " + resultSet.columnNames)
- console.info("ResultSet column count: " + resultSet.columnCount)
-})
+ console.info(`ResultSet column names: ${resultSet.columnNames}`);
+ console.info(`ResultSet column count: ${resultSet.columnCount}`);
+ }
+)
```
### remoteQuery
@@ -1876,14 +1881,14 @@ Queries data from the RDB store of a remote device based on specified conditions
**Example**
```js
-let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
-predicates.greaterThan("id", 0)
-let promise = rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
+let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
+predicates.greaterThan("id", 0);
+let promise = store.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- console.info("ResultSet column names: " + resultSet.columnNames)
- console.info("ResultSet column count: " + resultSet.columnCount)
+ console.info(`ResultSet column names: ${resultSet.columnNames}`);
+ console.info(`ResultSet column count: ${resultSet.columnCount}`);
}).catch((err) => {
- console.info("Failed to remoteQuery , err: " + err)
+ console.error(`Failed to remoteQuery, err: ${err}`);
})
```
@@ -1906,13 +1911,13 @@ Queries data using the specified SQL statement. This API uses an asynchronous ca
**Example**
```js
-rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
- if (err) {
- console.info("Failed to query data, err: " + err)
- return
- }
- console.log("ResultSet column names: " + resultSet.columnNames)
- console.log("ResultSet column count: " + resultSet.columnCount)
+store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
+ if (err) {
+ console.error(`Query failed, err: ${err}`);
+ return;
+ }
+ console.info(`ResultSet column names: ${resultSet.columnNames}`);
+ console.info(`ResultSet column count: ${resultSet.columnCount}`);
})
```
@@ -1940,12 +1945,12 @@ Queries data using the specified SQL statement. This API uses a promise to retur
**Example**
```js
-let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'])
+let promise = store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']);
promise.then((resultSet) => {
- console.log("ResultSet column names: " + resultSet.columnNames)
- console.log("ResultSet column count: " + resultSet.columnCount)
+ console.info(`ResultSet column names: ${resultSet.columnNames}`);
+ console.info(`ResultSet column count: ${resultSet.columnCount}`);
}).catch((err) => {
- console.info("Failed to query data, err: " + err)
+ console.error(`Query failed, err: ${err}`);
})
```
@@ -1969,12 +1974,12 @@ Executes an SQL statement that contains specified arguments but returns no value
```js
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)"
-rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) {
- if (err) {
- console.info("Failed to execute SQL, err: " + err)
- return
- }
- console.info('Create table done.')
+store.executeSql(SQL_CREATE_TABLE, null, function(err) {
+ if (err) {
+ console.error(`ExecuteSql failed, err: ${err}`);
+ return;
+ }
+ console.info(`Create table done.`);
})
```
@@ -2003,11 +2008,11 @@ Executes an SQL statement that contains specified arguments but returns no value
```js
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 = rdbStore.executeSql(SQL_CREATE_TABLE)
+let promise = store.executeSql(SQL_CREATE_TABLE);
promise.then(() => {
- console.info('Create table done.')
+ console.info(`Create table done.`);
}).catch((err) => {
- console.info("Failed to execute SQL, err: " + err)
+ console.error(`ExecuteSql failed, err: ${err}`);
})
```
@@ -2023,19 +2028,25 @@ Starts the transaction before executing an SQL statement.
```js
import featureAbility from '@ohos.ability.featureAbility'
-let context = featureAbility.getContext()
-const STORE_CONFIG = { name: "RdbTest.db",
- securityLevel: data_rdb.SecurityLevel.S1}
-data_rdb.getRdbStore(context, STORE_CONFIG, async function (err, rdbStore) {
- rdbStore.beginTransaction()
- const valueBucket = {
- "name": "lisi",
- "age": 18,
- "salary": 100.5,
- "blobType": new Uint8Array([1, 2, 3]),
- }
- await rdbStore.insert("test", valueBucket)
- rdbStore.commit()
+let context = featureAbility.getContext();
+const STORE_CONFIG = {
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+};
+relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
+ if (err) {
+ console.error(`GetRdbStore failed, err: ${err}`);
+ return;
+ }
+ store.beginTransaction();
+ const valueBucket = {
+ "name": "lisi",
+ "age": 18,
+ "salary": 100.5,
+ "blobType": new Uint8Array([1, 2, 3]),
+ };
+ await store.insert("test", valueBucket);
+ store.commit();
})
```
@@ -2051,19 +2062,25 @@ Commits the executed SQL statements.
```js
import featureAbility from '@ohos.ability.featureAbility'
-let context = featureAbility.getContext()
-const STORE_CONFIG = { name: "RdbTest.db",
- securityLevel: data_rdb.SecurityLevel.S1}
-data_rdb.getRdbStore(context, STORE_CONFIG, async function (err, rdbStore) {
- rdbStore.beginTransaction()
- const valueBucket = {
- "name": "lisi",
- "age": 18,
- "salary": 100.5,
- "blobType": new Uint8Array([1, 2, 3]),
- }
- await rdbStore.insert("test", valueBucket)
- rdbStore.commit()
+let context = featureAbility.getContext();
+const STORE_CONFIG = {
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+};
+relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
+ if (err) {
+ console.error(`GetRdbStore failed, err: ${err}`);
+ return;
+ }
+ store.beginTransaction();
+ const valueBucket = {
+ "name": "lisi",
+ "age": 18,
+ "salary": 100.5,
+ "blobType": new Uint8Array([1, 2, 3]),
+ };
+ await store.insert("test", valueBucket);
+ store.commit();
})
```
@@ -2079,24 +2096,31 @@ Rolls back the SQL statements that have been executed.
```js
import featureAbility from '@ohos.ability.featureAbility'
-let context = featureAbility.getContext()
-const STORE_CONFIG = { name: "RdbTest.db",
- securityLevel: data_rdb.SecurityLevel.S1}
-data_rdb.getRdbStore(context, STORE_CONFIG, async function (err, rdbStore) {
- try {
- rdbStore.beginTransaction()
- const valueBucket = {
- "id": 1,
- "name": "lisi",
- "age": 18,
- "salary": 100.5,
- "blobType": new Uint8Array([1, 2, 3]),
- }
- await rdbStore.insert("test", valueBucket)
- rdbStore.commit()
- } catch (e) {
- rdbStore.rollBack()
- }
+let context = featureAbility.getContext();
+const STORE_CONFIG = {
+ name: "RdbTest.db",
+ securityLevel: relationalStore.SecurityLevel.S1
+};
+relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
+ if (err) {
+ console.error(`GetRdbStore failed, err: ${err}`);
+ return;
+ }
+ try {
+ store.beginTransaction()
+ const valueBucket = {
+ "id": 1,
+ "name": "lisi",
+ "age": 18,
+ "salary": 100.5,
+ "blobType": new Uint8Array([1, 2, 3]),
+ };
+ await store.insert("test", valueBucket);
+ store.commit();
+ } catch (err) {
+ console.error(`Transaction failed, err: ${err}`);
+ store.rollBack();
+ }
})
```
@@ -2118,12 +2142,12 @@ Backs up an RDB store. This API uses an asynchronous callback to return the resu
**Example**
```js
-rdbStore.backup("dbBackup.db", function(err) {
- if (err) {
- console.info('Backup failed, err: ' + err)
- return
- }
- console.info('Backup success.')
+store.backup("dbBackup.db", function(err) {
+ if (err) {
+ console.error(`Backup failed, err: ${err}`);
+ return;
+ }
+ console.info(`Backup success.`);
})
```
@@ -2150,11 +2174,11 @@ Backs up an RDB store. This API uses a promise to return the result.
**Example**
```js
-let promiseBackup = rdbStore.backup("dbBackup.db")
+let promiseBackup = store.backup("dbBackup.db");
promiseBackup.then(()=>{
- console.info('Backup success.')
+ console.info(`Backup success.`);
}).catch((err)=>{
- console.info('Backup failed, err: ' + err)
+ console.error(`Backup failed, err: ${err}`);
})
```
@@ -2176,12 +2200,12 @@ Restores an RDB store from a backup file. This API uses an asynchronous callback
**Example**
```js
-rdbStore.restore("dbBackup.db", function(err) {
- if (err) {
- console.info('Restore failed, err: ' + err)
- return
- }
- console.info('Restore success.')
+store.restore("dbBackup.db", function(err) {
+ if (err) {
+ console.error(`Restore failed, err: ${err}`);
+ return;
+ }
+ console.info(`Restore success.`);
})
```
@@ -2208,11 +2232,11 @@ Restores an RDB store from a backup file. This API uses a promise to return the
**Example**
```js
-let promiseRestore = rdbStore.restore("dbBackup.db")
+let promiseRestore = store.restore("dbBackup.db");
promiseRestore.then(()=>{
- console.info('Restore success.')
+ console.info(`Restore success.`);
}).catch((err)=>{
- console.info('Restore failed, err: ' + err)
+ console.error(`Restore failed, err: ${err}`);
})
```
@@ -2236,12 +2260,12 @@ Sets distributed tables. This API uses an asynchronous callback to return the re
**Example**
```js
-rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
- if (err) {
- console.info('Failed to set distributed tables, err: ' + err)
- return
- }
- console.info('Set distributed tables successfully.')
+store.setDistributedTables(["EMPLOYEE"], function (err) {
+ if (err) {
+ console.error(`SetDistributedTables failed, err: ${err}`);
+ return;
+ }
+ console.info(`SetDistributedTables successfully.`);
})
```
@@ -2270,11 +2294,11 @@ Sets distributed tables. This API uses a promise to return the result.
**Example**
```js
-let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
+let promise = store.setDistributedTables(["EMPLOYEE"]);
promise.then(() => {
- console.info("Set distributed tables successfully.")
+ console.info(`SetDistributedTables successfully.`);
}).catch((err) => {
- console.info("Failed to set distributed tables, err: " + err)
+ console.error(`SetDistributedTables failed, err: ${err}`);
})
```
@@ -2299,12 +2323,12 @@ Obtains the distributed table name for a remote device based on the local table
**Example**
```js
-rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) {
+store.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) {
if (err) {
- console.info('Failed to obtain DistributedTableName, err: ' + err)
- return
+ console.error(`ObtainDistributedTableName failed, err: ${err}`);
+ return;
}
- console.info('Obtained distributed table name successfully, tableName=.' + tableName)
+ console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
})
```
@@ -2334,11 +2358,11 @@ Obtains the distributed table name for a remote device based on the local table
**Example**
```js
-let promise = rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE")
+let promise = store.obtainDistributedTableName("12345678abcde", "EMPLOYEE");
promise.then((tableName) => {
- console.info('Obtained distributed table name successfully, tableName= ' + tableName)
+ console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
}).catch((err) => {
- console.info('Failed to obtain DistributedTableName, err: ' + err)
+ console.error(`ObtainDistributedTableName failed, err: ${err}`);
})
```
@@ -2363,17 +2387,17 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret
**Example**
```js
-let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
-predicates.inDevices(['12345678abcde'])
-rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
- if (err) {
- console.log('Sync failed, err: ' + err)
- return
- }
- console.log('Sync done.')
- for (let i = 0; i < result.length; i++) {
- console.log('device=' + result[i][0] + ' status=' + result[i][1])
- }
+let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
+predicates.inDevices(['12345678abcde']);
+store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
+ if (err) {
+ console.error(`Sync failed, err: ${err}`);
+ return;
+ }
+ console.info(`Sync done.`);
+ for (let i = 0; i < result.length; i++) {
+ console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
+ }
})
```
@@ -2403,16 +2427,16 @@ Synchronizes data between devices. This API uses a promise to return the result.
**Example**
```js
-let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
-predicates.inDevices(['12345678abcde'])
-let promise = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates)
+let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
+predicates.inDevices(['12345678abcde']);
+let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
promise.then((resultSet) =>{
- console.log('Sync done.')
- for (let i = 0; i < resultSet.length; i++) {
- console.log('device=' + resultSet[i][0] + ' status=' + resultSet[i][1])
- }
+ console.info(`Sync done.`);
+ for (let i = 0; i < resultSet.length; i++) {
+ console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
+ }
}).catch((err) => {
- console.log('Sync failed')
+ console.error(`Sync failed, err: ${err}`);
})
```
@@ -2428,22 +2452,22 @@ Registers an observer for this RDB store. When the data in the RDB store changes
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------------------------- |
-| event | string | Yes | The value is'dataChange', which indicates a data change event. |
+| event | string | Yes | Event to observe. The value is **dataChange**, which indicates a data change event. |
| type | [SubscribeType](#subscribetype) | Yes | Subscription type to register.|
-| observer | Callback<Array<string>> | Yes | Observer that listens for the data changes in the RDB store. |
+| observer | Callback<Array<string>> | Yes | Callback invoked to return the data change. |
**Example**
```js
function storeObserver(devices) {
- for (let i = 0; i < devices.length; i++) {
- console.log('device=' + devices[i] + ' data changed')
- }
+ for (let i = 0; i < devices.length; i++) {
+ console.info(`device= ${devices[i]} data changed`);
+ }
}
try {
- rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
+ store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
} catch (err) {
- console.log('Failed to register observer')
+ console.error(`Register observer failed, err: ${err}`);
}
```
@@ -2459,22 +2483,22 @@ Unregisters the observer of the specified type from the RDB store. This API uses
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------------------ |
-| event | string | Yes | The value is'dataChange', which indicates a data change event. |
-| type | [SubscribeType](#subscribetype) | Yes | Subscription type to register. |
-| observer | Callback<Array<string>> | Yes | Data change observer registered. |
+| event | string | Yes | Event to observe. The value is **dataChange**, which indicates a data change event. |
+| type | [SubscribeType](#subscribetype) | Yes | Subscription type to unregister. |
+| observer | Callback<Array<string>> | Yes | Callback for the data change. |
**Example**
```js
function storeObserver(devices) {
- for (let i = 0; i < devices.length; i++) {
- console.log('device=' + devices[i] + ' data changed')
- }
+ for (let i = 0; i < devices.length; i++) {
+ console.info(`device= ${devices[i]} data changed`);
+ }
}
try {
- rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
+ store.off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
} catch (err) {
- console.log('Failed to unregister observer')
+ console.error(`Unregister observer failed, err: ${err}`);
}
```
@@ -2484,16 +2508,15 @@ Provides APIs to access the result set obtained by querying the RDB store. A res
### Usage
-Obtain the **resultSet** object by [RdbStore.query()](#query).
+Obtain the **resultSet** object first.
```js
-import dataRdb from '@ohos.data.rdb';
-let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("AGE", 18);
-let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
+let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- console.log(TAG + "resultSet columnNames:" + resultSet.columnNames);
- console.log(TAG + "resultSet columnCount:" + resultSet.columnCount);
+ console.info(`resultSet columnNames: ${resultSet.columnNames}`);
+ console.info(`resultSet columnCount: ${resultSet.columnCount}`);
});
```
@@ -2618,13 +2641,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example**
```js
-let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
-let promise= rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+let promise= store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- resultSet.goTo(1);
- resultSet.close();
+ resultSet.goTo(1);
+ resultSet.close();
}).catch((err) => {
- console.log('query failed');
+ console.error(`query failed, err: ${err}`);
});
```
@@ -2659,13 +2682,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example**
```js
-let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
-let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- resultSet.(5);
- resultSet.close();
+ resultSet.(5);
+ resultSet.close();
}).catch((err) => {
- console.log('query failed');
+ console.error(`query failed, err: ${err}`);
});
```
@@ -2695,13 +2718,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example**
```js
-let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
-let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- resultSet.goToFirstRow();
- resultSet.close();
+ resultSet.goToFirstRow();
+ resultSet.close();
}).catch((err) => {
- console.log('query failed');
+ console.error(`query failed, err: ${err}`);
});
```
@@ -2730,13 +2753,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example**
```js
-let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
-let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- resultSet.goToLastRow();
- resultSet.close();
+ resultSet.goToLastRow();
+ resultSet.close();
}).catch((err) => {
- console.log('query failed');
+ console.error(`query failed, err: ${err}`);
});
```
@@ -2765,13 +2788,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example**
```js
-let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
-let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- resultSet.goToNextRow();
- resultSet.close();
+ resultSet.goToNextRow();
+ resultSet.close();
}).catch((err) => {
- console.log('query failed');
+ console.error(`query failed, err: ${err}`);
});
```
@@ -2800,13 +2823,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example**
```js
-let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
-let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
+let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
+let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
- resultSet.goToPreviousRow();
- resultSet.close();
+ resultSet.goToPreviousRow();
+ resultSet.close();
}).catch((err) => {
- console.log('query failed');
+ console.error(`query failed, err: ${err}`);
});
```
@@ -2894,9 +2917,9 @@ Obtains the value of the Long type based on the specified column and the current
**Return value**
-| Type | Description |
-| ------ | -------------------------- |
-| number | Value obtained.|
+| Type | Description |
+| ------ | ------------------------------------------------------------ |
+| number | Value obtained.
The value range supported by this API is **Number.MIN_SAFE_INTEGER** to **Number.MAX_SAFE_INTEGER**. If the value is out of this range, use [getDouble](#getdouble).|
**Error codes**
@@ -2991,12 +3014,12 @@ Closes this result set.
**Example**
```js
-let predicatesClose = new dataRdb.RdbPredicates("EMPLOYEE");
-let promiseClose = rdbStore.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
+let predicatesClose = new relationalStore.RdbPredicates("EMPLOYEE");
+let promiseClose = store.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promiseClose.then((resultSet) => {
- resultSet.close();
+ resultSet.close();
}).catch((err) => {
- console.log('resultset close failed');
+ console.error(`resultset close failed, err: ${err}`);
});
```