diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md b/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md index 5fc7302b31b47f2858c45e110147c770b1639dd1..10f7ff81ae00262d69726296b1997ee02dfb828c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md +++ b/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md @@ -30,6 +30,7 @@ getRdbStore(context?: Context, config: StoreConfig, version: number, callback: A - 示例: ``` + //示例一:Stage or FA 模式 import Ability from '@ohos.application.Ability' import data_rdb from '@ohos.data.rdb' export default class MainAbility extends Ability { @@ -40,6 +41,14 @@ getRdbStore(context?: Context, config: StoreConfig, version: number, callback: A console.info('create table done.') }) } + //示例二:FA Only模式 + import data_rdb from '@ohos.data.rdb' + const STORE_CONFIG = { name: "RdbTest.db"} + const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" + data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { + rdbStore.executeSql(SQL_CREATE_TABLE) + console.info('create table done.') + }) ``` ## data_rdb.getRdbStore @@ -64,6 +73,7 @@ getRdbStore(context?: Context, config: StoreConfig, version: number): Promise< - 示例: ``` + //示例一:Stage or FA 模式 import Ability from '@ohos.application.Ability' import data_rdb from '@ohos.data.rdb' export default class MainAbility extends Ability { @@ -81,6 +91,21 @@ getRdbStore(context?: Context, config: StoreConfig, version: number): Promise< console.log("getRdbStore err.") }) } + //示例二:FA Only模式 + import data_rdb from '@ohos.data.rdb' + const STORE_CONFIG = { name: "RdbTest.db" } + const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" + let promisegetRdb = data_rdb.getRdbStore(STORE_CONFIG, 1); + promisegetRdb.then(async (rdbStore) => { + let promiseExecSql = rdbStore.executeSql(SQL_CREATE_TABLE, null) + promiseExecSql.then(() => { + console.info('executeSql creat done.') + }).catch((err) => { + console.log("executeSql creat err.") + }) + }).catch((err) => { + console.log("getRdbStore err.") + }) ``` ## data_rdb.deleteRdbStore @@ -100,6 +125,7 @@ deleteRdbStore(context?: Context, name: string, callback: AsyncCallback<void& - 示例: ``` + //示例一:Stage or FA 模式 import Ability from '@ohos.application.Ability' import data_rdb from '@ohos.data.rdb' export default class MainAbility extends Ability { @@ -107,6 +133,11 @@ deleteRdbStore(context?: Context, name: string, callback: AsyncCallback<void& console.info('delete store done.') }) } + //示例二:FA Only模式 + import data_rdb from '@ohos.data.rdb' + data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) { + console.info('delete store done.') + }) ``` ## data_rdb.deleteRdbStore @@ -130,6 +161,7 @@ deleteRdbStore(context?: Context, name: string): Promise<void> - 示例: ``` + //示例一:Stage or FA 模式 import Ability from '@ohos.application.Ability' import data_rdb from '@ohos.data.rdb' export default class MainAbility extends Ability { @@ -140,6 +172,14 @@ deleteRdbStore(context?: Context, name: string): Promise<void> console.log("deleteRdbStore err.") }) } + //示例二:FA Only模式 + import data_rdb from '@ohos.data.rdb' + let promisedeleteRdb = data_rdb.deleteRdbStore("RdbTest.db") + promisedeleteRdb.then(()=>{ + console.info('delete store done.') + }).catch((err) => { + console.log("deleteRdbStore err.") + }) ``` ## RdbPredicates diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-storage.md b/zh-cn/application-dev/reference/apis/js-apis-data-storage.md index 04b1695912e16df298266993d9be52bc239bc008..f39822ce4d2108c30849bfe2047780541b293aef 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-data-storage.md +++ b/zh-cn/application-dev/reference/apis/js-apis-data-storage.md @@ -47,10 +47,16 @@ getStorageSync(path: string): Storage import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext() - var path = await context.getFilesDir() - let storage = dataStorage.getStorageSync(path + '/mystore') - storage.putSync('startup', 'auto') - storage.flushSync() + context.getFilesDir((err, path) => { + if (err) { + console.error('getFilesDir failed. err: ' + JSON.stringify(err)); + return; + } + console.info('getFilesDir successful. path:' + JSON.stringify(path)); + let storage = dataStorage.getStorageSync(path + '/mystore') + storage.putSync('startup', 'auto') + storage.flushSync() + }); ``` @@ -74,15 +80,21 @@ getStorage(path: string, callback: AsyncCallback<Storage>): void import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext() - var path = await context.getFilesDir() - dataStorage.getStorage(path + '/mystore', function (err, storage) { + context.getFilesDir((err, path) => { if (err) { - console.info("Get the storage failed, path: " + path + '/mystore') + console.error('getFilesDir failed. err: ' + JSON.stringify(err)); return; } - storage.putSync('startup', 'auto') - storage.flushSync() - }) + console.info('getFilesDir successful. path:' + JSON.stringify(path)); + dataStorage.getStorage(path + '/mystore', function (err, storage) { + if (err) { + console.info("Get the storage failed, path: " + path + '/mystore') + return; + } + storage.putSync('startup', 'auto') + storage.flushSync() + }) + }); ``` @@ -110,14 +122,20 @@ getStorage(path: string): Promise<Storage> import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext() - var path = await context.getFilesDir() - let promisegetSt = dataStorage.getStorage(path + '/mystore') - promisegetSt.then((storage) => { - storage.putSync('startup', 'auto') - storage.flushSync() - }).catch((err) => { - console.info("Get the storage failed, path: " + path + '/mystore') - }) + context.getFilesDir((err, path) => { + if (err) { + console.info("Get the storage failed, path: " + path + '/mystore') + return; + } + console.info('getFilesDir successful. path:' + JSON.stringify(path)); + let promisegetSt = dataStorage.getStorage(path + '/mystore') + promisegetSt.then((storage) => { + storage.putSync('startup', 'auto') + storage.flushSync() + }).catch((err) => { + console.info("Get the storage failed, path: " + path + '/mystore') + }) + }); ```