@aaqu/fromcubes-db 0.0.0-stage → 0.1.1

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.
Files changed (54) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +24 -0
  3. package/README.md +442 -2
  4. package/SECURITY.md +75 -0
  5. package/THIRD-PARTY-NOTICES.md +151 -0
  6. package/examples/Quick Start/All Databases.json +1719 -0
  7. package/examples/Quick Start/ClickHouse.json +278 -0
  8. package/examples/Quick Start/CockroachDB.json +280 -0
  9. package/examples/Quick Start/Firebird.json +278 -0
  10. package/examples/Quick Start/MariaDB.json +281 -0
  11. package/examples/Quick Start/MySQL.json +281 -0
  12. package/examples/Quick Start/Oracle.json +280 -0
  13. package/examples/Quick Start/PostgreSQL.json +280 -0
  14. package/examples/Quick Start/SQL Server.json +282 -0
  15. package/examples/Quick Start/SQLite.json +278 -0
  16. package/examples/Quick Start/TiDB.json +281 -0
  17. package/examples/Quick Start/YugabyteDB.json +280 -0
  18. package/examples/SQLite Sensor Log With Portal.json +391 -0
  19. package/examples/Select With Parameters.json +130 -0
  20. package/index.js +32 -0
  21. package/lib/adapters/clickhouse.js +254 -0
  22. package/lib/adapters/firebird.js +416 -0
  23. package/lib/adapters/index.js +37 -0
  24. package/lib/adapters/mssql.js +178 -0
  25. package/lib/adapters/mysql.js +171 -0
  26. package/lib/adapters/oracle.js +272 -0
  27. package/lib/adapters/postgres.js +161 -0
  28. package/lib/adapters/read.js +57 -0
  29. package/lib/adapters/sqlite.js +193 -0
  30. package/lib/adapters/time.js +89 -0
  31. package/lib/bound.js +29 -0
  32. package/lib/editor-api.js +134 -0
  33. package/lib/editor-preview.js +191 -0
  34. package/lib/errors.js +66 -0
  35. package/lib/params.js +966 -0
  36. package/lib/pool.js +391 -0
  37. package/lib/settings.js +302 -0
  38. package/lib/sql/compile.js +160 -0
  39. package/lib/sql/dialect.js +194 -0
  40. package/lib/sql/parse.js +202 -0
  41. package/lib/sql/types.js +1071 -0
  42. package/lib/sqlite-files.js +137 -0
  43. package/nodes/connection.html +728 -0
  44. package/nodes/connection.js +179 -0
  45. package/nodes/editor/ark-pixel.LICENSE.txt +96 -0
  46. package/nodes/editor/ark-pixel.woff2 +0 -0
  47. package/nodes/editor/mark.svg +5 -0
  48. package/nodes/editor/sql-editor.css +604 -0
  49. package/nodes/editor/sql-editor.js +1490 -0
  50. package/nodes/editor/sql-model.js +203 -0
  51. package/nodes/icons/fromcubes-db.svg +24 -0
  52. package/nodes/query.html +662 -0
  53. package/nodes/query.js +195 -0
  54. package/package.json +81 -4
@@ -0,0 +1,280 @@
1
+ [
2
+ {
3
+ "id": "fcdb-qs-yugabytedb",
4
+ "type": "tab",
5
+ "label": "YugabyteDB quick start",
6
+ "disabled": false,
7
+ "info": "**What:** creates the table `fromcubes_demo` on deploy, inserts a row, reads the latest ten back and clears the table — on YugabyteDB.\n\n**How:**\n\nStart a local server:\n\n docker run -d --name fromcubes-yugabytedb -p 5433:5433 yugabytedb/yugabyte:2026.1.3.1-b6 bin/yugabyted start --background=false\n\nOpen the **YugabyteDB quick start** connection and enter user `yugabyte`, password `yugabyte` — an example cannot carry credentials.\n\nDeploy, then press the buttons. Both parameters declare their column's type, so `reading: \"abc\"` is refused before it reaches the database.\n\n**Expected:** each result in the Debug sidebar and in the Node-RED log (the terminal it runs in); errors under **error**."
8
+ },
9
+ {
10
+ "id": "fcdb-qs-yugabytedb-note",
11
+ "type": "comment",
12
+ "z": "fcdb-qs-yugabytedb",
13
+ "name": "YugabyteDB: create → insert → select → clear (see the tab's info)",
14
+ "info": "**What:** creates the table `fromcubes_demo` on deploy, inserts a row, reads the latest ten back and clears the table — on YugabyteDB.\n\n**How:**\n\nStart a local server:\n\n docker run -d --name fromcubes-yugabytedb -p 5433:5433 yugabytedb/yugabyte:2026.1.3.1-b6 bin/yugabyted start --background=false\n\nOpen the **YugabyteDB quick start** connection and enter user `yugabyte`, password `yugabyte` — an example cannot carry credentials.\n\nDeploy, then press the buttons. Both parameters declare their column's type, so `reading: \"abc\"` is refused before it reaches the database.\n\n**Expected:** each result in the Debug sidebar and in the Node-RED log (the terminal it runs in); errors under **error**.",
15
+ "x": 260,
16
+ "y": 40,
17
+ "wires": []
18
+ },
19
+ {
20
+ "id": "fcdb-qs-yugabytedb-on-deploy",
21
+ "type": "inject",
22
+ "z": "fcdb-qs-yugabytedb",
23
+ "name": "on deploy",
24
+ "props": [
25
+ {
26
+ "p": "payload"
27
+ }
28
+ ],
29
+ "repeat": "",
30
+ "crontab": "",
31
+ "once": true,
32
+ "onceDelay": "1",
33
+ "topic": "",
34
+ "payload": "",
35
+ "payloadType": "date",
36
+ "x": 140,
37
+ "y": 100,
38
+ "wires": [
39
+ [
40
+ "fcdb-qs-yugabytedb-create"
41
+ ]
42
+ ]
43
+ },
44
+ {
45
+ "id": "fcdb-qs-yugabytedb-create",
46
+ "type": "fromcubes-db-query",
47
+ "z": "fcdb-qs-yugabytedb",
48
+ "name": "create table",
49
+ "connection": "fcdb-qs-yugabytedb-conn",
50
+ "sql": "CREATE TABLE IF NOT EXISTS fromcubes_demo (\n id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,\n note TEXT NOT NULL,\n reading DOUBLE PRECISION,\n created_at TIMESTAMPTZ NOT NULL DEFAULT now()\n)",
51
+ "params": [],
52
+ "output": "count",
53
+ "target": "payload",
54
+ "timeoutMs": "",
55
+ "x": 340,
56
+ "y": 100,
57
+ "wires": [
58
+ [
59
+ "fcdb-qs-yugabytedb-debug"
60
+ ]
61
+ ]
62
+ },
63
+ {
64
+ "id": "fcdb-qs-yugabytedb-go",
65
+ "type": "inject",
66
+ "z": "fcdb-qs-yugabytedb",
67
+ "name": "insert a row",
68
+ "props": [
69
+ {
70
+ "p": "payload"
71
+ }
72
+ ],
73
+ "repeat": "",
74
+ "crontab": "",
75
+ "once": false,
76
+ "onceDelay": "0.1",
77
+ "topic": "",
78
+ "payload": "{\"note\":\"hello\",\"reading\":21.5}",
79
+ "payloadType": "json",
80
+ "x": 150,
81
+ "y": 160,
82
+ "wires": [
83
+ [
84
+ "fcdb-qs-yugabytedb-insert"
85
+ ]
86
+ ]
87
+ },
88
+ {
89
+ "id": "fcdb-qs-yugabytedb-insert",
90
+ "type": "fromcubes-db-query",
91
+ "z": "fcdb-qs-yugabytedb",
92
+ "name": "insert",
93
+ "connection": "fcdb-qs-yugabytedb-conn",
94
+ "sql": "INSERT INTO fromcubes_demo (note, reading)\nVALUES (:note, :reading)",
95
+ "params": [
96
+ {
97
+ "name": "note",
98
+ "type": "msg",
99
+ "value": "payload.note",
100
+ "as": "text"
101
+ },
102
+ {
103
+ "name": "reading",
104
+ "type": "msg",
105
+ "value": "payload.reading",
106
+ "as": "double precision"
107
+ }
108
+ ],
109
+ "output": "count",
110
+ "target": "inserted",
111
+ "timeoutMs": "",
112
+ "x": 340,
113
+ "y": 160,
114
+ "wires": [
115
+ [
116
+ "fcdb-qs-yugabytedb-select"
117
+ ]
118
+ ]
119
+ },
120
+ {
121
+ "id": "fcdb-qs-yugabytedb-read",
122
+ "type": "inject",
123
+ "z": "fcdb-qs-yugabytedb",
124
+ "name": "read",
125
+ "props": [
126
+ {
127
+ "p": "payload"
128
+ }
129
+ ],
130
+ "repeat": "",
131
+ "crontab": "",
132
+ "once": false,
133
+ "onceDelay": "0.1",
134
+ "topic": "",
135
+ "payload": "",
136
+ "payloadType": "date",
137
+ "x": 130,
138
+ "y": 220,
139
+ "wires": [
140
+ [
141
+ "fcdb-qs-yugabytedb-select"
142
+ ]
143
+ ]
144
+ },
145
+ {
146
+ "id": "fcdb-qs-yugabytedb-select",
147
+ "type": "fromcubes-db-query",
148
+ "z": "fcdb-qs-yugabytedb",
149
+ "name": "latest 10",
150
+ "connection": "fcdb-qs-yugabytedb-conn",
151
+ "sql": "SELECT id, note, reading, created_at\nFROM fromcubes_demo\nORDER BY id DESC\nLIMIT 10",
152
+ "params": [],
153
+ "output": "rows",
154
+ "target": "payload",
155
+ "timeoutMs": "",
156
+ "x": 540,
157
+ "y": 190,
158
+ "wires": [
159
+ [
160
+ "fcdb-qs-yugabytedb-debug"
161
+ ]
162
+ ]
163
+ },
164
+ {
165
+ "id": "fcdb-qs-yugabytedb-wipe",
166
+ "type": "inject",
167
+ "z": "fcdb-qs-yugabytedb",
168
+ "name": "clear",
169
+ "props": [
170
+ {
171
+ "p": "payload"
172
+ }
173
+ ],
174
+ "repeat": "",
175
+ "crontab": "",
176
+ "once": false,
177
+ "onceDelay": "0.1",
178
+ "topic": "",
179
+ "payload": "",
180
+ "payloadType": "date",
181
+ "x": 130,
182
+ "y": 280,
183
+ "wires": [
184
+ [
185
+ "fcdb-qs-yugabytedb-clear"
186
+ ]
187
+ ]
188
+ },
189
+ {
190
+ "id": "fcdb-qs-yugabytedb-clear",
191
+ "type": "fromcubes-db-query",
192
+ "z": "fcdb-qs-yugabytedb",
193
+ "name": "clear table",
194
+ "connection": "fcdb-qs-yugabytedb-conn",
195
+ "sql": "DELETE FROM fromcubes_demo",
196
+ "params": [],
197
+ "output": "count",
198
+ "target": "payload",
199
+ "timeoutMs": "",
200
+ "x": 340,
201
+ "y": 280,
202
+ "wires": [
203
+ [
204
+ "fcdb-qs-yugabytedb-debug"
205
+ ]
206
+ ]
207
+ },
208
+ {
209
+ "id": "fcdb-qs-yugabytedb-debug",
210
+ "type": "debug",
211
+ "z": "fcdb-qs-yugabytedb",
212
+ "name": "YugabyteDB",
213
+ "active": true,
214
+ "tosidebar": true,
215
+ "console": true,
216
+ "tostatus": true,
217
+ "complete": "payload",
218
+ "targetType": "msg",
219
+ "statusVal": "payload",
220
+ "statusType": "auto",
221
+ "x": 760,
222
+ "y": 190,
223
+ "wires": []
224
+ },
225
+ {
226
+ "id": "fcdb-qs-yugabytedb-catch",
227
+ "type": "catch",
228
+ "z": "fcdb-qs-yugabytedb",
229
+ "name": "database errors",
230
+ "scope": null,
231
+ "uncaught": false,
232
+ "x": 140,
233
+ "y": 340,
234
+ "wires": [
235
+ [
236
+ "fcdb-qs-yugabytedb-error"
237
+ ]
238
+ ]
239
+ },
240
+ {
241
+ "id": "fcdb-qs-yugabytedb-error",
242
+ "type": "debug",
243
+ "z": "fcdb-qs-yugabytedb",
244
+ "name": "error",
245
+ "active": true,
246
+ "tosidebar": true,
247
+ "console": true,
248
+ "tostatus": false,
249
+ "complete": "true",
250
+ "targetType": "full",
251
+ "statusVal": "",
252
+ "statusType": "auto",
253
+ "x": 340,
254
+ "y": 340,
255
+ "wires": []
256
+ },
257
+ {
258
+ "id": "fcdb-qs-yugabytedb-conn",
259
+ "type": "fromcubes-db-connection",
260
+ "name": "YugabyteDB quick start",
261
+ "dialect": "yugabytedb",
262
+ "userSource": "cred",
263
+ "passwordSource": "cred",
264
+ "poolMin": 0,
265
+ "poolMax": 10,
266
+ "idleTimeoutMs": 30000,
267
+ "connectTimeoutMs": 15000,
268
+ "queryTimeoutMs": 30000,
269
+ "queueMax": 100,
270
+ "undefinedAsNull": false,
271
+ "options": "",
272
+ "host": "localhost",
273
+ "port": 5433,
274
+ "database": "yugabyte",
275
+ "pgSsl": "disable",
276
+ "pgCa": "",
277
+ "pgSchema": "",
278
+ "appName": ""
279
+ }
280
+ ]
@@ -0,0 +1,391 @@
1
+ [
2
+ {
3
+ "id": "fcdb-portal-tab",
4
+ "type": "tab",
5
+ "label": "SQLite + portal",
6
+ "disabled": false,
7
+ "info": "fromcubes-db writing to SQLite, a portal-react page reading it live."
8
+ },
9
+ {
10
+ "id": "fcdb-portal-comment",
11
+ "type": "comment",
12
+ "z": "fcdb-portal-tab",
13
+ "name": "SQLite Sensor Log (fromcubes-db + portal-react)",
14
+ "info": "## What it demonstrates\nA simulated sensor writes a row every 3 s into the SQLite database `sensor-log` (`<userDir>/fromcubes-db/sensor-log.db`, created on the first query). A `portal-react` page shows the latest 20 rows live, and can add a reading or clear the table.\n\nEvery value — the reading, the row limit — is bound through a `:name` placeholder with a declared type. Nothing from the browser is ever part of the SQL text.\n\n## Needs\n`@aaqu/fromcubes-db`, `@aaqu/fromcubes-react` and, for the styling, `@aaqu/fromcubes-tailwind`.\n\n## How to run\n1. Import, deploy.\n2. Open `http://<host>:1880/fromcubes/sensor-log`.\n\n## Expected result\nA new row every 3 s in every open tab. **Add reading** inserts the typed value (a non-number is refused by the `real` declaration before it reaches the database; the reason is shown in that tab and in the debug sidebar); **Clear** empties the table for everyone. A refresh answers only the tab that asked (`msg._client`); writes are broadcast.",
15
+ "x": 290,
16
+ "y": 40,
17
+ "wires": []
18
+ },
19
+ {
20
+ "id": "fcdb-portal-conn",
21
+ "type": "fromcubes-db-connection",
22
+ "name": "sensor-log",
23
+ "dialect": "sqlite",
24
+ "showDialect": true,
25
+ "sqliteFile": "sensor-log",
26
+ "sqliteReadOnly": false,
27
+ "sqliteWal": true,
28
+ "sqliteForeignKeys": true,
29
+ "sqliteBusyTimeoutMs": 5000,
30
+ "poolMax": 1,
31
+ "options": ""
32
+ },
33
+ {
34
+ "id": "fcdb-portal-setup",
35
+ "type": "inject",
36
+ "z": "fcdb-portal-tab",
37
+ "name": "on deploy",
38
+ "props": [],
39
+ "repeat": "",
40
+ "once": true,
41
+ "onceDelay": 0.1,
42
+ "topic": "",
43
+ "x": 130,
44
+ "y": 120,
45
+ "wires": [["fcdb-portal-create"]]
46
+ },
47
+ {
48
+ "id": "fcdb-portal-create",
49
+ "type": "fromcubes-db-query",
50
+ "z": "fcdb-portal-tab",
51
+ "name": "create table",
52
+ "connection": "fcdb-portal-conn",
53
+ "sql": "CREATE TABLE IF NOT EXISTS readings (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n sensor TEXT NOT NULL,\n value REAL NOT NULL,\n at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))\n)",
54
+ "params": [],
55
+ "output": "count",
56
+ "target": "payload",
57
+ "timeoutMs": "",
58
+ "x": 330,
59
+ "y": 120,
60
+ "wires": [[]]
61
+ },
62
+ {
63
+ "id": "fcdb-portal-tick",
64
+ "type": "inject",
65
+ "z": "fcdb-portal-tab",
66
+ "name": "every 3 s",
67
+ "props": [],
68
+ "repeat": "3",
69
+ "once": false,
70
+ "topic": "",
71
+ "x": 130,
72
+ "y": 220,
73
+ "wires": [["fcdb-portal-sim"]]
74
+ },
75
+ {
76
+ "id": "fcdb-portal-sim",
77
+ "type": "function",
78
+ "z": "fcdb-portal-tab",
79
+ "name": "simulate t1",
80
+ "func": "const t = Date.now() / 60000;\nmsg.payload = { sensor: \"t1\", value: 21 + 3 * Math.sin(t) + (Math.random() - 0.5) };\nreturn msg;",
81
+ "outputs": 1,
82
+ "x": 300,
83
+ "y": 220,
84
+ "wires": [["fcdb-portal-insert"]]
85
+ },
86
+ {
87
+ "id": "fcdb-portal-insert",
88
+ "type": "fromcubes-db-query",
89
+ "z": "fcdb-portal-tab",
90
+ "name": "insert reading",
91
+ "connection": "fcdb-portal-conn",
92
+ "sql": "INSERT INTO readings (sensor, value)\nVALUES (:sensor, :value)",
93
+ "params": [
94
+ {
95
+ "name": "sensor",
96
+ "type": "msg",
97
+ "value": "payload.sensor",
98
+ "as": "text"
99
+ },
100
+ {
101
+ "name": "value",
102
+ "type": "msg",
103
+ "value": "payload.value",
104
+ "as": "real"
105
+ }
106
+ ],
107
+ "output": "count",
108
+ "target": "inserted",
109
+ "timeoutMs": "",
110
+ "x": 490,
111
+ "y": 220,
112
+ "wires": [["fcdb-portal-sel-broadcast"]]
113
+ },
114
+ {
115
+ "id": "fcdb-portal-sel-broadcast",
116
+ "type": "fromcubes-db-query",
117
+ "z": "fcdb-portal-tab",
118
+ "name": "latest 20",
119
+ "connection": "fcdb-portal-conn",
120
+ "sql": "SELECT id, sensor, value, at\nFROM readings\nORDER BY id DESC\nLIMIT :limit",
121
+ "params": [
122
+ {
123
+ "name": "limit",
124
+ "type": "num",
125
+ "value": "20",
126
+ "as": "integer"
127
+ }
128
+ ],
129
+ "output": "rows",
130
+ "target": "payload",
131
+ "timeoutMs": "",
132
+ "x": 690,
133
+ "y": 220,
134
+ "wires": [["fcdb-portal-out-1"]]
135
+ },
136
+ {
137
+ "id": "fcdb-portal",
138
+ "type": "portal-react",
139
+ "z": "fcdb-portal-tab",
140
+ "name": "Sensor log",
141
+ "subPath": "sensor-log",
142
+ "pageTitle": "Sensor log",
143
+ "customHead": "",
144
+ "componentCode": "function Sparkline({ values }) {\n if (values.length < 2) return <div className=\"h-24 flex items-center justify-center text-sm text-zinc-500\">waiting for readings…</div>;\n const min = Math.min(...values);\n const max = Math.max(...values);\n const span = max - min || 1;\n const points = values\n .map((v, i) => `${(i / (values.length - 1)) * 300},${90 - ((v - min) / span) * 80}`)\n .join(\" \");\n return (\n <svg viewBox=\"0 0 300 100\" className=\"w-full h-24\">\n <polyline points={points} fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" className=\"text-amber-400\" />\n </svg>\n );\n}\n\nfunction App() {\n const { data, send, portalClient } = useNodeRed();\n const [value, setValue] = useState(\"21.5\");\n\n // Ask for the rows once connected — portalClient arrives with the server's\n // hello, and a send before that would be dropped. The flow answers this\n // browser only (msg._client), and again after every reconnect.\n useEffect(() => {\n if (portalClient) send({ action: \"refresh\" });\n }, [portalClient]);\n\n // Rows arrive as an array; a refused write comes back as { error } to the\n // tab that sent it, and must not wipe the table it is looking at.\n const [rows, setRows] = useState([]);\n const [error, setError] = useState(null);\n useEffect(() => {\n if (Array.isArray(data)) {\n setRows(data);\n setError(null);\n } else if (data && data.error) setError(data.error);\n }, [data]);\n const latest = rows[0];\n const values = rows.map((r) => r.value).reverse();\n\n return (\n <div className=\"min-h-screen bg-zinc-950 text-zinc-100 p-8\">\n <div className=\"max-w-3xl mx-auto space-y-6\">\n <header className=\"flex items-baseline justify-between\">\n <h1 className=\"text-2xl font-semibold\">\n Sensor log <span className=\"text-amber-400\">SQLite</span>\n </h1>\n <span className=\"text-sm text-zinc-500\">fromcubes-db · portal-react</span>\n </header>\n\n <div className=\"grid grid-cols-3 gap-4\">\n <div className=\"rounded-xl bg-zinc-900 p-4\">\n <div className=\"text-xs uppercase text-zinc-500\">latest</div>\n <div className=\"text-3xl font-bold\">{latest ? latest.value.toFixed(1) : \"—\"}<span className=\"text-base text-zinc-500\"> °C</span></div>\n </div>\n <div className=\"rounded-xl bg-zinc-900 p-4\">\n <div className=\"text-xs uppercase text-zinc-500\">rows shown</div>\n <div className=\"text-3xl font-bold\">{rows.length}</div>\n </div>\n <div className=\"rounded-xl bg-zinc-900 p-4\">\n <div className=\"text-xs uppercase text-zinc-500\">last id</div>\n <div className=\"text-3xl font-bold\">{latest ? latest.id : \"—\"}</div>\n </div>\n </div>\n\n <div className=\"rounded-xl bg-zinc-900 p-4\">\n <Sparkline values={values} />\n </div>\n\n <div className=\"flex gap-2\">\n <input\n className=\"flex-1 rounded-lg bg-zinc-900 border border-zinc-700 px-3 py-2\"\n value={value}\n onChange={(e) => setValue(e.target.value)}\n />\n <button\n className=\"rounded-lg bg-amber-500 text-zinc-950 font-semibold px-4 py-2 hover:bg-amber-400\"\n onClick={() => send({ action: \"add\", value })}\n >\n Add reading\n </button>\n <button\n className=\"rounded-lg border border-zinc-700 px-4 py-2 hover:bg-zinc-800\"\n onClick={() => send({ action: \"clear\" })}\n >\n Clear\n </button>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-red-500/40 bg-red-500/10 px-3 py-2 text-sm text-red-300\">\n {error}\n </div>\n )}\n\n <table className=\"w-full text-sm\">\n <thead className=\"text-left text-zinc-500\">\n <tr>\n <th className=\"py-2\">id</th>\n <th>sensor</th>\n <th>value</th>\n <th>at (UTC)</th>\n </tr>\n </thead>\n <tbody>\n {rows.map((r) => (\n <tr key={r.id} className=\"border-t border-zinc-800\">\n <td className=\"py-1.5 text-zinc-500\">{r.id}</td>\n <td>{r.sensor}</td>\n <td className=\"font-mono\">{r.value.toFixed(2)}</td>\n <td className=\"text-zinc-400\">{r.at}</td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n </div>\n );\n}",
145
+ "x": 270,
146
+ "y": 340,
147
+ "wires": [["fcdb-portal-route"]]
148
+ },
149
+ {
150
+ "id": "fcdb-portal-route",
151
+ "type": "switch",
152
+ "z": "fcdb-portal-tab",
153
+ "name": "action",
154
+ "property": "payload.action",
155
+ "propertyType": "msg",
156
+ "rules": [
157
+ {
158
+ "t": "eq",
159
+ "v": "refresh",
160
+ "vt": "str"
161
+ },
162
+ {
163
+ "t": "eq",
164
+ "v": "add",
165
+ "vt": "str"
166
+ },
167
+ {
168
+ "t": "eq",
169
+ "v": "clear",
170
+ "vt": "str"
171
+ }
172
+ ],
173
+ "checkall": "false",
174
+ "outputs": 3,
175
+ "x": 450,
176
+ "y": 340,
177
+ "wires": [["fcdb-portal-sel-one"], ["fcdb-portal-add"], ["fcdb-portal-clear"]]
178
+ },
179
+ {
180
+ "id": "fcdb-portal-sel-one",
181
+ "type": "fromcubes-db-query",
182
+ "z": "fcdb-portal-tab",
183
+ "name": "latest 20",
184
+ "connection": "fcdb-portal-conn",
185
+ "sql": "SELECT id, sensor, value, at\nFROM readings\nORDER BY id DESC\nLIMIT :limit",
186
+ "params": [
187
+ {
188
+ "name": "limit",
189
+ "type": "num",
190
+ "value": "20",
191
+ "as": "integer"
192
+ }
193
+ ],
194
+ "output": "rows",
195
+ "target": "payload",
196
+ "timeoutMs": "",
197
+ "x": 690,
198
+ "y": 320,
199
+ "wires": [["fcdb-portal-out-2"]]
200
+ },
201
+ {
202
+ "id": "fcdb-portal-add",
203
+ "type": "fromcubes-db-query",
204
+ "z": "fcdb-portal-tab",
205
+ "name": "insert typed value",
206
+ "connection": "fcdb-portal-conn",
207
+ "sql": "INSERT INTO readings (sensor, value)\nVALUES (:sensor, :value)",
208
+ "params": [
209
+ {
210
+ "name": "sensor",
211
+ "type": "str",
212
+ "value": "manual",
213
+ "as": "text"
214
+ },
215
+ {
216
+ "name": "value",
217
+ "type": "msg",
218
+ "value": "payload.value",
219
+ "as": "real"
220
+ }
221
+ ],
222
+ "output": "count",
223
+ "target": "inserted",
224
+ "timeoutMs": "",
225
+ "x": 690,
226
+ "y": 440,
227
+ "wires": [["fcdb-portal-all-1"]]
228
+ },
229
+ {
230
+ "id": "fcdb-portal-all-1",
231
+ "type": "change",
232
+ "z": "fcdb-portal-tab",
233
+ "name": "everyone sees it",
234
+ "rules": [
235
+ {
236
+ "t": "delete",
237
+ "p": "_client",
238
+ "pt": "msg"
239
+ }
240
+ ],
241
+ "x": 930,
242
+ "y": 620,
243
+ "wires": [["fcdb-portal-sel-all"]]
244
+ },
245
+ {
246
+ "id": "fcdb-portal-clear",
247
+ "type": "fromcubes-db-query",
248
+ "z": "fcdb-portal-tab",
249
+ "name": "delete all",
250
+ "connection": "fcdb-portal-conn",
251
+ "sql": "DELETE FROM readings",
252
+ "params": [],
253
+ "output": "count",
254
+ "target": "deleted",
255
+ "timeoutMs": "",
256
+ "x": 690,
257
+ "y": 540,
258
+ "wires": [["fcdb-portal-all-1"]]
259
+ },
260
+ {
261
+ "id": "fcdb-portal-sel-all",
262
+ "type": "fromcubes-db-query",
263
+ "z": "fcdb-portal-tab",
264
+ "name": "latest 20",
265
+ "connection": "fcdb-portal-conn",
266
+ "sql": "SELECT id, sensor, value, at\nFROM readings\nORDER BY id DESC\nLIMIT :limit",
267
+ "params": [
268
+ {
269
+ "name": "limit",
270
+ "type": "num",
271
+ "value": "20",
272
+ "as": "integer"
273
+ }
274
+ ],
275
+ "output": "rows",
276
+ "target": "payload",
277
+ "timeoutMs": "",
278
+ "x": 1110,
279
+ "y": 620,
280
+ "wires": [["fcdb-portal-out-3"]]
281
+ },
282
+ {
283
+ "id": "fcdb-portal-catch",
284
+ "type": "catch",
285
+ "z": "fcdb-portal-tab",
286
+ "name": "refused for the page",
287
+ "scope": ["fcdb-portal-add", "fcdb-portal-clear", "fcdb-portal-sel-one"],
288
+ "uncaught": false,
289
+ "x": 150,
290
+ "y": 800,
291
+ "wires": [["fcdb-portal-error"]]
292
+ },
293
+ {
294
+ "id": "fcdb-portal-debug",
295
+ "type": "debug",
296
+ "z": "fcdb-portal-tab",
297
+ "name": "debug",
298
+ "active": true,
299
+ "tosidebar": true,
300
+ "console": false,
301
+ "tostatus": false,
302
+ "complete": "true",
303
+ "targetType": "full",
304
+ "x": 330,
305
+ "y": 720,
306
+ "wires": []
307
+ },
308
+ {
309
+ "id": "fcdb-portal-error",
310
+ "type": "change",
311
+ "z": "fcdb-portal-tab",
312
+ "name": "tell that tab",
313
+ "rules": [
314
+ {
315
+ "t": "set",
316
+ "p": "payload",
317
+ "pt": "msg",
318
+ "to": "{\"error\": $$.error.message}",
319
+ "tot": "jsonata"
320
+ }
321
+ ],
322
+ "x": 350,
323
+ "y": 800,
324
+ "wires": [["fcdb-portal-out-4"]]
325
+ },
326
+ {
327
+ "id": "fcdb-portal-catch-all",
328
+ "type": "catch",
329
+ "z": "fcdb-portal-tab",
330
+ "name": "any query error",
331
+ "scope": null,
332
+ "uncaught": false,
333
+ "x": 140,
334
+ "y": 720,
335
+ "wires": [["fcdb-portal-debug"]]
336
+ },
337
+ {
338
+ "id": "fcdb-portal-in",
339
+ "type": "link in",
340
+ "z": "fcdb-portal-tab",
341
+ "name": "to page",
342
+ "links": ["fcdb-portal-out-1", "fcdb-portal-out-2", "fcdb-portal-out-3", "fcdb-portal-out-4"],
343
+ "x": 115,
344
+ "y": 340,
345
+ "wires": [["fcdb-portal"]]
346
+ },
347
+ {
348
+ "id": "fcdb-portal-out-1",
349
+ "type": "link out",
350
+ "z": "fcdb-portal-tab",
351
+ "name": "to page",
352
+ "mode": "link",
353
+ "links": ["fcdb-portal-in"],
354
+ "x": 815,
355
+ "y": 220,
356
+ "wires": []
357
+ },
358
+ {
359
+ "id": "fcdb-portal-out-2",
360
+ "type": "link out",
361
+ "z": "fcdb-portal-tab",
362
+ "name": "to page",
363
+ "mode": "link",
364
+ "links": ["fcdb-portal-in"],
365
+ "x": 815,
366
+ "y": 320,
367
+ "wires": []
368
+ },
369
+ {
370
+ "id": "fcdb-portal-out-3",
371
+ "type": "link out",
372
+ "z": "fcdb-portal-tab",
373
+ "name": "to page",
374
+ "mode": "link",
375
+ "links": ["fcdb-portal-in"],
376
+ "x": 1235,
377
+ "y": 620,
378
+ "wires": []
379
+ },
380
+ {
381
+ "id": "fcdb-portal-out-4",
382
+ "type": "link out",
383
+ "z": "fcdb-portal-tab",
384
+ "name": "to page",
385
+ "mode": "link",
386
+ "links": ["fcdb-portal-in"],
387
+ "x": 475,
388
+ "y": 800,
389
+ "wires": []
390
+ }
391
+ ]