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

!6249 [翻译完成】#I5BY22

Merge pull request !6249 from Annie_wang/PR5200A
# Relational Database # Relational Database
The relational database (RDB) manages data based on relational models. With the underlying SQLite database, the RDB provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB offers a series of methods for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.
This module provides the following RDB-related functions:
- [RdbPredicates](#rdbpredicates): predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
- [RdbStore](#rdbstore): provides APIs for managing an RDB store.
> **NOTE**<br/> > **NOTE**<br/>
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -11,71 +19,9 @@ import data_rdb from '@ohos.data.rdb'; ...@@ -11,71 +19,9 @@ import data_rdb from '@ohos.data.rdb';
## data_rdb.getRdbStore ## data_rdb.getRdbStore
getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void
Obtains a relational database (RDB) store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
| version | number | Yes| RDB store version.|
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes| Callback invoked to return the RDB store obtained.|
**Example**
```js
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
if (err) {
console.info("Failed to get RdbStore, err: " + err)
return
}
console.log("Got RdbStore successfully.")
})
```
## data_rdb.getRdbStore
getRdbStore(config: StoreConfig, version: number): Promise&lt;RdbStore&gt;
Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
| version | number | Yes| RDB store version.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise used to return the RDB store obtained.|
**Example**
```js
const STORE_CONFIG = { name: "RdbTest.db" }
let promise = data_rdb.getRdbStore(STORE_CONFIG, 1);
promise.then(async (rdbStore) => {
console.log("Got RdbStore successfully.")
}).catch((err) => {
console.log("Failed to get RdbStore, err: " + err)
})
```
## data_rdb.getRdbStore<sup>8+</sup>
getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void
Obtains a RDB store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. Obtains an RDB store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -83,7 +29,7 @@ Obtains a RDB store. This API uses an asynchronous callback to return the result ...@@ -83,7 +29,7 @@ Obtains a RDB store. This API uses an asynchronous callback to return the result
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | Yes| Context of the app or functionality.<br>For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).<br>For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).| | context | Context | Yes| Context of the application or functionality.<br>See [Context](js-apis-Context.md) for versions earlier than API version 9.<br>See [Context](js-apis-ability-context.md) for API version 9 or later.|
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.| | config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
| version | number | Yes| RDB store version.| | version | number | Yes| RDB store version.|
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes| Callback invoked to return the RDB store obtained.| | callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes| Callback invoked to return the RDB store obtained.|
...@@ -101,7 +47,7 @@ data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { ...@@ -101,7 +47,7 @@ data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
}) })
``` ```
## data_rdb.getRdbStore<sup>8+</sup> ## data_rdb.getRdbStore
getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt; getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt;
...@@ -113,7 +59,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set ...@@ -113,7 +59,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | Yes| Context of the app or functionality.<br>For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).<br>For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).| | context | Context | Yes| Context of the application or functionality.<br>See [Context](js-apis-Context.md) for versions earlier than API version 9.<br>See [Context](js-apis-ability-context.md) for API version 9 or later.|
| config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.| | config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.|
| version | number | Yes| RDB store version.| | version | number | Yes| RDB store version.|
...@@ -137,68 +83,16 @@ promise.then(async (rdbStore) => { ...@@ -137,68 +83,16 @@ promise.then(async (rdbStore) => {
## data_rdb.deleteRdbStore ## data_rdb.deleteRdbStore
deleteRdbStore(name: string, callback: AsyncCallback&lt;void&gt;): void
Deletes an RDB store. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the RDB store to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example**
```js
data_rdb.deleteRdbStore("RdbTest.db", function (err, rdbStore) {
if (err) {
console.info("Failed to delete RdbStore, err: " + err)
return
}
console.log("Deleted RdbStore successfully.")
})
```
## data_rdb.deleteRdbStore
deleteRdbStore(name: string): Promise&lt;void&gt;
Deletes an RDB store. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the RDB store to delete.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
let promise = data_rdb.deleteRdbStore("RdbTest.db")
promise.then(()=>{
console.log("Deleted RdbStore successfully.")
}).catch((err) => {
console.info("Failed to delete RdbStore, err: " + err)
})
```
## data_rdb.deleteRdbStore<sup>8+</sup>
deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
Deletes an RDB store. This API uses a callback to return the result. Deletes an RDB store. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | Yes| Context of the app or functionality.<br>For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).<br>For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).| | context | Context | Yes| Context of the application or functionality.<br>See [Context](js-apis-Context.md) for versions earlier than API version 9.<br>See [Context](js-apis-ability-context.md) for API version 9 or later.|
| name | string | Yes| Name of the RDB store to delete.| | name | string | Yes| Name of the RDB store to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
...@@ -213,7 +107,7 @@ data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) { ...@@ -213,7 +107,7 @@ data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) {
}) })
``` ```
## data_rdb.deleteRdbStore<sup>8+</sup> ## data_rdb.deleteRdbStore
deleteRdbStore(context: Context, name: string): Promise&lt;void&gt; deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
...@@ -224,7 +118,7 @@ Deletes an RDB store. This API uses a promise to return the result. ...@@ -224,7 +118,7 @@ Deletes an RDB store. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | Yes| Context of the app or functionality.<br>For the definition of **Context** of API version 8, see [Context](js-apis-Context.md).<br>For the definition of **Context** of API version 9, see [Context](js-apis-ability-context.md).| | context | Context | Yes| Context of the application or functionality.<br>See [Context](js-apis-Context.md) for versions earlier than API version 9.<br>See [Context](js-apis-ability-context.md) for API version 9 or later.|
| name | string | Yes| Name of the RDB store to delete.| | name | string | Yes| Name of the RDB store to delete.|
**Return value** **Return value**
...@@ -234,7 +128,7 @@ Deletes an RDB store. This API uses a promise to return the result. ...@@ -234,7 +128,7 @@ Deletes an RDB store. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let promise = data_rdb.deleteRdbStore("RdbTest.db") let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db")
promise.then(()=>{ promise.then(()=>{
console.log("Deleted RdbStore successfully.") console.log("Deleted RdbStore successfully.")
}).catch((err) => { }).catch((err) => {
...@@ -1090,7 +984,7 @@ rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) { ...@@ -1090,7 +984,7 @@ rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) {
console.info("Failed to insert data, err: " + err) console.info("Failed to insert data, err: " + err)
return return
} }
console.log("Insert first done: " + ret) console.log("Inserted first row: " + ret)
}) })
``` ```
...@@ -1215,7 +1109,7 @@ Updates data in the database based on the specified **DataSharePredicates** obje ...@@ -1215,7 +1109,7 @@ Updates data in the database based on the specified **DataSharePredicates** obje
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| table | string | Yes| Name of the target table.| | table | string | Yes| Name of the target table.|
| values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to be updated in the database. The key-value pair is associated with the column name in the target table.| | values | [ValuesBucket](#valuesbucket) | Yes| Rows of data to be updated in the database. The key-value pair is associated with the column name in the target table.|
| predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes| Update conditions specified by the **DataSharePredicates** object.| | predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates)| Yes| Update conditions specified by the **DataSharePredicates** object.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of rows updated.|
**Example** **Example**
...@@ -1239,7 +1133,7 @@ rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) { ...@@ -1239,7 +1133,7 @@ rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, ret) {
``` ```
### update<sup>9+</sup> ### update<sup>9+</sup>
update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt; update(table: string, values: ValuesBucket, predicates: DataSharePredicates):Promise&lt;number&gt;
Updates data in the database based on the specified **DataSharePredicates** object. This API uses a promise to return the result. Updates data in the database based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
...@@ -1300,7 +1194,7 @@ rdbStore.delete(predicates, function (err, rows) { ...@@ -1300,7 +1194,7 @@ rdbStore.delete(predicates, function (err, rows) {
console.info("Failed to delete data, err: " + err) console.info("Failed to delete data, err: " + err)
return return
} }
console.log("Delete rows: " + rows) console.log("Deleted rows: " + rows)
}) })
``` ```
...@@ -1329,7 +1223,7 @@ let predicates = new data_rdb.RdbPredicates("EMPLOYEE") ...@@ -1329,7 +1223,7 @@ let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.delete(predicates) let promise = rdbStore.delete(predicates)
promise.then((rows) => { promise.then((rows) => {
console.log("Delete rows: " + rows) console.log("Deleted rows: " + rows)
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete data, err: " + err) console.info("Failed to delete data, err: " + err)
}) })
...@@ -1337,7 +1231,7 @@ promise.then((rows) => { ...@@ -1337,7 +1231,7 @@ promise.then((rows) => {
### delete<sup>9+</sup> ### delete<sup>9+</sup>
delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void delete(table: string, predicates: DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
Deletes data from the database based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result. Deletes data from the database based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
...@@ -1361,12 +1255,12 @@ rdbStore.delete("EMPLOYEE", predicates, function (err, rows) { ...@@ -1361,12 +1255,12 @@ rdbStore.delete("EMPLOYEE", predicates, function (err, rows) {
console.info("Failed to delete data, err: " + err) console.info("Failed to delete data, err: " + err)
return return
} }
console.log("Delete rows: " + rows) console.log("Deleted rows: " + rows)
}) })
``` ```
### delete<sup>9+</sup> ### delete<sup>9+</sup>
delete(table: string, predicates: DataSharePredicates):Promise&lt;number&gt; delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
Deletes data from the database based on the specified **DataSharePredicates** object. This API uses a promise to return the result. Deletes data from the database based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
...@@ -1390,7 +1284,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -1390,7 +1284,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.delete("EMPLOYEE", predicates) let promise = rdbStore.delete("EMPLOYEE", predicates)
promise.then((rows) => { promise.then((rows) => {
console.log("Delete rows: " + rows) console.log("Deleted rows: " + rows)
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete data, err: " + err) console.info("Failed to delete data, err: " + err)
}) })
...@@ -1417,7 +1311,7 @@ let predicates = new data_rdb.RdbPredicates("EMPLOYEE") ...@@ -1417,7 +1311,7 @@ let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
if (err) { if (err) {
console.info("Query failed, err: " + err) console.info("Failed to query data, err: " + err)
return return
} }
console.log("ResultSet column names: " + resultSet.columnNames) console.log("ResultSet column names: " + resultSet.columnNames)
...@@ -1454,13 +1348,13 @@ Queries data in the database based on specified conditions. This API uses a prom ...@@ -1454,13 +1348,13 @@ Queries data in the database based on specified conditions. This API uses a prom
console.log("ResultSet column names: " + resultSet.columnNames) console.log("ResultSet column names: " + resultSet.columnNames)
console.log("ResultSet column count: " + resultSet.columnCount) console.log("ResultSet column count: " + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.info("Query failed, err: " + err) console.info("Failed to query data, err: " + err)
}) })
``` ```
### query<sup>9+</sup> ### query<sup>9+</sup>
query(predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void query(predicates: DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
Queries data in the database based on specified conditions. This API uses an asynchronous callback to return the result. Queries data in the database based on specified conditions. This API uses an asynchronous callback to return the result.
...@@ -1480,7 +1374,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -1480,7 +1374,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose")
rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
if (err) { if (err) {
console.info("Query failed, err: " + err) console.info("Failed to query data, err: " + err)
return return
} }
console.log("ResultSet column names: " + resultSet.columnNames) console.log("ResultSet column names: " + resultSet.columnNames)
...@@ -1490,7 +1384,7 @@ rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], ...@@ -1490,7 +1384,7 @@ rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
### query<sup>9+</sup> ### query<sup>9+</sup>
query(predicates: dataSharePredicates.DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt; query(predicates: DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
Queries data in the database based on specified conditions. This API uses a promise to return the result. Queries data in the database based on specified conditions. This API uses a promise to return the result.
...@@ -1517,7 +1411,7 @@ promise.then((resultSet) => { ...@@ -1517,7 +1411,7 @@ promise.then((resultSet) => {
console.log("ResultSet column names: " + resultSet.columnNames) console.log("ResultSet column names: " + resultSet.columnNames)
console.log("ResultSet column count: " + resultSet.columnCount) console.log("ResultSet column count: " + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.info("Query failed, err: " + err) console.info("Failed to query data, err: " + err)
}) })
``` ```
...@@ -1540,7 +1434,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1540,7 +1434,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
```js ```js
rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
if (err) { if (err) {
console.info("Query failed, err: " + err) console.info("Failed to query data, err: " + err)
return return
} }
console.log("ResultSet column names: " + resultSet.columnNames) console.log("ResultSet column names: " + resultSet.columnNames)
...@@ -1575,7 +1469,7 @@ promise.then((resultSet) => { ...@@ -1575,7 +1469,7 @@ promise.then((resultSet) => {
console.log("ResultSet column names: " + resultSet.columnNames) console.log("ResultSet column names: " + resultSet.columnNames)
console.log("ResultSet column count: " + resultSet.columnCount) console.log("ResultSet column count: " + resultSet.columnCount)
}).catch((err) => { }).catch((err) => {
console.info("Query failed, err: " + err) console.info("Failed to query data, err: " + err)
}) })
``` ```
...@@ -1600,7 +1494,7 @@ Runs the SQL statement that contains the specified parameters but does not retur ...@@ -1600,7 +1494,7 @@ Runs the SQL statement that contains the specified parameters but does not retur
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)" 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) { rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) {
if (err) { if (err) {
console.info("ExecuteSql failed, err: " + err) console.info("Failed to execute SQL, err: " + err)
return return
} }
console.info('Create table done.') console.info('Create table done.')
...@@ -1634,7 +1528,7 @@ let promise = rdbStore.executeSql(SQL_CREATE_TABLE) ...@@ -1634,7 +1528,7 @@ let promise = rdbStore.executeSql(SQL_CREATE_TABLE)
promise.then(() => { promise.then(() => {
console.info('Create table done.') console.info('Create table done.')
}).catch((err) => { }).catch((err) => {
console.info("ExecuteSql failed, err: " + err) console.info("Failed to execute SQL, err: " + err)
}) })
``` ```
...@@ -1745,10 +1639,10 @@ Backs up the database with the specified name. This API uses an asynchronous cal ...@@ -1745,10 +1639,10 @@ Backs up the database with the specified name. This API uses an asynchronous cal
```js ```js
rdbStore.backup("dbBackup.db", function(err) { rdbStore.backup("dbBackup.db", function(err) {
if (err) { if (err) {
console.info('Backup failed, err: ' + err) console.info('Failed to back up data, err: ' + err)
return return
} }
console.info('Backup success.') console.info('Backup successful.')
}) })
``` ```
...@@ -1774,9 +1668,9 @@ Backs up the database with the specified name. This API uses a promise to return ...@@ -1774,9 +1668,9 @@ Backs up the database with the specified name. This API uses a promise to return
```js ```js
let promiseBackup = rdbStore.backup("dbBackup.db") let promiseBackup = rdbStore.backup("dbBackup.db")
promiseBackup.then(()=>{ promiseBackup.then(()=>{
console.info('Backup success.') console.info('Backup successful.')
}).catch((err)=>{ }).catch((err)=>{
console.info('Backup failed, err: ' + err) console.info('Failed to back up data, err: ' + err)
}) })
``` ```
...@@ -1798,10 +1692,10 @@ Restores a database from a specified database backup file. This API uses an asyn ...@@ -1798,10 +1692,10 @@ Restores a database from a specified database backup file. This API uses an asyn
```js ```js
rdbStore.restore("dbBackup.db", function(err) { rdbStore.restore("dbBackup.db", function(err) {
if (err) { if (err) {
console.info('Restore failed, err: ' + err) console.info('Failed to restore data, err: ' + err)
return return
} }
console.info('Restore success.') console.info('Restore successful.')
}) })
``` ```
...@@ -1827,9 +1721,9 @@ Restores a database from a specified database backup file. This API uses a promi ...@@ -1827,9 +1721,9 @@ Restores a database from a specified database backup file. This API uses a promi
```js ```js
let promiseRestore = rdbStore.restore("dbBackup.db") let promiseRestore = rdbStore.restore("dbBackup.db")
promiseRestore.then(()=>{ promiseRestore.then(()=>{
console.info('Restore success.') console.info('Restore successful.')
}).catch((err)=>{ }).catch((err)=>{
console.info('Restore failed, err: ' + err) console.info('Failed to restore data, err: ' + err)
}) })
``` ```
...@@ -1910,12 +1804,12 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1910,12 +1804,12 @@ Obtains the distributed table name for a remote device based on the local table
**Example** **Example**
```js ```js
rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) {
if (err) { if (err) {
console.info('Failed to obtain distributed table name, err: ' + err) console.info('Failed to obtain DistributedTableName, err: ' + err)
return return
} }
console.info('Obtained distributed table name successfully, tableName=.' + tableName) console.info('Obtained DistributedTableName successfully, tableName=.' + tableName)
}) })
``` ```
...@@ -1943,11 +1837,11 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1943,11 +1837,11 @@ Obtains the distributed table name for a remote device based on the local table
**Example** **Example**
```js ```js
let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") let promise = rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE")
promise.then((tableName) => { promise.then((tableName) => {
console.info('Obtained distributed table name successfully, tableName= ' + tableName) console.info('Obtained DistributedTableName successfully, tableName= ' + tableName)
}).catch((err) => { }).catch((err) => {
console.info('Failed to obtain distributed table name, err: ' + err) console.info('Failed to obtain DistributedTableName, err: ' + err)
}) })
``` ```
...@@ -1970,9 +1864,9 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret ...@@ -1970,9 +1864,9 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret
**Example** **Example**
```js ```js
let predicates = new rdb.RdbPredicates('EMPLOYEE') let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
predicates.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde'])
rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) { rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
if (err) { if (err) {
console.log('Sync failed, err: ' + err) console.log('Sync failed, err: ' + err)
return return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册