• Home
Name Date Size #Lines LOC

..--

AppScope/22-Oct-2025-3633

entry/22-Oct-2025-4,3884,025

hvigor/22-Oct-2025-77

screenshots/devices/22-Oct-2025-

.gitignoreD22-Oct-2025181 1313

README.mdD22-Oct-20251.3 KiB2613

README_zh.mdD22-Oct-20256.3 KiB8066

build-profile.json5D22-Oct-20251.1 KiB4442

hvigorfile.tsD22-Oct-2025158 21

hvigorwD22-Oct-20252 KiB6228

hvigorw.batD22-Oct-20252 KiB7356

oh-package.json5D22-Oct-2025211 1211

ohosTest.mdD22-Oct-20251.6 KiB1412

README.md

1# Data Management - Distributed Relational Database
2
3### Introduction
4
5This sample shows how to add, delete, modify, query, and synchronize data in the distributed relational database with extended TypeScript (eTS).
6
7### Usage
8
91. After starting the app, touch **+** to add a contact.
10
112. Touch a contact. On the edit page displayed, you can modify the contact information.
12
133. Touch and hold a contact. The **Select All**, **Cancel**, **Delete**, and **Quit** buttons are displayed at the bottom of the screen. You can touch **Quit** to quit the current page.
14
154. Touch the **More** button in the upper right corner, touch **Connect device**, and select the device with data to be synchronized. After the connection is set up, data is synchronized to the connected device.
16
175. Touch the **More** button in the upper right corner and touch **Settings**. On the page displayed, you can set the data synchronization mode, which can be **Automatic synchronization** or **Manual synchronization**.
18
19### Constraints
20
21- Two networked devices are required to test the data synchronization function.
22
23- This sample can run only on standard-system devices, and API version 8 or later are supported.
24
25- This sample requires DevEco Studio 3.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022) to compile and run.
26

README_zh.md

1# 分布式关系型数据库
2
3### 介绍
4
5本示例使用[@ohos.data.relationalStore](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-relationalStore.md) 接口和[@ohos.distributedDeviceManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-distributedservice-kit/js-apis-distributedDeviceManager.md) 接口展示了在eTS中分布式关系型数据库的使用,在增、删、改、查的基本操作外,还包括分布式数据库的数据同步功能。
6
7### 效果预览
8| 首页                                     | 编辑联系人                                  |设置| 数据同步                                   |
9|----------------------------------------|----------------------------------------|-------|----------------------------------------|
10| ![home](screenshots/devices/home.jpeg) | ![home](screenshots/devices/edit.jpeg) |![home](screenshots/devices/setting.png)| ![home](screenshots/devices/sync.jpeg) |
11
12使用说明:
131. 启动应用后点击“**+**”按钮可以添加联系人;
142. 点击联系人可以进入编辑界面编辑联系人信息;
153. 长按联系人进入多选状态,底部有“**全选**”、“**取消**”、“**删除**”、“**退出**”按钮,点击退出可以退出多选状态;
164. 点击右上角更多按钮,点击“**连接设备**”,选择要同步数据的设备,连接成功后可以开始将本端数据同步到对端;
175. 点击右上角更多按钮,点击“**设置**”可以进入设置界面设置数据同步方式,包括自动同步和手动同步。
18
19### 工程目录
20```
21entry/src/main/ets/
22|---common
23|   |---BasicDataSource.ets                     // 联系人列表懒加载数据
24|   |---BottomBtn.ets                           //
25|   |---ContactItem.ets                         // 联系人
26|   |---DataChangeDetailDialog                  // 联系人变更通知
27|   |---DeviceDialog.ets                        // 设备列表
28|   |---PopupMenu.ets                           // 设备选择
29|   |---QueryItem.ets                           // 联系人详情
30|   |---SearchBar.ets                           // 搜索
31|   |---TitleBar.ets                            // title
32|---model
33|   |---Contact.ets                             // 联系人数据
34|   |---LiteStore.ets                           // 轻量级数据操作
35|   |---Logger.ts                               // 日志工具
36|   |---RdbConst.ets                            // 数据库参数常量集
37|   |---RdbModel.ets                            // 分布式工具
38|   |---RemoteDeviceModel.ets                   // 分布式设备管理
39|---pages
40|   |---ContactEdit.ets                         // 编辑联系人
41|   |---Index.ets                               // 首页
42|   |---SearchPage.ets                          // 搜索设备
43|   |---Settings.ets                            // 设置
44```
45### 具体实现
46+ 数据库的增、删、改、查操作都在RdbModel中,源码参考[RdbModel.ets](entry/src/main/ets/model/RdbModel.ets):
47    + 数据库操作:使用[@ohos.data.relationalStore](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-relationalStore.md) 接口的getRdbStore获得一个相关的操作型关系数据库RdbStore,通过这个RdbStore调用相关接口进行增删改查,RdbStore.insert数据插入,RdbStore.delete数据删除,RdbStore.update更新数据,RdbStore.query根据条件查询数据;
48    + 数据同步:RdbStore.on注册数据库观察者,使用RdbStore.obtainDistributedTableName根据本地表名获取指定远程设备的分布式表名,数据发生变动时通过RdbStore.sync同步数据,不需要用时删除指定观察者使用RdbStore.off49+ 连接设备管理在RemoteDeviceModel中,源码参考[RemoteDeviceModel.ets](entry/src/main/ets/model/RemoteDeviceModel.ets):
50    + 设备同步:设备同步数据需要[ohos.permission.DISTRIBUTED_DATASYNC](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissiondistributed_datasync) 权限,在页面渲染前申请权限,源码参考[Index.ets](entry/src/main/ets/pages/Index.ets),使用[@ohos.distributedDeviceManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-distributedservice-kit/js-apis-distributedDeviceManager.md) 接口,首先通过createDeviceManager创建设备管理器实例,然后通过getTrustedDeviceListSync同步获取所有可信设备列表;
51    + 设备连接:首先通过on方法注册设备状态,例如发现设备,设备连接失败,然后通过startDeviceDiscovery方法发现周边设备,然后选择连接设备,再用[startAbility](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md) 启动连接设备的应用。
52
53### 相关权限
54
55[ohos.permission.DISTRIBUTED_DATASYNC](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissiondistributed_datasync)
56
57允许系统应用获取分布式设备的认证组网能力:[ohos.permission.ACCESS_SERVICE_DM](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccess_service_dm)
58
59### 依赖
60
61不涉及。
62
63### 约束与限制
64
651. 本示例的同步功能需要两台设备组网后测试;
662. 本示例仅支持标准系统上运行,支持设备:RK3568。
673. 本示例为Stage模型,支持API12版本SDK,SDK版本号(API Version 12 Release),镜像版本号(5.0 Release)
684. 本示例需要使用DevEco Studio 版本号(4.1 Release)及以上版本才可编译运行。
695. 本示例需要使用@ohos.distributedDeviceManager系统权限的系统接口。使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)70
71### 下载
72
73如需单独下载本工程,执行如下命令:
74```
75git init
76git config core.sparsecheckout true
77echo code/SuperFeature/DistributedAppDev/DistributedRdb/ > .git/info/sparse-checkout
78git remote add origin https://gitee.com/openharmony/applications_app_samples.git
79git pull origin master
80```