@aaqu/fromcubes-db 0.5.0
Fromcubes DB: Node-RED nodes for PostgreSQL, CockroachDB, YugabyteDB, TimescaleDB, CrateDB, MySQL, MariaDB, TiDB, Vitess, OceanBase, SQL Server, Oracle, SQLite, Firebird, ClickHouse, DuckDB and Spanner — injection-safe parameter binding and leak-free conn
@aaqu/fromcubes-db
Node-RED nodes for PostgreSQL, CockroachDB, YugabyteDB, TimescaleDB, CrateDB, MySQL, MariaDB, TiDB, Vitess, OceanBase, Microsoft SQL Server, Oracle, SQLite, Firebird, ClickHouse, DuckDB and Spanner behind one connection node and one query node. Tested against PostgreSQL 19, CockroachDB 26.4, YugabyteDB 2026.1, TimescaleDB 2.32, CrateDB 6.5, MySQL 26.10, MariaDB 13.1, TiDB 8.5, Vitess 24, OceanBase 4.4, SQL Server 2025, Oracle 26ai, Firebird 5.0, ClickHouse 26.11, DuckDB 2.0 and the Spanner emulator.
User guide — installing, the first query, parameters, declared types, every database's connection settings.
Each database is its own entry in the picker, with its own name, port and saved value — even where two of them currently run on the same engine and the same driver:
| Database | Picked as | Engine today | Driver today |
|---|---|---|---|
| PostgreSQL | postgres |
postgres |
pg |
| CockroachDB | cockroachdb |
postgres |
pg — Postgres wire protocol |
| YugabyteDB | yugabytedb |
postgres |
pg — YSQL, port 5433 |
| TimescaleDB | timescaledb |
postgres |
pg — PostgreSQL + extension |
| CrateDB | cratedb |
postgres |
pg — Postgres wire protocol |
| MySQL | mysql |
mysql |
mysql2 |
| MariaDB | mariadb |
mysql |
mysql2 |
| TiDB | tidb |
mysql |
mysql2 — MySQL protocol, 4000 |
| Vitess | vitess |
mysql |
mysql2 — through vtgate |
| OceanBase | oceanbase |
mysql |
mysql2 — MySQL mode, 2881 |
| Microsoft SQL Server | mssql |
mssql |
mssql / tedious |
| Oracle | oracle |
oracle |
oracledb, Thin mode |
| SQLite | sqlite |
sqlite |
node:sqlite, built into Node |
| Firebird | firebird |
firebird |
node-firebird, pure JS, 3050 |
| ClickHouse | clickhouse |
clickhouse |
@clickhouse/client, HTTP, 8123 |
| DuckDB | duckdb |
duckdb |
@duckdb/node-api, in process |
| Spanner | spanner |
spanner |
@google-cloud/spanner, gRPC |
"Today" is the point: MariaDB is not MySQL and CockroachDB is not PostgreSQL, they merely behave alike for now. Keeping them apart means the day one needs its own driver, settings or binding rule, it gets one — without unpicking the choice from every saved flow first.
Every one of them has its own integration suite running the same contract against a real
server — every product on a shared engine included, so "it speaks the same protocol" is
tested, not assumed. It is also how their differences were found: TiDB has no spatial types and
takes a vector as [1,2.5] text; YugabyteDB's numeric refuses NaN and Infinity; Vitess cannot
prepare a CALL; OceanBase allows 50 open prepared statements per session; CrateDB has its own types,
no transactions, and shows a write only after REFRESH TABLE.
Two things this package is strict about:
- SQL injection has no way in. The statement comes from the node's edit dialog and nothing else. Values arrive through a parameter list and are bound by the driver. No message content can change what a statement does.
- Connections do not leak. One pool per connection node, shared by every query node that uses it, drained and closed on redeploy.
📖 Documentation: aaqu.github.io/fromcubes-modules/db — install, first query, recipes, troubleshooting and what the package deliberately will not do.
Install
Palette manager → install @aaqu/fromcubes-db, or:
cd ~/.node-red
npm install @aaqu/fromcubes-db
All drivers ship with the package, so nothing else needs installing. Oracle runs in Thin mode —
no Oracle Instant Client required — and SQLite uses node:sqlite from Node itself, so there is
no native build step anywhere. DuckDB is the one native driver: a prebuilt binary per platform
(Linux x64/arm64, macOS, Windows), installed as an optional package and loaded on the first DuckDB
query. Where there is none — 32-bit ARM, or npm install --omit=optional — only DuckDB
connections fail, with DuckDB is not available on this platform (…); everything else works.
Node 24 or newer, Node-RED 5 or newer. That is what CI runs and the only combination the suites are executed against.
Use
Drop a db query node, create a connection, type SQL with :name placeholders, and map each
placeholder to a value:
SELECT id, name, email
FROM users
WHERE tenant_id = :tenant
AND status = :status
| Parameter | Source |
|---|---|
tenant |
msg.payload.tenantId |
status |
active (string) |
The parameter rows are normal Node-RED typedInputs — msg, flow, global, env, JSONata,
or a literal. The connection's user and password are not typedInputs, because a credential is
stored encrypted and outside the flow file; they take an environment variable through a source
picker of their own — see User and password.
Result lands on msg.payload (configurable), with msg.rowCount alongside, and msg.columns for a
statement that returns rows.
The dialog is split in two: Query carries the statement and its parameters, Connection carries what you set once — the connection itself, the result shape, the message property it lands on, and the timeout.
Placeholders
| Syntax | Meaning |
|---|---|
:name |
One value: string, number, boolean, date, buffer or null. |
:...name |
An array expanded into a value list, for IN (:...ids). |
Each database gets its own binding syntax automatically:
| Database | What the driver receives |
|---|---|
| PostgreSQL | WHERE id = $1 AND name = $2 |
| SQL Server | WHERE id = @p1 AND name = @p2 |
| Oracle | WHERE id = :p1 AND name = :p2 |
| MySQL | WHERE id = ? AND name = ? |
| SQLite | WHERE id = ? AND name = ? |
| DuckDB | WHERE id = $1 AND name = $2 |
| Spanner | WHERE id = @p1 AND name = @p2 |
An empty :...list renders as IN (NULL) — valid SQL that matches nothing.
Parameter types
Each parameter row has a type select. With auto the value is bound as it arrives. Pick anything
else and the value is checked first, so a bad message fails naming the parameter instead of
surfacing as a driver error about a column you never mentioned.
| Type | Accepts | Rejects |
|---|---|---|
string |
strings, numbers, booleans, Dates (→ ISO) | objects — use json |
number/integer |
numbers, numeric strings | "abc", NaN, Infinity, booleans |
boolean |
true/false, "yes"/"no", 1/0 |
"maybe", 2 |
date |
a Date, an ISO string, an epoch number | unparseable dates |
json |
objects, arrays, JSON strings | invalid JSON |
buffer |
Buffer, Uint8Array, base64 string | numbers |
null and undefined always pass through — whether a missing value is an error is decided by
Bind missing parameters as NULL on the connection.
For a spread parameter the check runs per element, so IN (:...ids) declared as integer
rejects the whole message when one id is junk, naming it: Parameter :ids[1] — expected an integer, got string "x".
Column types
Below the generic types the select also offers the column types of the database the connection
points at — varchar, numeric, tinyint, varchar2 — with a small field beside it for the
length or precision. Then the value is checked against that type as the product defines it, and
never reaches the SQL text: the declaration is read before binding and nowhere else.
Each product's own limits apply, which is the point of picking one:
| Declared | On | Means |
|---|---|---|
varchar(50) |
PostgreSQL, MySQL, MariaDB, CockroachDB | 50 characters |
varchar(50) |
SQL Server | 50 bytes — 'ółć' is 6 |
nvarchar(50) |
SQL Server | 50 UTF-16 units |
varchar2(50) |
Oracle | 50 bytes; varchar2(50 char) for characters |
tinyint |
MySQL | −128…127, or 0…255 with unsigned |
tinyint |
SQL Server | 0…255 |
Beyond length, the check covers what each type actually holds: integer ranges, decimal(p,s)
digit budgets, date ranges (datetime on SQL Server starts in 1753, MySQL's TIMESTAMP stops in
2038 — and a fraction the column rounds away is checked as rounded), and the shapes of uuid,
inet, macaddr, bit, ranges and SQL Server's time.
Vectors are a column type on several products: vector(3) on CockroachDB, MySQL 9, TiDB 8.4+
and MariaDB 11.7+, vector(3, float32) on SQL Server 2025 and Oracle 23ai+, QBit(Float32, 3) on
ClickHouse 25.10+, float_vector(3) on CrateDB
(the second argument is the storage format, checked against what that product has). The value is
an array of numbers, a typed array or its JSON text; a declared length must match exactly.
The declared type also picks the bind type. Left to themselves the drivers guess from the JS
value, and several guesses corrupt data rather than fail: SQL Server's driver sends every Date as
the legacy DATETIME, pg turns a json array into a PostgreSQL array, and oracledb reads any
object as a bind definition ({val, dir, type}) — so on Oracle an object always goes as JSON,
typed or not. The declaration still never reaches the SQL text.
Dates are UTC everywhere. A Date is an instant; a column without a time zone receives its UTC
wall clock and is read back the same way, whatever zone Node-RED runs in. Text without a zone
("2026-11-28 10:20") means that wall clock in UTC. MySQL and Oracle sessions are set to UTC
(Oracle with ISO NLS_* formats); a timestamp with more digits than a Date holds, or an offset a
Date would lose (timestamptz, datetimeoffset), travels as text so nothing is cut.
Numbers a double cannot hold are kept exactly. bigint is 19 digits, Oracle's NUMBER 38,
PostgreSQL's numeric a thousand — and Number('9223372036854775807') quietly returns
9223372036854776000. A BigInt stays a BigInt and a numeric string stays a string, both of which
every driver here binds, and range checks compare in BigInt rather than in doubles.
SQLite is the exception worth knowing: it accepts VARCHAR(5) and then stores anything at all
in it. The length check there is ours, not the database's — which is exactly why it is useful.
docs/column-types.md
lists where each product documents its types and every limit collected
from it. The full catalogue is lib/sql/types.js, and the integration suite creates a column of
every type in it on a real server, so a name in the picker is a name the database has.
Placeholders inside string literals, comments and quoted identifiers are left alone, so
created::text on Postgres and [a:b] on SQL Server keep working.
Result shapes
| Result | msg.payload |
|---|---|
| all rows | array of row objects (the default) |
| first row only | one row object, or null |
| affected row count | number |
| one message per row | one message per row, each a clone |
| result sets | every result set: an array of arrays, or an object keyed by names |
msg.rowCount comes with each of them. With result sets it is the rows of all sets together, and
msg.rowCounts holds the rows per set, in order.
A statement that returns rows also sets msg.columns — every shape but the count and result sets —
and it is there when no row matched, so an empty table still has its header:
msg.columns = [{ name: "name", type: "varchar" }, { name: "age", type: "int" }]
name is the key the rows use; type is the database's own name for the column's type, spelled
as that database spells it (int4 on PostgreSQL, NUMBER on Oracle, Nullable(String) on
ClickHouse), or null where the driver cannot name it — an expression on SQLite, an extension's
type on PostgreSQL. An INSERT, UPDATE or DELETE without RETURNING has no msg.columns.
Result sets
For a stored procedure that returns several SELECTs — ordinary on SQL Server. Set Result to result sets and, optionally, name the sets in Set names (one per line; commas work too):
CREATE PROCEDURE dbo.load_site @siteId INT AS
BEGIN
SET NOCOUNT ON;
SELECT id, name FROM sites WHERE id = @siteId;
SELECT id, label FROM cabinets WHERE site_id = @siteId;
SELECT cabinet_id, port, in_use FROM ports WHERE site_id = @siteId;
END
Query node SQL: EXEC dbo.load_site @siteId = :siteId, Set names: site, cabinets, ports.
msg.payload = {
site: [ { id: 1, name: "North" } ],
cabinets: [ { id: 1, label: "A-01" }, { id: 2, label: "A-02" } ],
ports: [ { cabinet_id: 1, port: 1, in_use: true }, /* … */ ]
}
msg.rowCounts = [1, 2, 3]
msg.rowCount = 6
- Without names
msg.payloadis an array with one array of rows per set —payload[0],payload[1], … That is whatmsg.payload.recordsetswas in node-red-contrib-mssql-plus with Driver output, so a migrated function node changesmsg.payload.recordsets[3]tomsg.payload[3]. - With names the procedure must return exactly that many sets. One fewer or one more and
the message fails with
ResultSetCountError—expected 13 result sets (cabinets…controlCabinets), got 12— instead of putting each later set under its neighbour's name. Names are JavaScript identifiers, each used once; the dialog and the node at start refuse anything else. - Empty sets keep their place. A set's values are read exactly like a single result's:
BIGINTpast 2⁵³ as text, binary as aBuffer, dates in UTC, CLOB as text. - A procedure's
OUTPUTparameters andRETURNvalue come inmsg.output— see Output parameters.
| Database | How to return several sets |
|---|---|
| SQL Server | EXEC dbo.proc @id = :id — every SELECT in the procedure, or in a batch of SELECTs |
| MySQL, MariaDB | CALL proc(:id) — every SELECT in the procedure |
| Oracle | BEGIN proc(:id); END; — the cursors the procedure passes to DBMS_SQL.RETURN_RESULT |
| PostgreSQL, CockroachDB, YugabyteDB, TimescaleDB | SELECT * FROM fn(:id) for a function RETURNS SETOF refcursor, or CALL proc(:id) with INOUT … refcursor parameters |
| OceanBase | CALL proc(:id), as on MySQL |
| TiDB, Vitess, CrateDB, SQLite, Firebird, ClickHouse, DuckDB, Spanner | not supported — none returns more than one set (TiDB and CrateDB have no stored procedures, Vitess cannot prepare a CALL); the node shows a red status |
On PostgreSQL the cursors live only inside the transaction that opened them, so the node runs the
call and a FETCH ALL per cursor between one BEGIN and COMMIT on one connection; a function
that also writes keeps what it wrote, a failure rolls all of it back. Several statements with a
bound value are refused there by the protocol itself, and on MySQL the driver keeps
multi-statement off — only CALL returns sets.
One statement per query
A query runs one statement. UPDATE …; SELECT … is refused with an error before anything runs —
on every database but SQL Server, where a T-SQL batch is a single request by design (the result
is its first SELECT). A trailing ; and comments are fine, and so is a block that is one
statement to its database: a DO $$ … $$, a PL/SQL BEGIN … END;, a trigger body.
Output parameters
A parameter whose source is output reads nothing from the message: the statement writes it,
and the node puts it in msg.output under the parameter's name — next to whatever Result
delivers, result sets included. It needs a declared type, because that is what the driver
receives the value as. The SQL says where each value goes, as any other SQL does:
EXEC :rc = dbo.load_site @siteId = :siteId, @total = :total OUTPUT
With :siteId from msg.payload.siteId, :total an output of type int and :rc an output
of type int:
msg.output = { rc: 0, total: 42 }
- A value is read back exactly as a column of that type is:
BIGINTpast 2⁵³ as text, dates in UTC, binary as aBuffer. One the statement left unset isnull. - On Oracle text and binary outputs stop at 32767 bytes, PL/SQL's own limit for a variable;
a longer
CLOBorBLOBbelongs in aSELECT. - On SQL Server an argument without the word
OUTPUTafter it comes backNULL— the server runs the procedure and says nothing. The SQL Editor marks such a placeholder. - node-red-contrib-mssql-plus put the values in
msg.queryParams[i].valueand the return code inpayload.returnValue(with Driver output); here both aremsg.output.<name>.
INOUT parameters. Tick out beside an input parameter (the SQL Editor: the ⇄ button
beside the source) and it goes both ways: the value comes from its source — msg, flow, global,
env, JSONata, a literal — is checked against the declared type like any input, and what the
statement leaves in it arrives in msg.output.<name>. A declared type is required and governs
both directions.
EXEC dbo.bump @counter = :counter OUTPUT -- SQL Server
BEGIN bump(:counter); END; -- Oracle, counter IN OUT NUMBER
With :counter from msg.payload.counter (7), out ticked, type int: msg.output = { counter: 8 }.
- Every digit and the offset go in: a
datetime2(7)orTIMESTAMP(9), adatetimeoffsetorTIMESTAMP WITH TIME ZONEkeeps what it was written with. - SQL Server's driver sends
decimal,numericandmoneyas a double both ways, so an INOUT value with more than 15 significant digits is refused rather than rounded — send it as a plain input and return the result through an output. - On Oracle an IN OUT value is bound as text or
RAWup to 32767 bytes; a longer one is refused before the call. A PL/SQLTIMESTAMPparameter holds 6 fractional digits — declare itTIMESTAMP_UNCONSTRAINEDfor 9. - Without
OUTPUTafter it, SQL Server never writes an INOUT argument back: what returns is what was sent. The SQL Editor marks it. - PostgreSQL needs no flag: bind the value as a plain input and
CALL proc(:counter)returns the procedure'sINOUT(andOUT) parameters as its row, under the procedure's own parameter names. Mapping that row onto placeholder names would be a guess, so the node refuses out there.
| Database | Output parameters |
|---|---|
| SQL Server | EXEC :rc = dbo.proc @id = :id, @total = :total OUTPUT, or SET :n = (SELECT COUNT(*) FROM t) |
| Oracle | BEGIN proc(:id, :total); END; for OUT parameters, BEGIN :rc := fn(:id); END; for a function |
| PostgreSQL, CockroachDB, YugabyteDB, TimescaleDB, Firebird | not needed — CALL and EXECUTE PROCEDURE return a procedure's output parameters as a row |
| MySQL, MariaDB, OceanBase, Vitess | not supported — OUT parameters land in session variables a pooled connection cannot promise to keep; SELECT them inside the procedure (Vitess cannot prepare a CALL at all) |
| TiDB, CrateDB, SQLite, ClickHouse, DuckDB, Spanner | not supported — no stored procedures |
Where they are not supported the node shows a red status and refuses every message, as it does for an output without a type.
What a database cannot do
Each product carries a table of what it can do (lib/capabilities.js): result sets, output
parameters, and the statements some databases do not have — transaction control, DELETE,
UPDATE, RETURNING. A statement the chosen database cannot run is caught from the SQL text
before anything is sent: the edit dialog lists the product's gaps under the SQL, the SQL Editor
marks the statement, the deployed node shows a red status such as Transactions not supported on
CrateDB and refuses every message with the reason. Today that is CrateDB's transaction control
(it accepts BEGIN and COMMIT and ignores them, and has no ROLLBACK).
Values read back
Rows keep the driver's shape except where that shape loses data — then the same value comes back the same way from every database:
- Exact numbers are a JS number when the double is that number, and text otherwise:
BIGINT42 is42, 9223372036854775807 is"9223372036854775807". MySQL, MariaDB and Oracle used to round those silently (…993 arrived as …992); PostgreSQL'sBIGINTused to be text even for 42.NUMERIC/DECIMALstay text on PostgreSQL, CockroachDB, MySQL and MariaDB; Oracle'sNUMBERfollows the same rule as integers. - Vectors are arrays of numbers (CockroachDB, MySQL, Oracle). TiDB reports a vector column as
plain text, so it arrives as its
[1,2.5]text there. - Binary is a
Buffereverywhere, SQLite included; CLOB is text, not a stream object. - SQLite reads an
INTEGERpast 2⁵³ (which used to fail the whole row) and parses columns declaredJSON. - DuckDB follows the exact-number rule for
BIGINT,HUGEINT, the unsigned integers andDECIMAL;TIMESTAMP_NSarrives as ISO text with all nine digits,±infinityas±Infinity, lists and structs as arrays and objects,JSONparsed.
Two the drivers give no way to fix — cast in the SQL when it matters:
| Database | Column | Arrives as | For the exact value |
|---|---|---|---|
| SQL Server | decimal, money |
a double — 38 digits become 17 | CAST(c AS varchar(50)) |
| SQL Server | json, vector |
text | JSON.parse in the flow |
| MariaDB | vector |
its float32 bytes | VEC_ToText(c) |
Column names
Rows come through exactly as the driver reported them — the package does not rewrite column
names. Note that Oracle reports them in UPPER CASE (FULL_NAME) where the others report what
you wrote (full_name). Moving a flow between the two, alias the columns in the SQL:
SELECT full_name AS "fullName" FROM users
On the canvas
Query nodes carry the database they run against in small type above the node — PostgreSQL,
SQLite — so a node can show both its own name and where it goes. The checkbox under the
database picker on the connection turns that off for every node using it.
SQL Editor
A full-screen editor for every query node in the flow: SQL Editor in Node-RED's status bar, or the button above the SQL in a query node's dialog. Every query node sits in a tree by flow tab; the SQL opens in Monaco (served from this package, no CDN). The gear beside the filter groups the tree by flow tab (default), database, connection or none (one list by name); the filter matches a query's name, flow, connection and database in every grouping.
Pasting SQL from elsewhere converts its placeholders to :name and adds a parameter row
for each new one (on by default; the same gear switches it off, for the node's dialog too):
| Database | Converted | Left alone |
|---|---|---|
| SQL Server | @name, ? |
@@ROWCOUNT, DECLAREd @x, a procedure's own @params, @arg in EXEC p @arg = … |
| PostgreSQL, CockroachDB, YugabyteDB | $1, $2 (same number, same name) |
? (a jsonb operator), @ |
| MySQL, MariaDB, TiDB, Firebird | ? |
@uservar, ?? |
| SQLite | ?, ?NNN, @name, $name |
|
| Oracle | :1, ? |
table@dblink |
| ClickHouse | nothing | ? (the ternary operator) |
Text inside strings, quoted names, comments and $$ bodies is never touched, and only the
pasted text is converted. Positional placeholders take the node's k-th parameter name when the
rest of the SQL does not use it, otherwise p1, p2, …. A note lists what changed; Ctrl/Cmd+Z
gives back the text as pasted (the added rows stay, marked "not in the SQL").
Under the SQL is the Input panel:
- Sample message — type one, or Capture next message to copy the next message the
deployed node receives. Samples stay in this browser (localStorage), never in
flows.json. - Fields — the sample's fields as
msgpaths. Click one to write:nameat the cursor, bound to that field. Typing:offers the node's parameters and the sample's fields. - Parameters — source, declared type and what each resolves to against the sample, with the same check a deployed node runs. A placeholder with no parameter is underlined in the SQL and gets a bind button.
What the database receives shows the compiled statement and its values apart from it.
Nothing runs: the preview uses the functions the node uses (parse, type check, compile), never
a database. flow, global, env and JSONata are read only when the flow runs — env never
reaches the browser.
Edits go onto the node with an undo entry (Ctrl/Cmd+Z), like a dialog save. Done (or Esc) closes the editor, Ctrl/Cmd+S saves without closing; neither deploys — you deploy from Node-RED when you choose. Cancel closes and puts every query back as it was when the editor opened. A sample is optional: a field it lacks is not flagged.
Examples
Import → Examples → @aaqu/fromcubes-db:
- Quick Start → one per database (PostgreSQL, CockroachDB, YugabyteDB, TimescaleDB, CrateDB, MySQL, MariaDB,
TiDB, Vitess, OceanBase, SQL Server, Oracle, SQLite, Firebird, ClickHouse, DuckDB, Spanner) — creates the table
fromcubes_demoon deploy, then buttons insert a row with declared types, read the latest ten and clear the table. Every result goes to the Debug sidebar and to the Node-RED log. The tab's info has thedocker runline for a matching local server and the user to enter (an example cannot carry credentials). - Quick Start → All Databases — the same rows for all seventeen on one tab, driven by four buttons at once; a server that is not running only fails its own row. MariaDB is on 3307 there, beside MySQL.
The Quick Start files are generated by tools/build-examples.mjs from one table of statements, so the combined
flow cannot drift from the single ones; each database's integration suite deploys its own file against a real
server.
- SQL Server Result Sets — a procedure returning three sets read as
msg.payload.site,.cabinets,.ports; the procedure is created on deploy. The SQL Server suite deploys this file against a real server. - SQL Server Output Parameters — a procedure handing back two
OUTPUTparameters, an INOUT page size it clamps, and itsRETURNcode inmsg.output, next to its rows; the procedure is created on deploy. The SQL Server suite deploys this file against a real server. - Select With Parameters — a typed
SELECT, then an auditINSERT(PostgreSQL; edit the connection first). - SQLite Sensor Log With Portal — no server needed. A simulated sensor writes into the SQLite database
sensor-logevery 3 s; a@aaqu/fromcubes-reactpage at/fromcubes/sensor-logshows the rows live, adds a reading and clears the table. A value its declared type refuses goes back to the page that sent it.tests/nodes/examples.test.jschecks every example and runs this one's statements on a real SQLite file.
Connection settings
Pick the database first — the dialog then shows only what that database accepts, instead of expecting you to know each driver's config shape.
| Database | Fields |
|---|---|
| PostgreSQL | SSL mode (off / require / verify CA / verify CA and hostname), CA certificate, schema (search_path), application name |
| MySQL | SSL, verify certificate, allow public key retrieval, charset, timezone |
| SQL Server | encrypt, trust server certificate, named instance, NTLM domain, application name |
| Oracle | host + port + service name, or a full connect string / TNS alias; service name vs SID |
| SQLite | database name (or :memory:), read only, WAL journal, foreign keys, busy timeout |
| DuckDB | database name (or :memory:), read only |
| Spanner | project, instance, database, service-account key (credential), emulator host |
SQLite databases
A SQLite connection names a database, not a file: sensors is
<userDir>/fromcubes-db/sensors.db (usually ~/.node-red/fromcubes-db/). The folder and the file
are created on the first query, and the dialog lists the databases already there, so several
connections can each use their own. Names are letters, digits and . _ -; .sqlite and
.sqlite3 are kept, anything else gets .db. A path is refused, as is a database file replaced by
a link — nothing a connection names can be outside that folder. Back up the folder, back up every
database. Used as a library (below), file is still a plain path of your choosing.
A DuckDB connection names its database the same way: analytics is
<userDir>/fromcubes-db/analytics.duckdb. DuckDB runs inside Node-RED and lets one process hold a
file for writing, so every connection naming the same database shares one DuckDB instance (and
must agree on Read only); close the DuckDB CLI or another Node-RED on that file first.
Pool max is the number of connections to that instance — they run queries in parallel, off
the event loop. The query timeout interrupts the statement.
Spanner
A Spanner connection names a project, an instance and a database (GoogleSQL dialect). The
service-account key — the JSON file from the Google Cloud console, pasted whole — is kept in
Node-RED's encrypted credentials and never logged; left empty, the client uses Application Default
Credentials. Emulator host (localhost:9010) points this connection, and only this one, at
Google's Spanner emulator: no login, and a missing instance or database is created there.
A SELECT runs in a read-only snapshot, INSERT/UPDATE/DELETE in a read-write transaction
committed before the node answers (THEN RETURN rows come back as rows, rowCount is Spanner's
exact count), and CREATE/ALTER/DROP as a schema update — which takes no parameters. A NULL
needs a type on Spanner: declare the column's type on the parameter, or it goes as a STRING.
INT64 past 2⁵³ and NUMERIC arrive as text, a TIMESTAMP with more than milliseconds as ISO
text with all nine digits.
User and password
Each is either a value — kept in Node-RED's encrypted credentials, outside the flow file, so an exported flow never carries it — or the name of an environment variable, read when the node starts:
| Source | What you type | Where it lives |
|---|---|---|
value (default) |
the user / the password | encrypted credentials file |
environment variable |
POSTGRES_PASSWORD |
the process, group or flow env |
The variable is for a flow built before the login it will use exists — an image that ships to a
device provisioned with its own password, handed to the container through --env-file. The
variable name is a normal setting and does travel in an exported flow; the value never does,
because it is the device's rather than the flow's.
The name is resolved the way every other environment reference in Node-RED is, so a variable set
on the group or the enclosing flow is found before the process one. Unset when the node starts is
a hard stop: the node logs an error, shows red, and no pool is built — a login that is silently
undefined would otherwise surface much later as the server's own authentication failure.
The two sources are independent; a fixed user with the password from the environment is the usual pairing. Leaving both alone is what every existing flow does, and it behaves as it always has.
Advanced stays as the escape hatch: JSON in the shape the driver's own documentation uses, merged key by key over the fields above. Adding one option does not discard the rest.
{ "keepAlive": true }
Connection handling
A Node-RED redeploy tears every node down and builds it again. Without care that leaves open sockets behind until the server runs out of connections. What this package does:
- One pool per connection node, living exactly as long as that node. Ten query nodes on one connection share one pool; a deploy of modified nodes that replaces or deletes every query node leaves it open. When the connection node is redeployed, the new pool connects only after the old one closed — never two at once — and queries sent meanwhile wait instead of failing.
- Lazy connect — an unused connection node costs nothing.
- Drain on close: in-flight queries are awaited (up to 10 s, under Node-RED's 15 s limit),
then the pool closes and
done()is called. - Bounded queue: the node admits at most
poolMaxqueries at a time and lets at mostqueueMaxwait. Past that they fail withQueueOverflowErrorinstead of piling up in memory. This is enforced here rather than left to the driver —pghas no queue limit at all, andmssqlandnode:sqlitehave none either. - Timeouts: applied by the driver where it supports them (
statement_timeout,requestTimeout,callTimeout) plus a hard stop in the node. - Backoff on failure, evaluated when a query arrives rather than on a background timer — a stray timer is exactly what survives an unload.
- No listener build-up: every
pool.on('error')and status subscription is removed on close.
Errors
Failures go through done(), so a Catch node picks them up. Constraint violations get the
same type whichever database raised them:
UniqueViolationError, ForeignKeyViolationError, NotNullViolationError,
CheckViolationError, ConnectionError, TimeoutError, QueueOverflowError,
PoolClosedError, ParameterError, SqlSyntaxError, QueryError, and ResultSetCountError
(a QueryError: the statement returned a different number of result sets than the node names;
err.expected and err.actual hold both counts).
The native code stays available on err.driverCode (SQLSTATE, ORA- number, SQL Server number). In a flow
it is msg.error.cause.driverCode: the Catch node copies only message, code, stack and cause into msg.error.
A message names parameters the way the SQL does. Drivers speak of the placeholder they were handed —
$2 on PostgreSQL, CockroachDB and YugabyteDB, @p2 on SQL Server, :p2 on Oracle, {p2:…} on
ClickHouse, a position on SQLite — so could not determine data type of parameter $2 reaches the
flow as … parameter :total (an item of a :...ids list as :...ids[1]). The driver's own words
stay on err.driverMessage (in a flow, msg.error.cause.message). MySQL, MariaDB, TiDB and Firebird bind ? and name no parameter in
their messages, so theirs arrive unchanged. Errors from the node's own type checks were already
written as Parameter :total — ….
Using it outside Node-RED
The core is a plain module:
const { ManagedPool } = require('@aaqu/fromcubes-db');
const pool = new ManagedPool({
dialect: 'postgres',
host: 'localhost',
database: 'app',
user: 'app',
password: '...',
});
const { rows, columns } = await pool.query('SELECT * FROM users WHERE id = :id', { id: 5 });
// columns: [{ name: 'id', type: 'int4' }, …] — also when rows is empty
await pool.close();
Driver settings go in options, merged over the package's own defaults — on PostgreSQL, for
instance, options: { application_name: 'reports' } replaces the default fromcubes-db:
new ManagedPool({ dialect: 'postgres', host: 'localhost', database: 'app', options: { application_name: 'reports' } });
Development
From the monorepo root (fromcubes-modules):
npm test # every package: parser, compiler, pool, and the nodes through node-red-node-test-helper
npm run test:integration # real databases in Docker (testcontainers)
npm run lint && npm run format:check
Integration tests start one container per database (images in tests/integration/images.js;
FCDB_IMAGE_MYSQL=mysql:8.4 and the like swap one). CI runs the newest line of each product and
the older ones still widely used — PostgreSQL 15, CockroachDB 25.4, YugabyteDB 2025.2, MySQL 8.4
and 9.7, MariaDB 10.11, 11.4, 11.8 and 12.3, TiDB 8.1, SQL Server 2022, Firebird 4.0, ClickHouse
26.8, 26.3 and 25.8 — where types a version lacks (MySQL VECTOR before 9.0,
SQL Server json before 2025) are skipped, and the picker marks them 9.0+ — SQLite and DuckDB need none, they run against a temp
file. SQL Server is amd64-only and runs under emulation on Apple Silicon; the Oracle image is
large and slow on first pull.
All seventeen products run the same contract suite: binding and injection, spread lists, nulls and
empty strings, unicode, dates, binary, decimals, booleans, generated keys, and the fact that each
statement commits on its own. It also creates a column of every type in lib/sql/types.js on the
running server — 62 on ClickHouse, 54 on PostgreSQL, YugabyteDB and TimescaleDB, 43 on MariaDB, 39 on
MySQL, Vitess and OceanBase, 38 on CockroachDB, 36 on SQL Server, 31 on TiDB, 20 on CrateDB, 28 on Oracle, 23 on Firebird, 11 on SQLite, 38 on DuckDB, 11 on Spanner — so the picker cannot offer a type the database does not
have — then binds a value of each type through its declaration, reads it back and compares, sends
every catalogued limit (which must land) and the value just past it (which must be refused). And it reads each server's own list of its types (pg_type, sys.types, dba_types, MySQL's HELP tables, RDB$TYPES, system.data_type_families, duckdb_types()): every type listed there must be catalogued or left out with a written reason, and every alias must be stored by the server as the type it claims to be. On top of that, flow.test.js deploys real Node-RED nodes against a
real server and counts connections through pg_stat_activity — including across restarts — and
tests/nodes/startup.test.js starts a 222-node flow with sixteen unreachable servers and a DuckDB file to prove that
start-up never waits for a database.
GitHub Actions runs them on every push and pull request touching the package, one job per
database (.github/workflows/db-integration.yml).
npx vitest run --project db-integration packages/fromcubes-db/tests/integration/sqlite.test.js # one dialect
To try it in a real editor:
cd ~/.node-red && npm install /path/to/fromcubes-modules/packages/fromcubes-db && node-red
License
Apache-2.0 — see LICENSE and NOTICE.
The node icon is the "database" icon from Lucide, used under the ISC
License. Its required notice is reproduced in THIRD-PARTY-NOTICES.md.