@aaqu/fromcubes-db 0.0.0-stage → 0.1.0
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/LICENSE +201 -0
- package/NOTICE +24 -0
- package/README.md +442 -2
- package/SECURITY.md +75 -0
- package/THIRD-PARTY-NOTICES.md +151 -0
- package/examples/Quick Start/All Databases.json +1719 -0
- package/examples/Quick Start/ClickHouse.json +278 -0
- package/examples/Quick Start/CockroachDB.json +280 -0
- package/examples/Quick Start/Firebird.json +278 -0
- package/examples/Quick Start/MariaDB.json +281 -0
- package/examples/Quick Start/MySQL.json +281 -0
- package/examples/Quick Start/Oracle.json +280 -0
- package/examples/Quick Start/PostgreSQL.json +280 -0
- package/examples/Quick Start/SQL Server.json +282 -0
- package/examples/Quick Start/SQLite.json +278 -0
- package/examples/Quick Start/TiDB.json +281 -0
- package/examples/Quick Start/YugabyteDB.json +280 -0
- package/examples/SQLite Sensor Log With Portal.json +391 -0
- package/examples/Select With Parameters.json +130 -0
- package/index.js +32 -0
- package/lib/adapters/clickhouse.js +254 -0
- package/lib/adapters/firebird.js +416 -0
- package/lib/adapters/index.js +37 -0
- package/lib/adapters/mssql.js +178 -0
- package/lib/adapters/mysql.js +171 -0
- package/lib/adapters/oracle.js +272 -0
- package/lib/adapters/postgres.js +161 -0
- package/lib/adapters/read.js +57 -0
- package/lib/adapters/sqlite.js +193 -0
- package/lib/adapters/time.js +89 -0
- package/lib/bound.js +29 -0
- package/lib/editor-api.js +134 -0
- package/lib/editor-preview.js +191 -0
- package/lib/errors.js +66 -0
- package/lib/params.js +966 -0
- package/lib/pool.js +391 -0
- package/lib/settings.js +302 -0
- package/lib/sql/compile.js +160 -0
- package/lib/sql/dialect.js +194 -0
- package/lib/sql/parse.js +202 -0
- package/lib/sql/types.js +1071 -0
- package/lib/sqlite-files.js +137 -0
- package/nodes/connection.html +728 -0
- package/nodes/connection.js +179 -0
- package/nodes/editor/ark-pixel.LICENSE.txt +96 -0
- package/nodes/editor/ark-pixel.woff2 +0 -0
- package/nodes/editor/mark.svg +5 -0
- package/nodes/editor/sql-editor.css +604 -0
- package/nodes/editor/sql-editor.js +1490 -0
- package/nodes/editor/sql-model.js +203 -0
- package/nodes/icons/fromcubes-db.svg +24 -0
- package/nodes/query.html +662 -0
- package/nodes/query.js +195 -0
- package/package.json +81 -4
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL Editor — the logic, without a DOM: which query nodes the tree lists, how
|
|
3
|
+
* the parameter rows line up with the SQL's placeholders, which fields a sample
|
|
4
|
+
* message offers, and which field a new placeholder most likely means.
|
|
5
|
+
*
|
|
6
|
+
* UMD: require() in tests, window.__fcdbSqlModel in the browser.
|
|
7
|
+
*/
|
|
8
|
+
(function (root, factory) {
|
|
9
|
+
if (typeof module === "object" && module.exports) module.exports = factory();
|
|
10
|
+
else root.__fcdbSqlModel = factory();
|
|
11
|
+
})(typeof self !== "undefined" ? self : this, function () {
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Every query node as the tree shows it, ordered by flow tab, then name.
|
|
16
|
+
*
|
|
17
|
+
* @param {Array<object>} nodes RED.nodes' query nodes
|
|
18
|
+
* @param {(id: string) => object|null} flowOf the tab (or subflow) a node is on
|
|
19
|
+
* @param {(id: string) => object|null} connectionOf
|
|
20
|
+
*/
|
|
21
|
+
function collectQueries(nodes, flowOf, connectionOf) {
|
|
22
|
+
const out = nodes.map(function (n) {
|
|
23
|
+
const flow = flowOf(n.z) || null;
|
|
24
|
+
const conn = n.connection ? connectionOf(n.connection) : null;
|
|
25
|
+
return {
|
|
26
|
+
id: n.id,
|
|
27
|
+
name: n.name || "",
|
|
28
|
+
label: n.name || "db query",
|
|
29
|
+
flowId: n.z || "",
|
|
30
|
+
flowLabel: flow ? flow.label || flow.name || flow.id : "(no flow)",
|
|
31
|
+
disabled: n.d ? "node" : flow && flow.disabled ? "flow" : "",
|
|
32
|
+
connection: n.connection || "",
|
|
33
|
+
product: conn && conn.dialect ? conn.dialect : "",
|
|
34
|
+
connectionLabel: conn ? conn.name || conn.dialect || conn.id : "",
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
out.sort(function (a, b) {
|
|
38
|
+
return a.flowLabel.localeCompare(b.flowLabel) || a.label.localeCompare(b.label) || a.id.localeCompare(b.id);
|
|
39
|
+
});
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Grouped by flow; a filter matches the node's name, its flow or its SQL-less label. */
|
|
44
|
+
function groupByFlow(queries, filter) {
|
|
45
|
+
const f = String(filter || "")
|
|
46
|
+
.trim()
|
|
47
|
+
.toLowerCase();
|
|
48
|
+
const groups = [];
|
|
49
|
+
const byFlow = {};
|
|
50
|
+
queries.forEach(function (q) {
|
|
51
|
+
if (f && (q.label + " " + q.flowLabel + " " + q.connectionLabel).toLowerCase().indexOf(f) === -1) return;
|
|
52
|
+
if (!byFlow[q.flowId]) {
|
|
53
|
+
byFlow[q.flowId] = { flowId: q.flowId, flowLabel: q.flowLabel, disabled: q.disabled === "flow", items: [] };
|
|
54
|
+
groups.push(byFlow[q.flowId]);
|
|
55
|
+
}
|
|
56
|
+
byFlow[q.flowId].items.push(q);
|
|
57
|
+
});
|
|
58
|
+
return groups;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The rows under the editor: the node's parameters in their saved order, each
|
|
63
|
+
* with what the preview said about it, then a row for every placeholder that
|
|
64
|
+
* has no parameter yet. Nothing is added to the node until the user says so.
|
|
65
|
+
*
|
|
66
|
+
* @param {Array<object>} params node.params as saved
|
|
67
|
+
* @param {object|null} preview POST /fromcubes-db/editor/preview answer
|
|
68
|
+
*/
|
|
69
|
+
function rowsFor(params, preview) {
|
|
70
|
+
const results = (preview && preview.params) || [];
|
|
71
|
+
const names = (preview && preview.names) || [];
|
|
72
|
+
const rows = params.map(function (p, index) {
|
|
73
|
+
const r = results[index] || {};
|
|
74
|
+
const name = String(p.name || "").trim();
|
|
75
|
+
return {
|
|
76
|
+
kind: "param",
|
|
77
|
+
index: index,
|
|
78
|
+
param: p,
|
|
79
|
+
name: name,
|
|
80
|
+
used: names.indexOf(name) !== -1,
|
|
81
|
+
status: r.status || "pending",
|
|
82
|
+
message: r.message || "",
|
|
83
|
+
value: r.value || null,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
((preview && preview.missing) || []).forEach(function (name) {
|
|
87
|
+
rows.push({ kind: "missing", name: name, used: true, status: "unbound", message: "no value bound", value: null });
|
|
88
|
+
});
|
|
89
|
+
return rows;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** How a value looks in a short cell. */
|
|
93
|
+
function kindOf(value) {
|
|
94
|
+
if (value === null) return "null";
|
|
95
|
+
if (Array.isArray(value)) return "array";
|
|
96
|
+
return typeof value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function previewText(value) {
|
|
100
|
+
const k = kindOf(value);
|
|
101
|
+
if (k === "string") return JSON.stringify(value.length > 40 ? value.slice(0, 40) + "…" : value);
|
|
102
|
+
if (k === "object") return "{" + Object.keys(value).length + "}";
|
|
103
|
+
if (k === "array") return "[" + value.length + "]";
|
|
104
|
+
return String(value);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const IDENT = /^[A-Za-z_$][\w$]*$/;
|
|
108
|
+
|
|
109
|
+
function joinPath(base, key) {
|
|
110
|
+
if (typeof key === "number") return base + "[" + key + "]";
|
|
111
|
+
if (IDENT.test(key)) return base ? base + "." + key : key;
|
|
112
|
+
return base + '["' + String(key).replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"]';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The fields of a sample message, as msg paths, depth first. Arrays show
|
|
117
|
+
* their first element only (a row of a hundred readings is one shape).
|
|
118
|
+
*
|
|
119
|
+
* @param {object} msg
|
|
120
|
+
* @param {{ maxDepth?: number, maxFields?: number }} [opts]
|
|
121
|
+
*/
|
|
122
|
+
function messageFields(msg, opts) {
|
|
123
|
+
const maxDepth = (opts && opts.maxDepth) || 5;
|
|
124
|
+
const maxFields = (opts && opts.maxFields) || 300;
|
|
125
|
+
const out = [];
|
|
126
|
+
function walk(value, path, depth) {
|
|
127
|
+
if (out.length >= maxFields || depth > maxDepth) return;
|
|
128
|
+
const k = kindOf(value);
|
|
129
|
+
if (k === "object") {
|
|
130
|
+
Object.keys(value).forEach(function (key) {
|
|
131
|
+
if (key === "_msgid") return;
|
|
132
|
+
const child = value[key];
|
|
133
|
+
const p = joinPath(path, key);
|
|
134
|
+
out.push({ path: p, key: key, depth: depth, kind: kindOf(child), preview: previewText(child) });
|
|
135
|
+
walk(child, p, depth + 1);
|
|
136
|
+
});
|
|
137
|
+
} else if (k === "array" && value.length) {
|
|
138
|
+
const p = joinPath(path, 0);
|
|
139
|
+
out.push({ path: p, key: "0", depth: depth, kind: kindOf(value[0]), preview: previewText(value[0]) });
|
|
140
|
+
walk(value[0], p, depth + 1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
walk(msg && typeof msg === "object" ? msg : {}, "", 0);
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A placeholder name from a field: `payload.sensor-id` → `sensor_id`. */
|
|
148
|
+
function nameFor(field) {
|
|
149
|
+
const base = String(field.key === "0" ? "item" : field.key).replace(/[^A-Za-z0-9_]/g, "_");
|
|
150
|
+
return /^[A-Za-z_]/.test(base) ? base : "p_" + base;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The msg path a new placeholder most likely means: a field whose own name
|
|
155
|
+
* matches it (payload first, then shallower), else `payload.<name>`.
|
|
156
|
+
*/
|
|
157
|
+
function suggestPath(name, fields) {
|
|
158
|
+
const want = String(name).toLowerCase();
|
|
159
|
+
const hits = fields.filter(function (f) {
|
|
160
|
+
return String(f.key).toLowerCase() === want && f.kind !== "object";
|
|
161
|
+
});
|
|
162
|
+
hits.sort(function (a, b) {
|
|
163
|
+
const pa = a.path.indexOf("payload") === 0 ? 0 : 1;
|
|
164
|
+
const pb = b.path.indexOf("payload") === 0 ? 0 : 1;
|
|
165
|
+
return pa - pb || a.depth - b.depth;
|
|
166
|
+
});
|
|
167
|
+
return hits.length ? hits[0].path : "payload." + name;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A new parameter for a placeholder, bound to its likeliest field. */
|
|
171
|
+
function newParam(name, fields) {
|
|
172
|
+
return { name: name, type: "msg", value: suggestPath(name, fields), as: "auto", asArgs: "" };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Equal parameter lists, as the node would save them. */
|
|
176
|
+
function sameParams(a, b) {
|
|
177
|
+
return JSON.stringify(normalizeParams(a)) === JSON.stringify(normalizeParams(b));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function normalizeParams(list) {
|
|
181
|
+
return (list || []).map(function (p) {
|
|
182
|
+
return {
|
|
183
|
+
name: String(p.name || "").trim(),
|
|
184
|
+
type: p.type || "msg",
|
|
185
|
+
value: p.value === undefined ? "" : p.value,
|
|
186
|
+
as: p.as || "auto",
|
|
187
|
+
asArgs: String(p.asArgs || "").trim(),
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
collectQueries: collectQueries,
|
|
194
|
+
groupByFlow: groupByFlow,
|
|
195
|
+
rowsFor: rowsFor,
|
|
196
|
+
messageFields: messageFields,
|
|
197
|
+
nameFor: nameFor,
|
|
198
|
+
suggestPath: suggestPath,
|
|
199
|
+
newParam: newParam,
|
|
200
|
+
sameParams: sameParams,
|
|
201
|
+
normalizeParams: normalizeParams,
|
|
202
|
+
};
|
|
203
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="44" height="60" viewBox="0 0 44 60">
|
|
2
|
+
<!-- The fromcubes mark, traced from the project artwork by tools/build-icon.mjs.
|
|
3
|
+
The badge is cut out of the mark with a mask rather than hidden behind a
|
|
4
|
+
halo painted in the background colour: an icon cannot know what is behind
|
|
5
|
+
it, and masking keeps the traced edges exact instead of re-rasterising them.
|
|
6
|
+
The badge is the "database" icon from Lucide (https://lucide.dev), ISC —
|
|
7
|
+
see THIRD-PARTY-NOTICES.md. -->
|
|
8
|
+
<mask id="fc-cut" maskUnits="userSpaceOnUse" x="0" y="0" width="44" height="60">
|
|
9
|
+
<rect width="44" height="60" fill="#ffffff"/>
|
|
10
|
+
<g transform="translate(24.2 33.25) scale(0.8750)" fill="none" stroke="#000000"
|
|
11
|
+
stroke-width="6.17" stroke-linecap="round" stroke-linejoin="round">
|
|
12
|
+
<ellipse cx="12" cy="5" rx="9" ry="3"/>
|
|
13
|
+
<path d="M3 5V19A9 3 0 0 0 21 19V5"/>
|
|
14
|
+
<path d="M3 12A9 3 0 0 0 21 12"/>
|
|
15
|
+
</g>
|
|
16
|
+
</mask>
|
|
17
|
+
<path fill="#10181d" fill-rule="evenodd" mask="url(#fc-cut)" d="M20.79 6.25L22.01 6.25L23.23 6.86L32.17 12.34L37.65 15.19L38.46 16.00L38.46 35.50L37.65 36.31L32.17 39.16L23.23 44.64L22.01 45.25L20.38 45.05L12.06 39.97L6.57 37.13L4.34 35.50L4.34 16.00L9.42 12.75L20.79 6.45ZM21.20 8.08L6.98 16.20L7.18 16.61L7.99 16.61L10.84 14.78L14.29 13.97L15.92 13.97L22.42 17.63L24.65 19.05L24.85 20.67L24.04 21.48L23.43 22.91L20.99 24.13L21.20 24.73L35.82 16.41L35.01 16.00L31.96 18.03L27.09 18.84L20.59 15.19L19.37 14.17L18.15 13.77L17.95 12.14L19.57 9.70L22.01 8.48L21.40 8.08ZM23.63 9.50L20.99 10.92L19.98 12.75L27.49 17.02L30.95 16.41L33.38 14.78L23.84 9.50ZM14.49 15.80L11.45 16.41L9.42 17.83L15.71 21.28L16.93 22.30L18.56 22.91L18.76 23.31L22.21 21.48L22.82 20.06L17.13 16.61L15.51 15.80L14.70 15.80ZM6.17 18.03L5.96 18.84L9.21 20.47L12.46 24.13L12.67 34.69L11.85 35.50L8.81 35.50L6.57 34.08L5.96 34.08L5.96 34.69L9.62 36.52L20.38 43.02L20.38 41.80L17.34 40.38L14.29 37.13L13.88 26.16L14.70 25.34L17.95 25.34L20.18 26.77L20.59 26.77L20.59 26.16L6.37 18.03ZM36.63 18.03L35.82 18.44L35.82 22.70L34.40 26.77L26.07 31.84L25.06 32.05L24.04 31.64L22.82 29.41L22.62 26.16L22.21 26.36L22.21 42.81L23.02 42.61L22.82 38.95L24.24 34.48L33.18 29.00L34.81 29.61L36.02 31.84L36.02 34.89L36.84 34.69L36.84 18.03ZM33.99 19.45L24.45 24.94L24.65 29.00L25.06 29.81L25.67 30.02L27.49 28.59L32.98 25.55L33.99 22.50L33.99 19.66ZM6.17 20.88L5.96 31.84L8.81 33.27L9.01 33.67L10.84 33.67L10.63 24.53L8.81 22.91L8.40 22.09L6.17 21.08ZM15.92 27.17L15.92 36.11L18.56 38.95L20.38 39.97L20.59 29.00L17.54 27.17L16.12 27.17ZM33.18 31.23L25.67 35.70L24.65 38.95L24.65 41.59L34.20 36.11L34.20 32.25L33.38 31.23Z"/>
|
|
18
|
+
<g transform="translate(24.2 33.25) scale(0.8750)" fill="none" stroke="#0b6a70"
|
|
19
|
+
stroke-width="2.74" stroke-linecap="round" stroke-linejoin="round">
|
|
20
|
+
<ellipse cx="12" cy="5" rx="9" ry="3"/>
|
|
21
|
+
<path d="M3 5V19A9 3 0 0 0 21 19V5"/>
|
|
22
|
+
<path d="M3 12A9 3 0 0 0 21 12"/>
|
|
23
|
+
</g>
|
|
24
|
+
</svg>
|