未验证 提交 fce37c3f 编写于 作者: 葛亚芳 提交者: Gitee

update en/application-dev/database/database-preference-guidelines.md.

Signed-off-by: N@ge-yafang <geyafang@huawei.com>
上级 915c92be
......@@ -74,7 +74,7 @@ Use the following APIs to delete a **Storage** instance or data file.
1. Import @ohos.data.storage and related modules to the development environment.
```
```js
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility' // Used to obtain the file storage path.
```
......@@ -82,7 +82,7 @@ Use the following APIs to delete a **Storage** instance or data file.
2. Create a **Storage** instance.
Read the specified file and load its data to the **Storage** instance for data operations.
```
```js
var context = featureAbility.getContext()
context.getFilesDir().then(() => {
console.info("======================>getFilesDirPromsie====================>");
......@@ -95,7 +95,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **put()** method of the **Storage** class to write data to the cached **Storage** instance.
```
```js
promise.then((storage) => {
let getPromise = storage.put('startup', 'auto') // Save data to the Storage instance.
getPromise.then(() => {
......@@ -112,7 +112,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **get()** method of the **Storage** class to read data.
```
```js
promise.then((storage) => {
let getPromise = storage.get('startup', 'default')
getPromise.then((value) => {
......@@ -128,7 +128,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **flush()** or **flushSync()** method to flush data in the **Storage** instance to its file.
```
```js
storage.flush();
```
......@@ -136,7 +136,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Specify **StorageObserver** as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and the **flush()** method is executed, **StorageObserver** will be invoked. Unregister the **StorageObserver** when it is no longer required.
```
```js
promise.then((storage) => {
var observer = function (key) {
console.info("The key of " + key + " changed.")
......@@ -155,7 +155,7 @@ Use the following APIs to delete a **Storage** instance or data file.
Use the **deleteStorage** method to delete the **Storage** singleton of the specified file from the memory, and delete the specified file, its backup file, and damaged files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will occur. The deleted data and files cannot be restored.
```
```js
let promise = dataStorage.deleteStorage(path + '/mystore')
promise.then(() => {
console.info("Deleted successfully.")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册