From 68ead797a8746fe744840c18cfa81ece51b73891 Mon Sep 17 00:00:00 2001
From: lqqCp3 <1960002614@qq.com>
Date: Fri, 9 Jan 2026 11:38:37 +0800
Subject: [PATCH 1/3] =?UTF-8?q?fix:=20[Issues:=20#IDIOS5]=20=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9watermelondb=E7=9A=84=E6=8C=87=E5=AF=BC=E6=96=87?=
=?UTF-8?q?=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
en/watermelondb.md | 50 ++++++++++++++--------
zh-cn/watermelondb.md | 99 ++++++++++++++++++-------------------------
2 files changed, 73 insertions(+), 76 deletions(-)
diff --git a/en/watermelondb.md b/en/watermelondb.md
index 0c75c67a..6428eb49 100644
--- a/en/watermelondb.md
+++ b/en/watermelondb.md
@@ -10,9 +10,10 @@ Please go to the Releases page of the third-party library to check the matching
information:
+
| Third-party library version | Release information | Supported RN version |
| --------------------------- | ------------------------------------------------------------------------------------------------------ | -------------------- |
-| v0.28.2-rc.1 | [@react-native-ohos/watermelondb Releases](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/tags) | 0.72/0.77 |
+| v0.28.2 | [@react-native-ohos/watermelondb Releases](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/tags) | 0.72/0.77 |
## 1. Installation and Usage
@@ -616,13 +617,16 @@ const styles = StyleSheet.create({
export default SchemaExampleT;
```
-## Manual Link
+## 2.Manual Link
This step is a guide for manually configuring native dependencies.
First, you need to open the HarmonyOS project harmony in the project using DevEco Studio.
### 1.Add overrides field to oh-package.json in the project root directory
+In order to make the project depend on the same version of the RN SDK, you need to add an overrides field to the oh-package.json5 file in the root directory of the project, which points to the version of the RN SDK required by the project. The version to be replaced can be either a specific version number, a version range, or a locally existing HAR package or source code directory.
+For the function of this field, please refer to the official documentation.(https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides):
+
```json
{
"overrides": {
@@ -633,8 +637,10 @@ First, you need to open the HarmonyOS project harmony in the project using DevEc
### 2. There are currently two methods:
-Import via har package (this method will be deprecated after the IDE improves related functions, and it is the preferred method currently);
-Link source code directly.
+There are currently two methods available:
+
+1. Import via HAR package (This method will be deprecated after the IDE-related features are fully implemented, but it is the preferred method at present);
+2. Directly link to the source code.
Method 1: Import via har package (recommended)
@@ -757,7 +763,7 @@ ohpm install
Then compile and run the project.
-## Constraints and Limitations
+## 3.Constraints and Limitations
### Compatibility Support
@@ -766,6 +772,8 @@ The content of this document has been verified based on the following versions
1. RNOH:0.72.90; SDK:HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM:NEXT.0.0.105;
2. RNOH:0.77.18; SDK:HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM:6.0.0.112;
+### Permission Requirements
+
#### Add the reason for applying for the above permissions in the entry directory
Open `entry/src/main/resources/base/element/string.json`,add:
@@ -790,7 +798,7 @@ Open `entry/src/main/resources/base/element/string.json`,add:
}
```
-## Properties
+## 4.Properties
> [!TIP] "Platform"This column shows which platforms the property supports in the original third-party library。
@@ -798,6 +806,7 @@ Open `entry/src/main/resources/base/element/string.json`,add:
**Collection class**
+
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| ------------------------- | ------------------------------------------------------------------------------ | -------- | -------- | ----------- | ----------------- |
| db | Get the reference to the database instance that this collection belongs to | function | no | iOS/Android | yes |
@@ -806,6 +815,8 @@ Open `entry/src/main/resources/base/element/string.json`,add:
| create | Create and save new records in the collection | function | yes | iOS/Android | yes |
| prepareCreate | Pre - create a record object without immediately persisting it to the database | function | yes | iOS/Android | yes |
| prepareCreateFromDirtyRaw | Pre - create a record object from raw unvalidated data | function | yes | iOS/Android | yes |
+| disposableFromDirtyRaw | Create a one - time temporary record based on raw dirty data | function | yes | iOS/Android | yes |
+| table | Get the name of the database table corresponding to this collection | function | no | iOS/Android | yes |
| \_fetchQuery | Execute the SQL query statement and return the complete result set | function | no | iOS/Android | no |
| \_fetchIds | Get the list of all record IDs that match the query criteria | function | no | iOS/Android | no |
| \_fetchCount | Count the total number of records that satisfy the query criteria | function | no | iOS/Android | no |
@@ -813,13 +824,12 @@ Open `entry/src/main/resources/base/element/string.json`,add:
| \_fetchRecord | Get the complete data content of a single record | function | no | iOS/Android | no |
| \_applyChangesToCache | Apply the data changes to the in-memory cache system | function | no | iOS/Android | no |
| \_notify | Notify all registered observers that the data has changed | function | no | iOS/Android | no |
-| disposableFromDirtyRaw | Create a one - time temporary record based on raw dirty data | function | yes | iOS/Android | yes |
-| table | Get the name of the database table corresponding to this collection | function | no | iOS/Android | yes |
| schema | Get the data table structure definition corresponding to this collection | function | no | iOS/Android | yes |
| experimentalSubscribe | Subscribe to collection - level data change notifications | function | yes | iOS/Android | yes |
**Database class**
+
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| -------------------------- | -------------------------------------------------------------------------------- | -------- | -------- | ----------- | ----------------- |
| get<T extends Model> | Retrieve a specific record from the database according to the model class and ID | function | yes | iOS/Android | yes |
@@ -836,6 +846,7 @@ Open `entry/src/main/resources/base/element/string.json`,add:
**Relation class**
+
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| ------------- | ------------------------------------------------------------------------------ | -------- | -------- | ----------- | ----------------- |
| get id | Get the unique identifier of the associated target model | function | no | iOS/Android | yes |
@@ -847,6 +858,7 @@ Open `entry/src/main/resources/base/element/string.json`,add:
**Model class**
+
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| --------------------------------------------- | ----------------------------------------------------------------------------------- | -------- | -------- | ----------- | ----------------- |
| associations | Define the association relationship mapping between the model and other data tables | function | no | iOS/Android | yes |
@@ -885,6 +897,7 @@ Open `entry/src/main/resources/base/element/string.json`,add:
**Query class**
+
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| -------------------------------- | ---------------------------------------------------- | -------- | -------- | ----------- | ----------------- |
| pipe<T> | Perform chain conversion operations on query results | function | no | iOS/Android | yes |
@@ -911,6 +924,7 @@ Open `entry/src/main/resources/base/element/string.json`,add:
**Schema class**
+
| Name | Description | Type | Required | Platform | HarmonyOS Support |
| -------------------------------- | ------------------------------------------------------------------- | -------- | -------- | ----------- | ----------------- |
| tableName<T extends Model> | Define the name of the database table | function | yes | iOS/Android | yes |
@@ -919,18 +933,18 @@ Open `entry/src/main/resources/base/element/string.json`,add:
| validateColumnsSchema | Verify the validity of the field schema definition | function | yes | iOS/Android | yes |
| tableSchema | Define the structure and field configuration of a single data table | function | yes | iOS/Android | yes |
-## Pending Issues
+## 5.Pending Issues
-- [ ] \_fetchQuery Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
-- [ ] \_fetchIds Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
-- [ ] \_fetchCount Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
-- [ ] \_unsafeFetchRaw Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
-- [ ] \_fetchRecord Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
-- [ ] \_applyChangesToCache Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
-- [ ] \_notify Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
+- [ ] \_fetchQuery Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
+- [ ] \_fetchIds Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
+- [ ] \_fetchCount Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
+- [ ] \_unsafeFetchRaw Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
+- [ ] \_fetchRecord Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
+- [ ] \_applyChangesToCache Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
+- [ ] \_notify Some parameters of the interface are not supported on HarmonyOS. As an underlying method provided for other modules, it cannot be called directly. [issue#2](https://gitcode.com/OpenHarmony-RN/rntpc_watermelondb/issues/2)
-## Others
+## 6.Others
-## Open Source License
+## 7.Open Source License
This project is based on [The MIT License (MIT)](https://github.com/Nozbe/WatermelonDB/blob/master/LICENSE) ,Feel free to enjoy and contribute to the open source project。
diff --git a/zh-cn/watermelondb.md b/zh-cn/watermelondb.md
index 4c515492..1f643bd6 100644
--- a/zh-cn/watermelondb.md
+++ b/zh-cn/watermelondb.md
@@ -33,6 +33,8 @@ yarn add @react-native-ohos/watermelondb
> [!WARNING] 使用时 import 的库名不变。
+### watermelondb example
+
```js
// jsi: false
import React, { useState } from 'react';
@@ -130,39 +132,34 @@ const validateUserColumns = () => {
return results;
};
-// ===================== 初始化数据库改为接收表类型参数(核心修改)=====================
-// 初始化数据库(新增tableType参数)
const initializeDatabase = async (tableType) => {
- // 根据表类型获取对应表结构
const targetTableSchema = tableSchemaMap[tableType] || userTableSchema;
const adapter = new SQLiteAdapter({
- dbName: `watermelon_${tableType}_db`, // 不同表使用不同数据库名
+ dbName: `watermelon_${tableType}_db`,
schema: getAppDatabaseSchema(targetTableSchema),
jsi: false,
migrations: schemaMigrations({ migrations: [] }),
});
- await adapter.initializingPromise; // 等待适配器初始化
+ await adapter.initializingPromise;
return new Database({ adapter, modelClasses: [] });
};
const SchemaExample = () => {
const [validationResult, setValidationResult] = useState(null);
const [createResult, setCreateResult] = useState(null);
- const [database, setDatabase] = useState({}); // 修改为对象存储不同表的数据库实例
+ const [database, setDatabase] = useState({});
+
- // 验证字段结构(保留原有)
const handleValidateSchema = () => {
const results = validateUserColumns();
setValidationResult(results);
setCreateResult(null);
};
- // ===================== 修改创建方法为接收表类型参数(核心修改)=====================
- // 创建数据库表(新增tableType参数)
const handleCreateTables = async (tableType) => {
try {
- // 检查该表是否已创建
+
if (database[tableType]) {
const tableName = tableSchemaMap[tableType]?.name || userTable;
setCreateResult({
@@ -174,7 +171,7 @@ const SchemaExample = () => {
}
const db = await initializeDatabase(tableType);
- // 存储对应表类型的数据库实例
+
setDatabase({ ...database, [tableType]: db });
const tableName = tableSchemaMap[tableType]?.name || userTable;
setCreateResult({
@@ -191,11 +188,11 @@ const SchemaExample = () => {
}
};
- // 清空页面状态(保留原有)
+
const handleClear = () => {
setValidationResult(null);
setCreateResult(null);
- setDatabase({}); // 重置为空对象
+ setDatabase({});
};
return (
@@ -203,25 +200,24 @@ const SchemaExample = () => {
WatermelonDB 表创建示例
- {/* 为每个按钮绑定不同的tableType参数 */}
- {/* 字段验证结果展示(完全保留原有) */}
+
{validationResult && (
字段验证结果
@@ -259,7 +255,7 @@ const SchemaExample = () => {
)}
- {/* 创建结果展示(完全保留原有) */}
+
{createResult && (
{
);
};
-// ===================== 样式完全保留原有 =====================
+
const styles = StyleSheet.create({
container: {
flex: 1,
@@ -351,18 +347,16 @@ import { Database } from '@nozbe/watermelondb';
import SQLiteAdapter from '@nozbe/watermelondb/adapters/sqlite';
import { schemaMigrations } from '@nozbe/watermelondb/Schema/migrations';
-// ===================== 原有表定义(保留)=====================
-// 使用 tableName 定义表名(带类型)
+
const userTable = tableName('users');
-// 使用 columnName 定义字段名
+
const userColumns = {
name: columnName('name'),
email: columnName('email'),
age: columnName('age'),
};
-// 定义用户表结构(使用 tableSchema)
const userTableSchema = tableSchema({
name: userTable,
columns: [
@@ -372,8 +366,7 @@ const userTableSchema = tableSchema({
],
});
-// ===================== 新增4个不同表的定义(核心新增)=====================
-// 1. 用户信息表(user_info)- 对应columnName按钮
+
const userInfoTable = tableName('user_info');
const userInfoColumns = {
userId: columnName('user_id'),
@@ -389,7 +382,7 @@ const userInfoTableSchema = tableSchema({
],
});
-// 2. 订单表(order)- 对应tableSchema按钮
+
const orderTable = tableName('order');
const orderTableSchema = tableSchema({
name: orderTable,
@@ -401,7 +394,7 @@ const orderTableSchema = tableSchema({
],
});
-// 3. 商品表(product)- 对应appSchema按钮
+
const productTable = tableName('product');
const productTableSchema = tableSchema({
name: productTable,
@@ -412,7 +405,7 @@ const productTableSchema = tableSchema({
],
});
-// 表结构映射 - 用于根据类型获取对应表
+
const tableSchemaMap = {
tableName: userTableSchema,
columnName: userInfoTableSchema,
@@ -420,8 +413,7 @@ const tableSchemaMap = {
appSchema: productTableSchema,
};
-// ===================== 原有应用schema改为动态生成(仅修改此处)=====================
-// 动态生成appSchema(根据传入的表结构)
+
const getAppDatabaseSchema = tableSchema => {
return appSchema({
version: 1,
@@ -429,10 +421,10 @@ const getAppDatabaseSchema = tableSchema => {
});
};
-// 验证字段定义(使用 validateColumnSchema)
+
const validateUserColumns = () => {
const results = [];
- // 修复原有错误:columnArray → columns
+
userTableSchema.columnArray.forEach(column => {
try {
validateColumnSchema(column);
@@ -445,39 +437,36 @@ const validateUserColumns = () => {
return results;
};
-// ===================== 初始化数据库改为接收表类型参数(核心修改)=====================
-// 初始化数据库(新增tableType参数)
+
const initializeDatabase = tableType => {
- // 根据表类型获取对应表结构
+
const targetTableSchema = tableSchemaMap[tableType] || userTableSchema;
const adapter = new SQLiteAdapter({
- dbName: `watermelonT_${tableType}_db`, // 不同表使用不同数据库名
+ dbName: `watermelonT_${tableType}_db`,
schema: getAppDatabaseSchema(targetTableSchema),
jsi: true,
migrations: schemaMigrations({ migrations: [] }),
});
- adapter.initializingPromise; // 等待适配器初始化
+ adapter.initializingPromise;
return new Database({ adapter, modelClasses: [] });
};
const SchemaExampleT = () => {
const [validationResult, setValidationResult] = useState(null);
const [createResult, setCreateResult] = useState(null);
- const [database, setDatabase] = useState({}); // 修改为对象存储不同表的数据库实例
+ const [database, setDatabase] = useState({});
+
- // 验证字段结构(保留原有)
const handleValidateSchema = () => {
const results = validateUserColumns();
setValidationResult(results);
setCreateResult(null);
};
- // ===================== 修改创建方法为接收表类型参数(核心修改)=====================
- // 创建数据库表(新增tableType参数)
+
const handleCreateTables = tableType => {
try {
- // 检查该表是否已创建
if (database[tableType]) {
const tableName = tableSchemaMap[tableType]?.name || userTable;
setCreateResult({
@@ -489,7 +478,6 @@ const SchemaExampleT = () => {
}
const db = initializeDatabase(tableType);
- // 存储对应表类型的数据库实例
setDatabase({ ...database, [tableType]: db });
const tableName = tableSchemaMap[tableType]?.name || userTable;
setCreateResult({
@@ -506,11 +494,10 @@ const SchemaExampleT = () => {
}
};
- // 清空页面状态(保留原有)
const handleClear = () => {
setValidationResult(null);
setCreateResult(null);
- setDatabase({}); // 重置为空对象
+ setDatabase({});
};
return (
@@ -518,25 +505,24 @@ const SchemaExampleT = () => {
WatermelonDB 表创建示例
- {/* 为每个按钮绑定不同的tableType参数 */}
handleCreateTables('tableName')} // 新增参数
+ onPress={() => handleCreateTables('tableName')}
color="#4CAF50"
/>
handleCreateTables('columnName')} // 新增参数
+ onPress={() => handleCreateTables('columnName')}
color="#4CAF50"
/>
handleCreateTables('tableSchema')} // 新增参数
+ onPress={() => handleCreateTables('tableSchema')}
color="#4CAF50"
/>
handleCreateTables('appSchema')} // 新增参数
+ onPress={() => handleCreateTables('appSchema')}
color="#4CAF50"
/>
{
- {/* 字段验证结果展示(完全保留原有) */}
{validationResult && (
字段验证结果
@@ -574,7 +559,6 @@ const SchemaExampleT = () => {
)}
- {/* 创建结果展示(完全保留原有) */}
{createResult && (
{
);
};
-// ===================== 样式完全保留原有 =====================
const styles = StyleSheet.create({
container: {
flex: 1,
@@ -651,7 +634,7 @@ const styles = StyleSheet.create({
export default SchemaExampleT;
```
-## Manual Link
+## 2.Manual Link
此步骤为手动配置原生依赖项的指导。
@@ -799,7 +782,7 @@ ohpm install
然后编译、运行即可。
-## 约束与限制
+## 3.约束与限制
### 兼容性
@@ -834,7 +817,7 @@ ohpm install
}
```
-## 属性
+## 4.属性
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
--
Gitee
From 77a577db28c5fe40f624295abcc5198102a5cfaf Mon Sep 17 00:00:00 2001
From: lqqCp3 <1960002614@qq.com>
Date: Fri, 9 Jan 2026 11:55:38 +0800
Subject: [PATCH 2/3] =?UTF-8?q?docs:=20[Issues:#IDIOV3]=20=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9watermelondb=E7=9A=84=E6=8C=87=E5=AF=BC=E6=96=87?=
=?UTF-8?q?=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
en/watermelondb.md | 2 +-
zh-cn/watermelondb.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/en/watermelondb.md b/en/watermelondb.md
index 6428eb49..4ea40844 100644
--- a/en/watermelondb.md
+++ b/en/watermelondb.md
@@ -734,7 +734,7 @@ std::vector> PackageProvider::getPackages(
### 4. Import the watermelondb module on the ArkTS side
-open `entry/src/main/ets/RNPackagesFactory.ts`,add:
+open `entry/src/main/ets/RNPackagesFactory.ets`,add:
```diff
...
diff --git a/zh-cn/watermelondb.md b/zh-cn/watermelondb.md
index 1f643bd6..38a2150b 100644
--- a/zh-cn/watermelondb.md
+++ b/zh-cn/watermelondb.md
@@ -753,7 +753,7 @@ std::vector> PackageProvider::getPackages(
### 4. 在 ArkTs 侧引入 watermelondb 组件
-找到 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
+找到 `entry/src/main/ets/RNPackagesFactory.ets`,添加:
```diff
...
--
Gitee
From fea21d0801f73c51a7b2cbc6d891051bdfff0845 Mon Sep 17 00:00:00 2001
From: lqqCp3 <1960002614@qq.com>
Date: Fri, 9 Jan 2026 14:32:53 +0800
Subject: [PATCH 3/3] =?UTF-8?q?docs:=20[Issues:=20#IDE3MY]=20=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9watermelondb=E7=9A=84=E6=8C=87=E5=AF=BC=E6=96=87?=
=?UTF-8?q?=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
en/watermelondb.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/en/watermelondb.md b/en/watermelondb.md
index 4ea40844..2bdb8d40 100644
--- a/en/watermelondb.md
+++ b/en/watermelondb.md
@@ -635,7 +635,7 @@ For the function of this field, please refer to the official documentation.(http
}
```
-### 2. There are currently two methods:
+### 2. Integrate native code:
There are currently two methods available:
--
Gitee