From e7c4fb92b716924547052b2603abfb4883c6c13f Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Mon, 5 Dec 2022 16:55:07 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../database-preference-guidelines.md | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/en/application-dev/database/database-preference-guidelines.md b/en/application-dev/database/database-preference-guidelines.md index c4f6250f5a..897be37128 100644 --- a/en/application-dev/database/database-preference-guidelines.md +++ b/en/application-dev/database/database-preference-guidelines.md @@ -28,26 +28,29 @@ Obtain a **Preferences** instance for data operations. A **Preferences** instanc | --------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | ohos.data.preferences | getPreferences(context: Context, name: string): Promise\ | Obtains a **Preferences** instance.| -### Accessing Data +### Processing Data -Call the **put()** method to add or modify data in a **Preferences** instance. +Call **put()** to add or modify data in a **Preferences** instance. -Call the **get()** method to read data from a **Preferences** instance. +Call **get()** to read data from a **Preferences** instance. Call **getAll()** to obtain an **Object** instance that contains all KV pairs in a **Preferences** instance. -**Table 2** APIs for accessing **Preferences** data +Call **delete()** to delete the KV pair of the specified key from the **Preferences** instance. + +**Table 2** APIs for processing **Preferences** data | Class | API | Description | | ----------- | ---------------------------------------------------------- | ------------------------------------------------------------ | | Preferences | put(key: string, value: ValueType): Promise\ | Writes data to the **Preferences** instance. The value to write can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.| | Preferences | get(key: string, defValue: ValueType): Promise\ | Obtains data from the **Preferences** instance. The value to read can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.| -| Preferences | getAll(): Promise | Obtains an **Object** instance that contains all KV pairs in the **Preferences** instance. | +| Preferences | getAll(): Promise\ | Obtains an **Object** instance that contains all KV pairs in the **Preferences** instance. | +| Preferences | delete(key: string): Promise\ | Deletes the KV pair of the specified key from the **Preferences** instance. | ### Storing Data Persistently -Call the **flush()** method to write the cached data back to its text file for persistent storage. +Call **flush()** to write the cached data back to its text file for persistent storage. **Table 4** API for data persistence @@ -68,7 +71,7 @@ You can subscribe to data changes. When the value of the subscribed key is chang ### Deleting Data -Use the following APIs to delete a **Preferences** instance or data file. +You can use the following APIs to delete a **Preferences** instance or data file. **Table 6** APIs for deleting **Preferences** @@ -130,7 +133,7 @@ Use the following APIs to delete a **Preferences** instance or data file. 3. Write data. - Use the **preferences.put()** method to write data to the **Preferences** instance. + Use **preferences.put()** to write data to the **Preferences** instance. ```js let putPromise = preferences.put('startup', 'auto'); @@ -143,7 +146,7 @@ Use the following APIs to delete a **Preferences** instance or data file. 4. Read data. - Use the **preferences.get()** method to read data. + Use **preferences.get()** to read data. ```js let getPromise = preferences.get('startup', 'default'); @@ -156,7 +159,7 @@ Use the following APIs to delete a **Preferences** instance or data file. 5. Store data persistently. - Use the **flush()** method to flush data from the **Preferences** instance to its file. + Use **flush()** to flush data from the **Preferences** instance to its file. ```js preferences.flush(); @@ -177,7 +180,7 @@ Use the following APIs to delete a **Preferences** instance or data file. console.info("Failed to put the value of 'startup'. Cause: " + err); return; } - console.info("Put the value of 'startup' successfully."); + console.info("Put the value of 'startup' successfully."); preferences.flush(function (err) { if (err) { console.info("Failed to flush data. Cause: " + err); @@ -190,7 +193,7 @@ Use the following APIs to delete a **Preferences** instance or data file. 7. Delete the specified file. - Use the **deletePreferences** method to delete the **Preferences** instance and its persistent file and backup and corrupted files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will be caused. The deleted data and files cannot be restored. + Use **deletePreferences()** to delete the **Preferences** instance and its persistent file and backup and corrupted files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will be caused. The deleted data and files cannot be restored. ```js let proDelete = data_preferences.deletePreferences(context, 'mystore'); -- GitLab