未验证 提交 c43ffa52 编写于 作者: O openharmony_ci 提交者: Gitee

!22417 [翻译完成】#I7OYQ4

Merge pull request !22417 from Annie_wang/PR21542
......@@ -10,7 +10,7 @@ The **Preferences** module provides APIs for processing data in the form of key-
User applications call **Preference** through the JS interface to read and write data files. You can load the data of a **Preferences** persistence file to a **Preferences** instance. Each file uniquely corresponds to an instance. The system stores the instance in memory through a static container until the instance is removed from the memory or the file is deleted. The following figure illustrates how **Preference** works.
The preference persistent file of an application is stored in the application sandbox. You can use **context** to obtain the file path. For details, see [Obtaining the Application Development Path](../application-models/application-context-stage.md#obtaining-the-application-development-path).
The preference persistent file of an application is stored in the application sandbox. You can use **context** to obtain the file path. For details, see [Obtaining Application File Paths](../application-models/application-context-stage.md# obtaining-application-file-paths).
**Figure 1** Preferences working mechanism
......@@ -28,7 +28,7 @@ The preference persistent file of an application is stored in the application sa
## Available APIs
The following table lists the APIs used for preferences data persistence. Most of the APIs are executed asynchronously, using a callback or promise to return the result. The following table uses the callback-based APIs as an example. For more information about the APIs, see [User Preferences](../reference/apis/js-apis-data-preferences.md).
The following table lists the APIs used for preferences data persistence. Most of the APIs are executed asynchronously in callback or promise mode. The following table uses the callback-based APIs as an example. For more information about the APIs, see [User Preferences](../reference/apis/js-apis-data-preferences.md).
| API| Description|
| -------- | -------- |
......@@ -68,7 +68,7 @@ The following table lists the APIs used for preferences data persistence. Most o
return;
}
console.info('Succeeded in getting preferences.');
// Perform related data operations.
// Before performing related data operations, obtain a Preferences instance.
})
} catch (err) {
console.error(`Failed to get preferences. Code:${err.code},message:${err.message}`);
......@@ -93,7 +93,7 @@ The following table lists the APIs used for preferences data persistence. Most o
return;
}
console.info('Succeeded in getting preferences.');
// Perform related data operations.
// Before performing related data operations, obtain a Preferences instance.
})
} catch (err) {
console.error(`Failed to get preferences. Code is ${err.code},message:${err.message}`);
......@@ -143,7 +143,7 @@ The following table lists the APIs used for preferences data persistence. Most o
4. Read data.
Use **get()** to obtain the value of the specified key. If the value is null or is not of the default value type, the default data is returned.
Use **get()** to obtain the value of the specified key. If the value is null or is not of the default value type, the default data is returned.
Example:
......@@ -182,8 +182,10 @@ The following table lists the APIs used for preferences data persistence. Most o
6. Persist data.
You can use **flush()** to persist the data held in a **Preferences** instance to a file. Example:
You can use **flush()** to persist the data held in a **Preferences** instance to a file.
Example:
```js
try {
preferences.flush((err) => {
......@@ -200,8 +202,10 @@ The following table lists the APIs used for preferences data persistence. Most o
7. Subscribe to data changes.
Specify an observer as the callback to return the data changes for an application. When the value of the subscribed key is changed and saved by **flush()**, the observer callback will be invoked to return the new data. Example:
Specify an observer as the callback to return the data changes for an application. When the value of the subscribed key is changed and saved by **flush()**, the observer callback will be invoked to return the new data.
Example:
```js
let observer = function (key) {
console.info('The key' + key + 'changed.');
......
......@@ -50,7 +50,7 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
## How to Develop
1. Obtain an **RdbStore** instance.<br> Example:
1. Obtain an **RdbStore** instance.<br>Example:
Stage model:
......@@ -75,7 +75,7 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
console.info(`Succeeded in getting RdbStore.`);
store.executeSql(SQL_CREATE_TABLE); // Create a data table.
// Perform operations such as adding, deleting, modifying, and querying data in the RDB store.
// Before performing data operations on the database, obtain an RdbStore instance.
});
}
......@@ -107,7 +107,7 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
console.info(`Succeeded in getting RdbStore.`);
store.executeSql(SQL_CREATE_TABLE); // Create a data table.
// Perform operations such as adding, deleting, modifying, and querying data in the RDB store.
// Before performing data operations on the database, obtain an RdbStore instance.
});
```
......@@ -118,7 +118,7 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
>
> - When an application calls **getRdbStore()** to obtain an RDB store instance for the first time, the corresponding database file is generated in the application sandbox. When the RDB store is used, temporary files ended with **-wal** and **-shm** may be generated in the same directory as the database file. If you want to move the database files to other places, you must also move these temporary files. After the application is uninstalled, the database files and temporary files generated on the device are also removed.
2. Use **insert()** to insert data to the RDB store.
2. Use **insert()** to insert data to the RDB store.
Example:
......@@ -144,7 +144,7 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
3. Modify or delete data based on the specified **Predicates** instance.
Use **update()** to modify data and **delete()** to delete data.
Use **update()** to modify data and **delete()** to delete data.
Example:
......@@ -180,7 +180,7 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
4. Query data based on the conditions specified by **Predicates**.
Use **query()** to query data. The data obtained is returned in a **ResultSet** object.
Use **query()** to query data. The data obtained is returned in a **ResultSet** object.
Example:
......@@ -203,7 +203,7 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
5. Delete the RDB store.
Use **deleteRdbStore()** to delete the RDB store and related database files.
Use **deleteRdbStore()** to delete the RDB store and related database files.
Example:
......@@ -242,4 +242,4 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
}
console.info('Succeeded in deleting RdbStore.');
});
```
```
\ No newline at end of file
......@@ -91,7 +91,7 @@ The following table lists the APIs for cross-device data synchronization of the
## How to Develop
The following uses a single KV store as an example to describe how to implement cross-device data synchronization. The following describes the development process.
The following uses a single KV store as an example to describe how to implement cross-device data synchronization. The development process is as follows.
![kvStore_development_process](figures/kvStore_development_process.png)
......@@ -171,7 +171,7 @@ The following uses a single KV store as an example to describe how to implement
return;
}
console.info('Succeeded in getting KVStore.');
// Perform related data operations.
// Before performing related data operations, obtain a KV store instance.
});
} catch (e) {
console.error(`An unexpected error occurred. Code:${e.code},message:${e.message}`);
......@@ -275,4 +275,4 @@ The following uses a single KV store as an example to describe how to implement
}
}
});
```
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册