tangbao-he-db-helper 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/db-crud.html +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ MyBatis-style database helper for Node-RED with MySQL and SQLite support.
|
|
|
29
29
|
|
|
30
30
|
- Node.js >= 18.0
|
|
31
31
|
- Node-RED >= 4.0.0
|
|
32
|
+
- **For SQLite support**: `better-sqlite3` >= 12.0.0 (installed separately)
|
|
32
33
|
|
|
33
34
|
## Installation
|
|
34
35
|
|
|
@@ -41,7 +42,7 @@ Or install from a local `.tgz` file:
|
|
|
41
42
|
|
|
42
43
|
```bash
|
|
43
44
|
cd ~/.node-red
|
|
44
|
-
npm install /path/to/tangbao-he-db-helper
|
|
45
|
+
npm install /path/to/tangbao-he-db-helper-*.tgz
|
|
45
46
|
```
|
|
46
47
|
|
|
47
48
|
**For SQLite support, also install:**
|
|
@@ -72,7 +73,8 @@ When you select a driver in the configuration panel, the available fields automa
|
|
|
72
73
|
- **SQLite**: Database File Path only (e.g., `/data/mydb.db` or `./mydb.db`)
|
|
73
74
|
|
|
74
75
|
**MySQL Settings:**
|
|
75
|
-
- Host, Port, Database
|
|
76
|
+
- Host, Port, Database
|
|
77
|
+
- User / Password (stored in Node-RED credentials, encrypted at rest)
|
|
76
78
|
- Charset (default: `UTF8_GENERAL_CI`)
|
|
77
79
|
- Timezone (default: `local`)
|
|
78
80
|
- Connection Pool Limit (default: `50`)
|
|
@@ -163,6 +165,8 @@ Pre-built CRUD operations. No SQL writing needed.
|
|
|
163
165
|
**SQLite Upsert Note:**
|
|
164
166
|
SQLite uses `ON CONFLICT(id) DO UPDATE SET col = excluded.col` instead of MySQL's `ON DUPLICATE KEY UPDATE col = VALUES(col)`. The CRUD node automatically selects the correct syntax based on your configured driver.
|
|
165
167
|
|
|
168
|
+
> **Important:** For `upsertBatch` to work with SQLite, the target table must have a **PRIMARY KEY** or **UNIQUE** constraint on the `idColumn`. Otherwise SQLite will raise a conflict resolution error.
|
|
169
|
+
|
|
166
170
|
**Array to IN:**
|
|
167
171
|
|
|
168
172
|
For `selectList`, `selectOne`, `selectCount`, and `selectPage`, array values are automatically converted to `IN` conditions:
|
|
@@ -250,10 +254,22 @@ msg.params = { userName: "Alice", userAge: 20 };
|
|
|
250
254
|
|
|
251
255
|
2. Restart Node-RED.
|
|
252
256
|
|
|
253
|
-
3. Create a `tangbao-db-config` node, select **SQLite** as the driver, and enter the database file path (e.g., `./data.db`).
|
|
257
|
+
3. Create a `tangbao-db-config` node, select **SQLite** as the driver, and enter the database file path (e.g., `./data.db` or an absolute path like `/data/mydb.db`).
|
|
254
258
|
|
|
255
259
|
4. Use `tangbao-db-crud` or `tangbao-db-query` / `tangbao-db-execute` as usual. All CRUD operations work the same way.
|
|
256
260
|
|
|
261
|
+
### SQLite vs MySQL Quick Reference
|
|
262
|
+
|
|
263
|
+
| Feature | MySQL | SQLite |
|
|
264
|
+
|---------|-------|--------|
|
|
265
|
+
| Connection | TCP (host:port) | Local file |
|
|
266
|
+
| Auth | User / Password | None |
|
|
267
|
+
| Pooling | Yes (configurable) | No (single connection) |
|
|
268
|
+
| Auto-reconnect | Yes | N/A |
|
|
269
|
+
| `upsertBatch` | `ON DUPLICATE KEY UPDATE` | `ON CONFLICT DO UPDATE` (requires PK/UNIQUE) |
|
|
270
|
+
| `deleteAndInsertBatch` | Transaction | Transaction |
|
|
271
|
+
| Table discovery | `information_schema` | `sqlite_master` |
|
|
272
|
+
|
|
257
273
|
## Logging Configuration (日志配置)
|
|
258
274
|
|
|
259
275
|
本节点包使用 `node.log` / `node.error` 输出运行日志,其输出级别受 Node-RED 全局日志配置控制。
|
package/db-crud.html
CHANGED
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
$select.html('<option value="">-- 加载中 --</option>');
|
|
162
|
-
$.getJSON('
|
|
162
|
+
$.getJSON('tangbao-db-config/' + dbConfigId + '/tables', function(tables) {
|
|
163
163
|
var html = '<option value="">-- 请选择表 --</option>';
|
|
164
164
|
var hasCurrent = false;
|
|
165
165
|
tables.forEach(function(t) {
|