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

!2642 内源演习问题代码修改:Docs

Merge pull request !2642 from Cap_W/master
......@@ -84,7 +84,10 @@
读取指定文件,将数据加载到Storage实例,用于数据操作。
```
var context = featureAbility.getContext()
var path = await context.getFilesDir()
context.getFilesDir().then(() => {
console.info("======================>getFilesDirPromsie====================>");
});
let promise = dataStorage.getStorage(path + '/mystore')
```
......
......@@ -17,7 +17,7 @@
| -------- | -------- |
|getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number,&nbsp;callback:&nbsp;AsyncCallback&lt;RdbStore&gt;):&nbsp;void | 获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以callback形式返回。<br/>-&nbsp;config:与此RDB存储相关的数据库配置。<br/>-&nbsp;version:数据库版本。<br/>-&nbsp;callback:指定callback回调函数。返回一个RdbStore。 |
|getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number):&nbsp;Promise&lt;RdbStore&gt; | 获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以Promise形式返回。<br/>-&nbsp;config:与此RDB存储相关的数据库配置。<br/>-&nbsp;version:数据库版本。 |
|deleteRdbStore(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void | 删除数据库,结果以callback形式返回。<br/>-&nbsp;name:数据库名称。<br/>-&nbsp;callback:指定callback回调函数。如果数据库已删除,则为true;否则返回false。 |
|deleteRdbStore(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void | 删除数据库,结果以callback形式返回。<br/>-&nbsp;name:数据库名称。<br/>-&nbsp;callback:指定callback回调函数。 |
| deleteRdbStore(name:&nbsp;string):&nbsp;Promise&lt;void&gt; | 使用指定的数据库文件配置删除数据库,结果以Promise形式返回。<br/>-&nbsp;name:数据库名称。 |
### 数据库的增删改查
......@@ -201,9 +201,10 @@
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {name: "rdbstore.db",}
let rdbStore = await data_rdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST);
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(SQL_CREATE_TABLE)
console.info('create table done.')
})
```
2. 插入数据。
......@@ -228,16 +229,16 @@
```
let predicates = new data_rdb.RdbPredicates("test");
predicates.equalTo("name", "Tom")
let resultSet = await rdbStore.query(predicates)
resultSet.goToFirstRow()
const id = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name = await resultSet.getString(resultSet.getColumnIndex("name"))
const age = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
resultSet.close()
let promisequery = rdbStore.query(predicates)
promisequery.then((resultSet) => {
resultSet.goToFirstRow()
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
resultSet.close()
})
```
4. 设置分布式同步表。
......
......@@ -729,8 +729,31 @@ groupBy(fields: Array&lt;string&gt;): DataAbilityPredicates
predicates.groupBy(["AGE", "NAME"])
```
### indexedBy
indexedBy(field: string): DataAbilityPredicates
配置谓词以指定索引列。
- 参数:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| indexName | string | 是 | 索引列的名称。 |
- 返回值:
| 类型 | 说明 |
| -------- | -------- |
| [DataAbilityPredicates](#dataabilitypredicates) | 返回具有指定索引列的谓词。 |
- 示例:
```
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE")
predicates.indexedBy("SALARY_INDEX")
```
### in
......
......@@ -14,7 +14,7 @@ import data_rdb from '@ohos.data.rdb'
## data_rdb.getRdbStore
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
获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以callback形式返回。
......@@ -23,7 +23,7 @@ getRdbStore(context?: Context, config: StoreConfig, version: number, callback: A
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | | 应用程序或功能的上下文 |
| context<sup>8+</sup> | Context | | 应用程序或功能的上下文 |
| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 |
| version | number | 是 | 数据库版本。 |
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | 是 | 指定callback回调函数。返回一个RdbStore。 |
......@@ -57,7 +57,7 @@ export default class MainAbility extends Ability {
## 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;
获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以Promise形式返回。
......@@ -67,7 +67,7 @@ getRdbStore(context?: Context, config: StoreConfig, version: number): Promise&lt
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | | 应用程序或功能的上下文 |
| context<sup>8+</sup> | Context | | 应用程序或功能的上下文 |
| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 |
| version | number | 是 | 数据库版本。 |
......@@ -120,7 +120,7 @@ export default class MainAbility extends Ability {
## data_rdb.deleteRdbStore
deleteRdbStore(context?: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
删除数据库,结果以callback形式返回。
......@@ -129,9 +129,9 @@ deleteRdbStore(context?: Context, name: string, callback: AsyncCallback&lt;void&
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | | 应用程序或功能的上下文 |
| context<sup>8+</sup> | Context | | 应用程序或功能的上下文 |
| name | string | 是 | 数据库名称。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 指定callback回调函数。如果数据库已删除,则为true;否则返回false。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 指定callback回调函数。 |
**示例**
```
......@@ -155,7 +155,7 @@ export default class MainAbility extends Ability {
## data_rdb.deleteRdbStore
deleteRdbStore(context?: Context, name: string): Promise&lt;void&gt;
deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
使用指定的数据库文件配置删除数据库,结果以Promise形式返回。
......@@ -164,13 +164,13 @@ deleteRdbStore(context?: Context, name: string): Promise&lt;void&gt;
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| context<sup>8+</sup> | Context | | 应用程序或功能的上下文 |
| context<sup>8+</sup> | Context | | 应用程序或功能的上下文 |
| name | string | 是 | 数据库名称。 |
**返回值**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 指定Promise回调函数。如果数据库已删除,则为true;否则返回false。 |
| Promise&lt;void&gt; | 指定Promise回调函数。 |
**示例**
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册