diff --git a/zh-cn/application-dev/database/database-relational-guidelines.md b/zh-cn/application-dev/database/database-relational-guidelines.md index 6d62e1d6024c0faff563643d3ae9d5100c8c6f14..0eb66f5cd42022b1cf8ef6475cbcd280e9c2e63f 100644 --- a/zh-cn/application-dev/database/database-relational-guidelines.md +++ b/zh-cn/application-dev/database/database-relational-guidelines.md @@ -201,76 +201,81 @@ FA模型示例: ```js - import data_rdb from '@ohos.data.relationalStore' + import relationalStore from '@ohos.data.relationalStore' import featureAbility from '@ohos.ability.featureAbility' + var store; + // 获取context - let context = featureAbility.getContext() + let context = featureAbility.getContext(); const STORE_CONFIG = { name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1 - } + securityLevel: relationalStore.SecurityLevel.S1 + }; // 假设当前数据库版本为3 - data_rdb.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) { - // 当数据库创建时,数据库默认版本为0 - if (rdbStore.version == 0) { - rdbStore.executeSql("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY AUTOINCREMENT, score REAL);", null) - // 设置数据库的版本,入参为大于0的整数 - rdbStore.version = 3 - } + relationalStore.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) { + store = rdbStore; + // 当数据库创建时,数据库默认版本为0 + if (store.version == 0) { + store.executeSql("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY AUTOINCREMENT, score REAL);", null); + // 设置数据库的版本,入参为大于0的整数 + store.version = 3; + } - // 当数据库存在并假定版本为1时,例应用从某一版本升级到当前版本,数据库需要从1版本升级到2版本 - if (rdbStore.version != 3 && rdbStore.version == 1) { - // version = 1:表结构:student (id, age) => version = 2:表结构:student (id, age, score) - rdbStore.executeSql("ALTER TABLE student ADD COLUMN score REAL", null) - rdbStore.version = 2 - } + // 当数据库存在并假定版本为1时,例应用从某一版本升级到当前版本,数据库需要从1版本升级到2版本 + if (store.version != 3 && store.version == 1) { + // version = 1:表结构:student (id, age) => version = 2:表结构:student (id, age, score) + store.executeSql("ALTER TABLE student ADD COLUMN score REAL", null); + store.version = 2; + } - // 当数据库存在并假定版本为2时,例应用从某一版本升级到当前版本,数据库需要从2版本升级到3版本 - if (rdbStore.version != 3 && rdbStore.version == 2) { - // version = 2:表结构:student (id, age, score) => version = 3:表结构:student (id, score) - rdbStore.executeSql("ALTER TABLE student DROP COLUMN age INTEGER", null) - rdbStore.version = 3 - } + // 当数据库存在并假定版本为2时,例应用从某一版本升级到当前版本,数据库需要从2版本升级到3版本 + if (store.version != 3 && store.version == 2) { + // version = 2:表结构:student (id, age, score) => version = 3:表结构:student (id, score) + store.executeSql("ALTER TABLE student DROP COLUMN age INTEGER", null); + store.version = 3; + } }) ``` Stage模型示例: ```ts - import data_rdb from '@ohos.data.relationalStore' + import relationalStore from '@ohos.data.relationalStore' import UIAbility from '@ohos.app.ability.UIAbility' class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { - const STORE_CONFIG = { - name: "rdbstore.db", - securityLevel: data_rdb.SecurityLevel.S1 - } + var store; + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1 + }; - // 假设当前数据库版本为3 - data_rdb.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) { - // 当数据库创建时,数据库默认版本为0 - if (rdbStore.version == 0) { - rdbStore.executeSql("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY AUTOINCREMENT, score REAL);", null) - // 设置数据库的版本,入参为大于0的整数 - rdbStore.version = 3 - } + // 假设当前数据库版本为3 + relationalStore.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) { + store = rdbStore; + // 当数据库创建时,数据库默认版本为0 + if (store.version == 0) { + store.executeSql("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY AUTOINCREMENT, score REAL);", null); + // 设置数据库的版本,入参为大于0的整数 + store.version = 3; + } - // 当数据库存在并假定版本为1时,例应用从某一版本升级到当前版本,数据库需要从1版本升级到2版本 - if (rdbStore.version != 3 && rdbStore.version == 1) { - // version = 1:表结构:student (id, age) => version = 2:表结构:student (id, age, score) - rdbStore.executeSql("ALTER TABLE student ADD COLUMN score REAL", null) - rdbStore.version = 2 - } + // 当数据库存在并假定版本为1时,例应用从某一版本升级到当前版本,数据库需要从1版本升级到2版本 + if (store.version != 3 && store.version == 1) { + // version = 1:表结构:student (id, age) => version = 2:表结构:student (id, age, score) + store.executeSql("ALTER TABLE student ADD COLUMN score REAL", null); + store.version = 2; + } - // 当数据库存在并假定版本为2时,例应用从某一版本升级到当前版本,数据库需要从2版本升级到3版本 - if (rdbStore.version != 3 && rdbStore.version == 2) { - // version = 2:表结构:student (id, age, score) => version = 3:表结构:student (id, score) - rdbStore.executeSql("ALTER TABLE student DROP COLUMN age INTEGER", null) - rdbStore.version = 3 - } - }) + // 当数据库存在并假定版本为2时,例应用从某一版本升级到当前版本,数据库需要从2版本升级到3版本 + if (store.version != 3 && store.version == 2) { + // version = 2:表结构:student (id, age, score) => version = 3:表结构:student (id, score) + store.executeSql("ALTER TABLE student DROP COLUMN age INTEGER", null); + store.version = 3; + } + }) } } ``` @@ -284,23 +289,24 @@ 示例代码如下: ```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 //使用事务插入数据 - 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(); } ``` @@ -315,17 +321,17 @@ 示例代码如下: ```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(); }) ``` @@ -335,9 +341,9 @@ ```json "requestPermissions": - { - "name": "ohos.permission.DISTRIBUTED_DATASYNC" - } + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC" + } ``` (2) 获取应用权限。 @@ -351,13 +357,13 @@ ```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}`); }) ``` @@ -372,16 +378,16 @@ 示例代码如下: ```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}`); }) ``` @@ -395,15 +401,15 @@ ```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= ${device[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}`); } ``` @@ -416,8 +422,24 @@ 示例代码如下: ```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) { + // 获取deviceIds + 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. 远程查询。 @@ -429,19 +451,19 @@ 示例代码如下: ```js - let rdbPredicate = new data_rdb.RdbPredicates('employee') - predicates.greaterThan("id", 0) - let promiseQuery = rdbStore.remoteQuery('12345678abcde', 'employee', rdbPredicate) + 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}`); }) ``` @@ -452,11 +474,11 @@ 示例代码如下: ```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}`); }) ``` @@ -465,11 +487,11 @@ 示例代码如下: ```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}`); }) ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-relationalStore.md b/zh-cn/application-dev/reference/apis/js-apis-data-relationalStore.md index f4d7e48663787ed4085aae8363ce98c32d8f0123..c94780f46579a103230146e7abe796914e6b353a 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-data-relationalStore.md +++ b/zh-cn/application-dev/reference/apis/js-apis-data-relationalStore.md @@ -15,10 +15,10 @@ ## 导入模块 ```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 @@ -51,20 +51,23 @@ FA模型示例: import featureAbility from '@ohos.ability.featureAbility' +var store; + // 获取context -let context = featureAbility.getContext() +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("Get RdbStore failed, err: " + err) - return - } - console.log("Get 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.`); }) ``` @@ -74,24 +77,26 @@ Stage模型示例: import UIAbility from '@ohos.app.ability.UIAbility' class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage){ - const STORE_CONFIG = { - name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1 - } + onWindowStageCreate(windowStage) { + var store; + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1 + }; - data_rdb.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) { - if (err) { - console.info("Get RdbStore failed, err: " + err) - return - } - console.log("Get RdbStore successfully.") - }) - } + 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 +## relationalStore.getRdbStore getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> @@ -128,19 +133,22 @@ FA模型示例: ```js import featureAbility from '@ohos.ability.featureAbility' +var store; + // 获取context -let context = featureAbility.getContext() +let context = featureAbility.getContext(); const STORE_CONFIG = { - name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1 -} + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1 +}; -let promise = data_rdb.getRdbStore(context, STORE_CONFIG); +let promise = relationalStore.getRdbStore(context, STORE_CONFIG); promise.then(async (rdbStore) => { - console.log("Get RdbStore successfully.") + store = rdbStore; + console.info(`Get RdbStore successfully.`); }).catch((err) => { - console.log("Get RdbStore failed, err: " + err) + console.error(`Get RdbStore failed, err: ${err}`); }) ``` @@ -150,23 +158,25 @@ Stage模型示例: import UIAbility from '@ohos.app.ability.UIAbility' class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage){ - const STORE_CONFIG = { - name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1 - } + onWindowStageCreate(windowStage) { + var store; + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1 + }; - let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG); - promise.then(async (rdbStore) => { - console.log("Get RdbStore successfully.") - }).catch((err) => { - console.log("Get RdbStore failed, err: " + err) - }) - } + 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}`); + }) + } } ``` -## data_rdb.deleteRdbStore +## relationalStore.deleteRdbStore deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void @@ -200,12 +210,12 @@ import featureAbility from '@ohos.ability.featureAbility' // 获取context let context = featureAbility.getContext() -data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) { - if (err) { - console.info("Delete RdbStore failed, err: " + err) - return - } - console.log("Delete RdbStore successfully.") +relationalStore.deleteRdbStore(context, "RdbTest.db", function (err) { + if (err) { + console.error(`Delete RdbStore failed, err: ${err}`); + return; + } + console.info(`Delete RdbStore successfully.`); }) ``` @@ -215,19 +225,19 @@ Stage模型示例: import UIAbility from '@ohos.app.ability.UIAbility' class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage){ - data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err) { - if (err) { - console.info("Delete RdbStore failed, err: " + err) - return - } - console.log("Delete RdbStore successfully.") - }) - } + 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> @@ -264,13 +274,13 @@ FA模型示例: import featureAbility from '@ohos.ability.featureAbility' // 获取context -let context = featureAbility.getContext() +let context = featureAbility.getContext(); -let promise = data_rdb.deleteRdbStore(context, "RdbTest.db") +let promise = relationalStore.deleteRdbStore(context, "RdbTest.db"); promise.then(()=>{ - console.log("Delete RdbStore successfully.") + console.info(`Delete RdbStore successfully.`); }).catch((err) => { - console.info("Delete RdbStore failed, err: " + err) + console.error(`Delete RdbStore failed, err: ${err}`); }) ``` @@ -280,14 +290,14 @@ Stage模型示例: import UIAbility from '@ohos.app.ability.UIAbility' class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage){ - let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db") - promise.then(()=>{ - console.log("Delete RdbStore successfully.") - }).catch((err) => { - console.info("Delete RdbStore failed, err: " + err) - }) - } + 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}`); + }) + } } ``` @@ -397,7 +407,7 @@ constructor(name: string) **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); ``` ### inDevices @@ -424,8 +434,8 @@ inDevices(devices: Array<string>): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.inDevices(['12345678abcde']) +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.inDevices(['12345678abcde']); ``` ### inAllDevices @@ -446,8 +456,8 @@ inAllDevices(): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.inAllDevices() +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.inAllDevices(); ``` ### equalTo @@ -475,8 +485,8 @@ equalTo(field: string, value: ValueType): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.equalTo("NAME", "lisi") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.equalTo("NAME", "lisi"); ``` @@ -505,8 +515,8 @@ notEqualTo(field: string, value: ValueType): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.notEqualTo("NAME", "lisi") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.notEqualTo("NAME", "lisi"); ``` @@ -528,7 +538,7 @@ beginWrap(): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); predicates.equalTo("NAME", "lisi") .beginWrap() .equalTo("AGE", 18) @@ -554,7 +564,7 @@ endWrap(): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); predicates.equalTo("NAME", "lisi") .beginWrap() .equalTo("AGE", 18) @@ -580,7 +590,7 @@ or(): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); predicates.equalTo("NAME", "Lisa") .or() .equalTo("NAME", "Rose") @@ -603,7 +613,7 @@ and(): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); predicates.equalTo("NAME", "Lisa") .and() .equalTo("SALARY", 200.5) @@ -633,8 +643,8 @@ contains(field: string, value: string): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.contains("NAME", "os") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.contains("NAME", "os"); ``` ### beginsWith @@ -661,8 +671,8 @@ beginsWith(field: string, value: string): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.beginsWith("NAME", "os") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.beginsWith("NAME", "os"); ``` ### endsWith @@ -689,8 +699,8 @@ endsWith(field: string, value: string): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.endsWith("NAME", "se") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.endsWith("NAME", "se"); ``` ### isNull @@ -716,8 +726,8 @@ isNull(field: string): RdbPredicates **示例**: ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.isNull("NAME") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.isNull("NAME"); ``` ### isNotNull @@ -743,8 +753,8 @@ isNotNull(field: string): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.isNotNull("NAME") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.isNotNull("NAME"); ``` ### like @@ -771,8 +781,8 @@ like(field: string, value: string): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.like("NAME", "%os%") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.like("NAME", "%os%"); ``` ### glob @@ -799,8 +809,8 @@ glob(field: string, value: string): RdbPredicates **示例:** ```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 @@ -828,8 +838,8 @@ between(field: string, low: ValueType, high: ValueType): RdbPredicates **示例:** ```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 @@ -857,8 +867,8 @@ notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates **示例:** ```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 @@ -885,8 +895,8 @@ greaterThan(field: string, value: ValueType): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.greaterThan("AGE", 18) +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.greaterThan("AGE", 18); ``` ### lessThan @@ -913,8 +923,8 @@ lessThan(field: string, value: ValueType): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.lessThan("AGE", 20) +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.lessThan("AGE", 20); ``` ### greaterThanOrEqualTo @@ -941,8 +951,8 @@ greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.greaterThanOrEqualTo("AGE", 18) +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.greaterThanOrEqualTo("AGE", 18); ``` ### lessThanOrEqualTo @@ -969,8 +979,8 @@ lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.lessThanOrEqualTo("AGE", 20) +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.lessThanOrEqualTo("AGE", 20); ``` ### orderByAsc @@ -996,8 +1006,8 @@ orderByAsc(field: string): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.orderByAsc("NAME") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.orderByAsc("NAME"); ``` ### orderByDesc @@ -1023,8 +1033,8 @@ orderByDesc(field: string): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.orderByDesc("AGE") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.orderByDesc("AGE"); ``` ### distinct @@ -1044,8 +1054,8 @@ distinct(): RdbPredicates **示例:** ```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 @@ -1071,8 +1081,8 @@ limitAs(value: number): RdbPredicates **示例:** ```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 @@ -1098,8 +1108,8 @@ offsetAs(rowOffset: number): RdbPredicates **示例:** ```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 @@ -1125,8 +1135,8 @@ groupBy(fields: Array<string>): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.groupBy(["AGE", "NAME"]) +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.groupBy(["AGE", "NAME"]); ``` ### indexedBy @@ -1153,8 +1163,8 @@ indexedBy(field: string): RdbPredicates **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.indexedBy("SALARY_INDEX") +let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); +predicates.indexedBy("SALARY_INDEX"); ``` ### in @@ -1181,8 +1191,8 @@ in(field: string, value: Array<ValueType>): RdbPredicates **示例:** ```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 @@ -1209,8 +1219,8 @@ notIn(field: string, value: Array<ValueType>): RdbPredicates **示例:** ```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 @@ -1231,9 +1241,9 @@ predicates.notIn("NAME", ["Lisa", "Rose"]) ```js // 设置数据库版本 -rdbStore.version = 3 +store.version = 3; // 获取数据库版本 -console.info("Get RdbStore version is " + rdbStore.version) +console.info(`RdbStore version is ${store.version}`); ``` ### insert @@ -1256,17 +1266,17 @@ insert(table: string, values: ValuesBucket, callback: AsyncCallback<number> ```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("Insert is failed"); - return; - } - console.log("Insert is successful, 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}`); }) ``` @@ -1291,17 +1301,17 @@ insert(table: string, values: ValuesBucket, conflict: ConflictResolution, callb ```js const valueBucket = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), -} -rdbStore.insert("EMPLOYEE", valueBucket, data_rdb.ConflictResolution.ON_CONFLICT_REPLACE, function (status, rowId) { - if (status) { - console.log("Insert is failed"); - return; - } - console.log("Insert is successful, rowId = " + rowId); + "NAME": "Lisa", + "AGE": 18, + "SALARY": 100.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), +}; +store.insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rowId) { + if (err) { + console.error(`Insert is failed, err: ${err}`); + return; + } + console.info(`Insert is successful, rowId = ${rowId}`); }) ``` @@ -1330,16 +1340,16 @@ insert(table: string, values: ValuesBucket):Promise<number> ```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("Insert is successful, rowId = " + rowId); -}).catch((status) => { - console.log("Insert is failed"); + console.info(`Insert is successful, rowId = ${rowId}`); +}).catch((err) => { + console.error(`Insert is failed, err: ${err}`); }) ``` @@ -1369,16 +1379,16 @@ insert(table: string, values: ValuesBucket, conflict: ConflictResolution):Promi ```js const valueBucket = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), -} -let promise = rdbStore.insert("EMPLOYEE", valueBucket, data_rdb.ConflictResolution.ON_CONFLICT_REPLACE) + "NAME": "Lisa", + "AGE": 18, + "SALARY": 100.5, + "CODES": new Uint8Array([1, 2, 3, 4, 5]), +}; +let promise = store.insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); promise.then((rowId) => { - console.log("Insert is successful, rowId = " + rowId); -}).catch((status) => { - console.log("Insert is failed"); + console.info(`Insert is successful, rowId = ${rowId}`); +}).catch((err) => { + console.error(`Insert is failed, err: ${err}`); }) ``` @@ -1402,31 +1412,31 @@ batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCal ```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}`); }) ``` @@ -1455,30 +1465,30 @@ batchInsert(table: string, values: Array<ValuesBucket>):Promise<number& ```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}`); }) ``` @@ -1502,19 +1512,19 @@ update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback& ```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("Updated failed, 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(`Updated failed, err: ${err}`); + return; + } + console.info(`Updated row count: ${rows}`); }) ``` @@ -1539,19 +1549,19 @@ update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolu ```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, data_rdb.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rows) { - if (err) { - console.info("Updated failed, 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, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rows) { + if (err) { + console.error(`Updated failed, err: ${err}`); + return; + } + console.info(`Updated row count: ${rows}`); }) ``` @@ -1580,18 +1590,18 @@ update(values: ValuesBucket, predicates: RdbPredicates):Promise<number> ```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("Updated failed, err: " + err) + console.error(`Updated failed, err: ${err}`); }) ``` @@ -1621,18 +1631,18 @@ update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolu ```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, data_rdb.ConflictResolution.ON_CONFLICT_REPLACE) + "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, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); promise.then(async (rows) => { - console.log("Updated row count: " + rows) + console.info(`Updated row count: ${rows}`); }).catch((err) => { - console.info("Updated failed, err: " + err) + console.error(`Updated failed, err: ${err}`); }) ``` @@ -1664,15 +1674,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("Updated failed, 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(`Updated failed, err: ${err}`); + return; + } + console.info(`Updated row count: ${rows}`); }) ``` @@ -1705,18 +1715,18 @@ update(table: string, values: ValuesBucket, predicates: dataSharePredicates.Data ```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("Updated failed, err: " + err) + console.error(`Updated failed, err: ${err}`); }) ``` @@ -1738,14 +1748,14 @@ delete(predicates: RdbPredicates, callback: AsyncCallback<number>):void **示例:** ```js -let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.equalTo("NAME", "Lisa") -rdbStore.delete(predicates, function (err, rows) { - if (err) { - console.info("Delete failed, err: " + err) - return - } - console.log("Delete 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}`); }) ``` @@ -1772,13 +1782,13 @@ delete(predicates: RdbPredicates):Promise<number> **示例:** ```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("Delete rows: " + rows) + console.info(`Delete rows: ${rows}`); }).catch((err) => { - console.info("Delete failed, err: " + err) + console.error(`Delete failed, err: ${err}`); }) ``` @@ -1804,14 +1814,14 @@ delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callb ```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("Delete failed, err: " + err) - return - } - console.log("Delete 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}`); }) ``` @@ -1842,13 +1852,13 @@ delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promi ```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("Delete rows: " + rows) + console.info(`Delete rows: ${rows}`); }).catch((err) => { - console.info("Delete failed, err: " + err) + console.error(`Delete failed, err: ${err}`); }) ``` @@ -1871,15 +1881,15 @@ query(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCa **示例:** ```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("Query failed, 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}`); }) ``` @@ -1907,14 +1917,14 @@ query(predicates: RdbPredicates, columns?: Array<string>):Promise<Resul **示例:** ```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("Query failed, err: " + err) + console.error(`Query failed, err: ${err}`); }) ``` @@ -1941,15 +1951,15 @@ query(table: string, predicates: dataSharePredicates.DataSharePredicates, column ```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("Query failed, 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}`); }) ``` @@ -1981,14 +1991,14 @@ query(table: string, predicates: dataSharePredicates.DataSharePredicates, column ```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("Query failed, err: " + err) + console.error(`Query failed, err: ${err}`); }) ``` @@ -2013,17 +2023,18 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A **示例:** ```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 @@ -2052,14 +2063,14 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A **示例:** ```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}`); }) ``` @@ -2082,13 +2093,13 @@ querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback& **示例:** ```js -rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { - if (err) { - console.info("Query failed, 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}`); }) ``` @@ -2116,12 +2127,12 @@ querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> **示例:** ```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("Query failed, err: " + err) + console.error(`Query failed, err: ${err}`); }) ``` @@ -2145,12 +2156,12 @@ executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallbac ```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("ExecuteSql failed, 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.`); }) ``` @@ -2179,11 +2190,11 @@ executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> ```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("ExecuteSql failed, err: " + err) + console.error(`ExecuteSql failed, err: ${err}`); }) ``` @@ -2199,19 +2210,25 @@ beginTransaction():void ```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(); }) ``` @@ -2227,19 +2244,25 @@ commit():void ```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(); }) ``` @@ -2255,24 +2278,31 @@ rollBack():void ```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(); + } }) ``` @@ -2294,12 +2324,12 @@ backup(destName:string, callback: AsyncCallback<void>):void **示例:** ```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.`); }) ``` @@ -2326,11 +2356,11 @@ backup(destName:string): Promise<void> **示例:** ```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}`); }) ``` @@ -2352,12 +2382,12 @@ restore(srcName:string, callback: AsyncCallback<void>):void **示例:** ```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.`); }) ``` @@ -2384,11 +2414,11 @@ restore(srcName:string): Promise<void> **示例:** ```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}`); }) ``` @@ -2412,12 +2442,12 @@ setDistributedTables(tables: Array<string>, callback: AsyncCallback<voi **示例:** ```js -rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { - if (err) { - console.info('SetDistributedTables failed, err: ' + err) - return - } - console.info('SetDistributedTables successfully.') +store.setDistributedTables(["EMPLOYEE"], function (err) { + if (err) { + console.error(`SetDistributedTables failed, err: ${err}`); + return; + } + console.info(`SetDistributedTables successfully.`); }) ``` @@ -2446,11 +2476,11 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { **示例:** ```js -let promise = rdbStore.setDistributedTables(["EMPLOYEE"]) +let promise = store.setDistributedTables(["EMPLOYEE"]); promise.then(() => { - console.info("SetDistributedTables successfully.") + console.info(`SetDistributedTables successfully.`); }).catch((err) => { - console.info("SetDistributedTables failed, err: " + err) + console.error(`SetDistributedTables failed, err: ${err}`); }) ``` @@ -2475,12 +2505,12 @@ obtainDistributedTableName(device: string, table: string, callback: AsyncCallbac **示例:** ```js -rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) { +store.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) { if (err) { - console.info('ObtainDistributedTableName failed, err: ' + err) - return + console.error(`ObtainDistributedTableName failed, err: ${err}`); + return; } - console.info('ObtainDistributedTableName successfully, tableName=.' + tableName) + console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); }) ``` @@ -2510,11 +2540,11 @@ rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, **示例:** ```js -let promise = rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE") +let promise = store.obtainDistributedTableName("12345678abcde", "EMPLOYEE"); promise.then((tableName) => { - console.info('ObtainDistributedTableName successfully, tableName= ' + tableName) + console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); }).catch((err) => { - console.info('ObtainDistributedTableName failed, err: ' + err) + console.error(`ObtainDistributedTableName failed, err: ${err}`); }) ``` @@ -2539,17 +2569,17 @@ sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array **示例:** ```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]}`); + } }) ``` @@ -2579,16 +2609,16 @@ rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, resul **示例:** ```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}`); }) ``` @@ -2612,14 +2642,14 @@ on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<stri ```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('Register observer failed') + console.error(`Register observer failed, err: ${err}`); } ``` @@ -2643,14 +2673,14 @@ off(event:'dataChange', type: SubscribeType, observer: Callback<Array<stri ```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('Unregister observer failed') + console.error(`Unregister observer failed, err: ${err}`); } ``` @@ -2660,16 +2690,15 @@ try { ### 使用说明 -需要通过[RdbStore.query()](#query)获取resultSet对象。 +首先需要获取resultSet对象。 ```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}`); }); ``` @@ -2794,13 +2823,13 @@ goTo(offset:number): boolean **示例:** ```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}`); }); ``` @@ -2835,13 +2864,13 @@ goToRow(position: number): boolean **示例:** ```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}`); }); ``` @@ -2871,13 +2900,13 @@ goToFirstRow(): boolean **示例:** ```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}`); }); ``` @@ -2906,13 +2935,13 @@ goToLastRow(): boolean **示例:** ```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}`); }); ``` @@ -2941,13 +2970,13 @@ goToNextRow(): boolean **示例:** ```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}`); }); ``` @@ -2976,13 +3005,13 @@ goToPreviousRow(): boolean **示例:** ```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}`); }); ``` @@ -3135,12 +3164,12 @@ close(): void **示例:** ```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}`); }); ```