提交 0731d7ff 编写于 作者: L liusaimei

Share相关使用说明文档示例代码ArxTs规范整改

Signed-off-by: Nliusaimei <liusaimei@huawei.com>
上级 a47b52f8
...@@ -64,6 +64,8 @@ ...@@ -64,6 +64,8 @@
import Extension from '@ohos.application.DataShareExtensionAbility'; import Extension from '@ohos.application.DataShareExtensionAbility';
import rdb from '@ohos.data.relationalStore'; import rdb from '@ohos.data.relationalStore';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import relationalStore from '@ohos.data.relationalStore';
import Want from '@ohos.app.ability.Want';
``` ```
4. 数据提供方的业务实现由开发者自定义。例如可以通过数据库、读写文件或访问网络等各方式实现数据提供方的数据存储。 4. 数据提供方的业务实现由开发者自定义。例如可以通过数据库、读写文件或访问网络等各方式实现数据提供方的数据存储。
...@@ -75,20 +77,20 @@ ...@@ -75,20 +77,20 @@
+ TBL_NAME + TBL_NAME
+ ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, isStudent BOOLEAN, Binary BINARY)'; + ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, isStudent BOOLEAN, Binary BINARY)';
let rdbStore; let rdbStore: relationalStore.RdbStore;
let result; let result: string;
export default class DataShareExtAbility extends Extension { export default class DataShareExtAbility extends Extension {
private rdbStore_; private rdbStore_: relationalStore.RdbStore;
// 重写onCreate接口 // 重写onCreate接口
onCreate(want, callback) { onCreate(want: Want, callback: Function) {
result = this.context.cacheDir + '/datashare.txt'; result = this.context.cacheDir + '/datashare.txt';
// 业务实现使用RDB // 业务实现使用RDB
rdb.getRdbStore(this.context, { rdb.getRdbStore(this.context, {
name: DB_NAME, name: DB_NAME,
securityLevel: rdb.SecurityLevel.S1 securityLevel: rdb.SecurityLevel.S1
}, function (err, data) { }, (err, data) => {
rdbStore = data; rdbStore = data;
rdbStore.executeSql(DDL_TBL_CREATE, [], (err) => { rdbStore.executeSql(DDL_TBL_CREATE, [], (err) => {
console.info(`DataShareExtAbility onCreate, executeSql done err:${err}`); console.info(`DataShareExtAbility onCreate, executeSql done err:${err}`);
...@@ -100,7 +102,7 @@ ...@@ -100,7 +102,7 @@
} }
// 重写query接口 // 重写query接口
query(uri, predicates, columns, callback) { query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: Function) {
if (predicates === null || predicates === undefined) { if (predicates === null || predicates === undefined) {
console.info('invalid predicates'); console.info('invalid predicates');
} }
...@@ -188,6 +190,8 @@ ...@@ -188,6 +190,8 @@
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import dataShare from '@ohos.data.dataShare'; import dataShare from '@ohos.data.dataShare';
import dataSharePredicates from '@ohos.data.dataSharePredicates'; import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { ValuesBucket } from '@ohos.data.ValuesBucket'
import window from '@ohos.window';
``` ```
2. 定义与数据提供方通信的URI字符串。 2. 定义与数据提供方通信的URI字符串。
...@@ -200,11 +204,11 @@ ...@@ -200,11 +204,11 @@
3. 创建工具接口类对象。 3. 创建工具接口类对象。
```js ```js
let dsHelper; let dsHelper: dataShare.DataShareHelper;
let abilityContext; let abilityContext: Context;
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage: window.WindowStage) {
abilityContext = this.context; abilityContext = this.context;
dataShare.createDataShareHelper(abilityContext, dseUri, (err, data) => { dataShare.createDataShareHelper(abilityContext, dseUri, (err, data) => {
dsHelper = data; dsHelper = data;
...@@ -217,8 +221,19 @@ ...@@ -217,8 +221,19 @@
```js ```js
// 构建一条数据 // 构建一条数据
let valuesBucket = { 'name': 'ZhangSan', 'age': 21, 'isStudent': false, 'Binary': new Uint8Array([1, 2, 3]) }; let key1 = 'name';
let updateBucket = { 'name': 'LiSi', 'age': 18, 'isStudent': true, 'Binary': new Uint8Array([1, 2, 3]) }; let key2 = 'age';
let key3 = 'isStudent';
let key4 = 'Binary';
let valueName1 = 'ZhangSan';
let valueName2 = 'LiSi';
let valueAge1 = 21;
let valueAge2 = 18;
let valueIsStudent1 = false;
let valueIsStudent2 = true;
let valueBinary = new Uint8Array([1, 2, 3]);
let valuesBucket: ValuesBucket = { key1: valueName1, key2: valueAge1, key3: valueIsStudent1, key4: valueBinary };
let updateBucket: ValuesBucket = { key1: valueName2, key2: valueAge2, key3: valueIsStudent2, key4: valueBinary };
let predicates = new dataSharePredicates.DataSharePredicates(); let predicates = new dataSharePredicates.DataSharePredicates();
let valArray = ['*']; let valArray = ['*'];
// 插入一条数据 // 插入一条数据
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册