@aaqu/fromcubes-db
Query PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, CockroachDB, YugabyteDB, TimescaleDB, CrateDB, TiDB, Vitess, OceanBase, Firebird, ClickHouse, DuckDB and Spanner from Node-RED. You write the SQL; values are always bound as parameters — so no message can change what a statement does.
Step one
Install
In the editor: menu → Manage palette → Install, then search for
@aaqu/fromcubes-db. Or from a terminal:
cd ~/.node-red
npm install @aaqu/fromcubes-db
Restart Node-RED. Two nodes appear in the palette, db query under fromcubes:
- db query — the node you drop on a flow.
- db connection — a configuration node holding the connection. You create it from inside the query node, and several query nodes can share one.
Every driver ships with the package: nothing else to install, nothing to compile. Oracle runs in Thin mode, so
no Oracle Instant Client is needed, and SQLite uses node:sqlite from Node itself. The package wants
Node 24 or newer and Node-RED 5 or newer — the combination its test suites run against.
| Your database | Choose in the dialog | Usual port | Driver today |
|---|---|---|---|
| PostgreSQL | PostgreSQL | 5432 | pg |
| CockroachDB | CockroachDB | 26257 | pg |
| YugabyteDB | YugabyteDB | 5433 | pg |
| TimescaleDB | TimescaleDB | 5432 | pg |
| CrateDB | CrateDB | 5432 | pg |
| MySQL | MySQL | 3306 | mysql2 |
| MariaDB | MariaDB | 3306 | mysql2 |
| TiDB | TiDB | 4000 | mysql2 |
| Vitess | Vitess | 3306 | mysql2 |
| OceanBase | OceanBase | 2881 | mysql2 |
| Microsoft SQL Server | Microsoft SQL Server | 1433 | mssql |
| Oracle | Oracle | 1521 | oracledb |
| SQLite | SQLite | — it is a file | node:sqlite |
| Firebird | Firebird | 3050 | node-firebird |
| ClickHouse | ClickHouse | 8123 (HTTP) | @clickhouse/client |
| DuckDB | DuckDB | — a file, in process | @duckdb/node-api |
| Spanner | Spanner | gRPC (emulator 9010) | @google-cloud/spanner |
Example flows come with the package — menu → Import → Examples → @aaqu/fromcubes-db.
Quick Start holds one for every database: it creates the table fromcubes_demo on
deploy, and buttons insert a row, read the latest ten and clear it, with every result in the Debug sidebar and
the Node-RED log. Each tab's info has the docker run line for a matching local server.
All Databases puts the same rows for all seventeen on one tab.
SQLite Sensor Log With Portal needs no server at all: a simulated sensor writes into the SQLite
database sensor-log every three seconds, and a page at /fromcubes/sensor-log (built
with @aaqu/fromcubes-react) shows the rows live, adds a reading and clears the table. A value the
declared type refuses comes back to that page as a message instead of disappearing.
Each database is its own entry, not a shared one: CockroachDB, YugabyteDB, TimescaleDB and CrateDB are not filed under PostgreSQL, and MariaDB, TiDB, Vitess and OceanBase are not filed under MySQL. Two of them run on the same driver today, which is a fact about today — picking the one you actually run means the day it needs its own handling, your flows already say so.
Five minutes
Your first query
Reading one user by id, from an inject node to a debug node.
-
Drop a db query node
Drag db query onto the canvas and double-click it.
-
Create the connection
The dialog has two tabs: Query for the statement and its parameters, Connection for where it runs and what comes back. On the Connection tab, click the pencil next to Connection. Choose your database first — the rest of that dialog then shows only the settings that database accepts. Fill in host, port, database, user and password, then Add.
The user and password go into Node-RED's encrypted credential file, never the flow file, so an exported flow carries no secrets. If the login only exists on the machine that will run the flow, switch either of them to environment variable and name it instead — see User and password.
The connection dialog shows only the settings the chosen database accepts. -
Type the SQL
Write the statement with
:namewherever a value belongs:SELECT id, name, email FROM users WHERE id = :id -
Point each placeholder at a value
Add a row per placeholder under Parameters. Each row is a standard Node-RED typedInput, so it can read from
msg,flow,global,env, a JSONata expression, or hold a literal. The last box declares the expected type. The hint under the list names every placeholder still without a value, and every value no placeholder uses.: id msg. payload.userId integer
SQL with :nameplaceholders above, one parameter row per placeholder below. -
Wire it up and deploy
inject → db query → debug. Rows arrive on
msg.payloadwithmsg.rowCountbeside them. The node's status reads1 rowin green, or shows the error in red.A filled dot is always this node's own doing. A hollow ring is the connection it shares: add a second query node on the same connection and both will show
connectedas soon as either one opens it, since they share a single pool.
Pick the result shape. On the Connection tab, the
Result select decides what lands on msg.payload: all rows as an array, the first
row only, the affected row count, one message per row, or every result set of a
stored procedure. The box beside it names the message property, with the msg. already spelled out
in front of it.
Values read back
Rows keep the driver's shape unless that loses data. An exact number is a JS number when the double
is that number and text otherwise — BIGINT 42 is 42, 9223372036854775807 is
"9223372036854775807", where MySQL, MariaDB and Oracle used to round it silently. Vectors are
arrays of numbers, binary is a Buffer everywhere, an Oracle CLOB is text, and SQLite reads an
INTEGER past 253 and parses columns declared JSON.
Two the drivers cannot be made to read exactly: SQL Server's decimal and money arrive
as doubles (cast to varchar in the SQL for every digit) and its json and
vector as text; MariaDB's vector as its bytes (VEC_ToText(c)).
Reference
Writing queries
Two forms. :name binds one value; :...name spreads an array into a list for
IN.
SELECT * FROM users WHERE id = :id AND name = :name
You never write those forms yourself — :name works everywhere. It also means the same query node
keeps working if you point it at a different database.
Why a value cannot break the query
The SQL sent to the server depends only on what you typed. Put
'; DROP TABLE users; -- into :name and the statement does not change by a byte: the
string is looked up as a name, matches nothing, and the table is untouched.
Placeholders inside string literals, comments and quoted identifiers are left alone, so
created::text stays a Postgres cast and [order:1] stays a SQL Server column name.
Lists
SELECT * FROM users WHERE id IN (:...ids)
Give ids an array and each element is bound separately. An empty array becomes
IN (NULL) — valid SQL matching nothing, rather than a syntax error.
Use a plain :name when the value is an array, such as a Postgres
text[] column. The spread form is spelled out precisely so both stay possible.
Reference
Parameter types
Left on auto, a value is bound as it arrives. Set a type and it is checked first — so a malformed
message fails naming the parameter, instead of arriving as a database error about a column you never mentioned.
| Type | Accepts | Rejects |
|---|---|---|
string |
strings, numbers, booleans, Dates (stored as ISO) | objects — use json |
numberinteger |
numbers and numeric strings ("42" → 42) |
"abc", NaN, Infinity, booleans |
boolean |
true/false, "yes"/"no",
"on"/"off", 1/0
|
"maybe", 2 |
date |
a Date, an ISO string, an epoch number | anything unparseable |
json |
objects, arrays, or a JSON string (parsed first) | invalid JSON |
buffer |
Buffer, Uint8Array, base64 string | numbers |
On a spread parameter the check runs per element and names the one that failed:
Parameter :ids[1] — expected an integer, got string "x"
null passes through as SQL NULL whatever the type. A missing value is an error by default
— a typo in msg.payload.usreId should not quietly become WHERE id IS NULL. Tick
Bind missing parameters as NULL
on the connection for the opposite behaviour.
Column types
Below those six the select also lists the column types of the database this node's connection points at, with a
small field beside it for the length or precision: varchar + 50,
numeric + 10,2. The value is then checked against that type as the product defines it.
Nothing about the declaration reaches the SQL text — it is read before binding and nowhere else.
| Declared | On | Means |
|---|---|---|
varchar(50) |
PostgreSQL, MySQL, MariaDB, CockroachDB, YugabyteDB, TiDB | 50 characters |
varchar(50) |
SQL Server | 50 bytes — 'ółć' is six of them |
nvarchar(50) |
SQL Server | 50 UTF-16 units |
varchar2(50) |
Oracle | 50 bytes; write varchar2(50 char) for characters |
tinyint |
MySQL | −128…127, or 0…255 with unsigned |
tinyint |
SQL Server | 0…255 |
Length is only the visible half. The same check holds integers to their range, counts the digits a
decimal(10,2) has room for, and knows that datetime on SQL Server begins in 1753 while
MySQL's TIMESTAMP ends in 2038 — the sort of limit a flow meets years after it was written. Where a
type has a shape rather than a size, the shape is what is checked: uuid, inet,
macaddr, bit, ranges, SQL Server's time. A fraction the column rounds
away is checked as rounded: 03:14:07.6 into MySQL's TIMESTAMP is
03:14:08, one second past the end.
Vectors are a column type on CockroachDB, MySQL 9, MariaDB 11.7+, TiDB 8.4+, SQL Server 2025
and Oracle 23ai+. Declare vector + 3, or 3, float32 where the product has
storage formats (SQL Server, Oracle); send an array of numbers, a typed array or its JSON text. A declared
length has to match exactly.
The declared type also picks how the value is bound, because the drivers' own guesses corrupt rather than fail:
SQL Server's sends every Date as the legacy DATETIME (1/300 s, nothing before 1753),
pg turns a JSON array into a PostgreSQL array, and oracledb reads any object as a bind
definition — so on Oracle an object always travels as JSON, declared or not.
Dates are UTC. 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 run in UTC (Oracle
with ISO date formats, so a nine-digit timestamp kept as text lands as written). 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. MySQL's Timezone field can still say
local for tables other programs fill in local time.
Big numbers survive. A JavaScript double carries fifteen reliable digits;
bigint holds nineteen and Oracle's NUMBER thirty-eight.
Number('9223372036854775807') does not fail — it returns 9223372036854776000, and
the row lands with an id nobody sent. So a BigInt stays a BigInt and a numeric string stays a string, both of
which every driver here binds, and the range check compares in BigInt rather than in doubles.
SQLite is the one to know about: it accepts VARCHAR(5) and then stores anything at all in it. The
length check there is this node's, not the database's — which is the reason it is worth having.
column-types.md lists where each product documents its types and every limit collected from it. The integration suite creates a column of every type in the catalogue on a real server — 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, the Spanner emulator — binds a value of each through its declaration and reads it back, and sends every limit (which must land) and the value just past it (which must be refused). A name in the picker is a name the database has, and a limit in the check is the server's.
It also asks each server for its own list of types — pg_type, sys.types,
dba_types, MySQL's HELP tables — and fails on any type there the catalogue has not either taken in
or left out for a written reason, and on any alias the server stores as something else. That is how MariaDB's
int1…int8 and national varchar spellings got in, and MySQL's
geomcollection came out of MariaDB, which refuses it.
The same suite runs on the older lines still widely used — PostgreSQL 15, CockroachDB 25.4, MySQL 8.4 and 9.7,
MariaDB 10.11, 11.4, 11.8 and 12.3, SQL Server 2022. The picker lists the newest catalogue and marks what an
older server has not got with the version that brought it: vector(n) — 9.0+ on MySQL,
json — 2025+ on SQL Server. MariaDB's TIMESTAMP reaches 2106 only from 11.5; before
that it ends in 2038.
Editor
SQL Editor
SQL Editor in Node-RED's status bar opens every query node of the flow in one full-screen editor — or use the button above the SQL in a query node's dialog. The tree on the left lists the query nodes by flow tab; the SQL opens in Monaco, served by this package. The gear beside the filter groups the tree by flow tab (the default), database, connection or none — one list by name. The filter matches a query's name, flow, connection and database whichever grouping is on.
Pasted SQL keeps working. Paste a statement written for another tool and its placeholders
become :name, each new one with a parameter row: @name and ? on SQL
Server, $1 on PostgreSQL, CockroachDB and YugabyteDB, ? on MySQL, MariaDB, TiDB and
Firebird, ?/?NNN/@name/$name on SQLite, :1 and
? on Oracle. What is not a placeholder where it stands is left alone: strings, quoted names,
comments, $$ bodies, :: casts, @@ROWCOUNT, a DECLAREd
@x or a procedure's own @params, the @arg in
EXEC p @arg = …, MySQL's @uservar, PostgreSQL's ? jsonb operator and
ClickHouse's ? ternary. Positional placeholders take the node's k-th parameter name when nothing
else uses it, otherwise p1, p2, …. A note says what changed and
Ctrl/Cmd+Z gives back the pasted text. It works in the node's dialog too; switch it off under the
gear.
Below the SQL sits Input: a sample message (typed, or captured from the next message the
deployed node receives), its fields, and the parameters. Click a field to write :name at the cursor
bound to that field; type : for the node's parameters and the sample's fields. Each parameter shows
what it resolves to against the sample and whether its declared type accepts it — the same check the node runs
on deploy. A placeholder without a parameter is underlined in the SQL.
What the database receives shows the compiled statement and the values sent apart from it.
Nothing runs against a database. Values from flow, global, env and
JSONata are read only when the flow runs; environment variables never reach the browser. Samples stay in your
browser, never in flows.json.
Edits land on the node with an undo entry (Ctrl/Cmd+Z), exactly as a dialog save would. Done (or Esc) closes the editor and keeps everything; 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. The sample is optional — a field it lacks is not flagged, since the message the flow sends may look different.
How do I…
Recipes
Insert and get the new id back
Ask the database for it in the same statement, then set Result to first row only:
| Database | Statement |
|---|---|
| PostgreSQL CockroachDB YugabyteDB SQLite MariaDB 10.5+ |
INSERT INTO users (name) VALUES (:name) RETURNING id |
| SQL Server | INSERT INTO users (name) OUTPUT INSERTED.id VALUES (:name) |
| MySQL, TiDB |
Has no RETURNING — read msg.insertId instead, which the driver reports with
the insert itself.
|
| Oracle |
RETURNING INTO needs output binds, which this node does not support. See the warning below.
|
On MySQL, MariaDB and SQLite the generated key also arrives as msg.insertId after an
INSERT. It comes back in the same result as the insert, over the same connection, so it really is
the row you just created. It is left off entirely for other statements and other databases, rather than being
reported as a plausible-looking 0.
What you must not do — on any database — is follow the insert with a second query node
reading LAST_INSERT_ID() or CURRVAL. Those are per-session values, and the second
query may take a different connection from the pool and hand you someone else's id. On Oracle, use a key you
already know or generate a UUID in the flow.
Update only if something still matches
Set Result to affected row count and branch on it:
UPDATE orders
SET status = :status
WHERE id = :id AND status = :expected
msg.payload is 0 when nothing matched — how you detect a lost race without reading the
row first.
Optional filters in one statement
Instead of building different SQL per combination, let the database skip a filter whose parameter is NULL:
SELECT * FROM users
WHERE (:name IS NULL OR name = :name)
AND (:status IS NULL OR status = :status)
ORDER BY id
Search with a wildcard
Put the wildcard in the value, not in the SQL — either way it stays data:
SELECT * FROM users WHERE name LIKE :pattern
Then set that parameter to a JSONata expression such as
payload.query & "%".
Page through a large table
SELECT id, name FROM users
ORDER BY id
LIMIT :limit OFFSET :offset
SQL Server and Oracle spell it OFFSET :offset ROWS FETCH NEXT :limit ROWS ONLY.
Fan a result set out
Set Result to one message per row. Each message is a clone, so a downstream node changing one row cannot corrupt the others.
Read several result sets from one procedure
A stored procedure that returns several SELECTs — ordinary on SQL Server — is read by one node. 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
SQL in the node: EXEC dbo.load_site @siteId = :siteId, Set names:
site, cabinets, ports. The message that comes out:
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, or the message fails with
ResultSetCountError—expected 13 result sets (cabinets…controlCabinets), got 12— rather than putting each later set under its neighbour's name. Names are JavaScript identifiers, each used once. -
Empty sets keep their place, and every set is read like a single result: a
BIGINTpast 253 as text, binary as aBuffer, dates in UTC. -
OUTPUTparameters and the procedure'sRETURNvalue arrive inmsg.output— see output parameters.
| Database | How a statement returns several sets |
|---|---|
| SQL Server | EXEC dbo.proc @id = :id — every SELECT in the procedure, or in a batch of SELECTs. |
| MySQL, MariaDB, OceanBase | 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. The node reads every cursor
inside the one transaction that opened it.
|
| 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 option is hidden for these connections, and a node set to it
shows a red status.
|
Import → Examples → SQL Server Result Sets creates such a procedure on deploy and reads it.
Read a procedure's output parameters
Give a parameter the source output: it 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.
It needs a declared type, which is what the driver receives the value as.
EXEC :rc = dbo.load_site @siteId = :siteId, @total = :total OUTPUT
With :total and :rc both outputs of type int, the message leaves with
msg.output = { rc: 0, total: 42 }.
-
Values are read like a column of the same type: a
BIGINTpast 253 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. -
SQL Server returns an argument only when
OUTPUTfollows it — without the word the value comes backNULL, silently. The SQL Editor marks such a placeholder. -
Coming from node-red-contrib-mssql-plus:
msg.queryParams[i].valueandpayload.returnValueare bothmsg.output.<name>here.
INOUT parameters. Tick out beside an input parameter (in 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>. The 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
-
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. -
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'sINOUTandOUTparameters as its row, under the procedure's own parameter names. Mapping that row onto placeholder names would be a guess, so out is refused 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 them as a row. |
| MySQL, MariaDB, TiDB, Vitess, OceanBase, CrateDB, SQLite, ClickHouse, DuckDB, Spanner |
Not supported — MySQL keeps OUT parameters in session variables a pooled connection cannot promise to
keep (SELECT them inside the procedure instead); the others have no procedures. The node
shows a red status.
|
Import → Examples → SQL Server Output Parameters creates such a procedure on deploy and reads its outputs, an INOUT page size it clamps, and its RETURN code.
Handle failures
Add a Catch node scoped to your query nodes. Failures arrive as msg.error with a
recognisable name — see below.
Reference
Connection settings
The dialog asks for what the chosen database accepts, so you do not have to know each driver's configuration format.
| Database | Settings |
|---|---|
| PostgreSQL | SSL mode, CA certificate, schema (sets search_path), application name |
| MySQL MariaDB |
SSL, verify certificate, 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 (kept as a credential), emulator host |
SQLite takes a name, not a path. sensors is
<userDir>/fromcubes-db/sensors.db — usually ~/.node-red/fromcubes-db/ — and the
folder and file are created on the first query. The field lists the databases already there, so each connection
can name its own and the same flow finds the same file however Node-RED was started. Names are letters, digits
and . _ -; a path, or a database file replaced by a link, is refused. Back up that one folder and
every database is in it.
DuckDB names its database the same way — analytics is
<userDir>/fromcubes-db/analytics.duckdb — and runs inside Node-RED. DuckDB 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. Its driver is a
prebuilt binary (Linux x64/arm64, macOS, Windows). Where there is none, only DuckDB connections fail, with
DuckDB is not available on this platform (…).
Spanner takes a project, an instance and a database. The service-account key (the JSON from the
Google Cloud console) is kept in Node-RED's encrypted credentials and never logged; empty means Application
Default Credentials. With Emulator host set, that one connection talks to Google's Spanner
emulator — no login, and a missing instance or database is created there. A SELECT reads a
snapshot, DML runs in a committed read-write transaction (THEN RETURN rows come back), DDL is a
schema update without parameters. A NULL needs a type: declare it on the parameter.
All of them also carry pool size, connect / query / idle timeouts and a queue limit. The defaults suit a flow doing a few queries a second; raise Pool max if you run many at once.
Pool max is a hard ceiling on connections to the server, and Queue limit caps
how many queries may wait for one. Past that they fail with QueueOverflowError rather than
accumulating in memory — the limit is applied by the node, so it means the same thing on every database,
including the ones whose own driver has no such setting.
Query timeout covers the whole wait, queueing included, and is a ceiling: a per-node timeout can lower it but not raise it, because on PostgreSQL and Oracle it is applied to the connection itself.
About SSL. require encrypts the connection but does not check the certificate —
it stops passive sniffing, not someone able to redirect your traffic. Only verify-full protects
against that. On SQL Server the equivalent is leaving Trust the server certificate unticked.
User and password
Each of the two is either a value — kept in Node-RED's encrypted credential file, outside the flow file, so an exported flow carries no secret — or the name of an environment variable, read when the node starts. Pick the source next to the field; when it is a variable, you type the name, not the value.
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 name is
a normal setting and does travel in an exported flow; the value never does, because it belongs to the device
rather than to the flow.
Names are 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. If it is unset when the node starts, the node stops there — an error, a red status and no pool — instead of connecting with an empty password and failing later in the server's own words. The two are independent: a fixed user with the password from the environment is the usual pairing.
On the canvas
Every query node using a connection carries that database's name in small type above the node —
PostgreSQL, SQLite — so a node shows both the name you gave it and where it goes. The
checkbox under the database picker turns that off for every node on that connection.
Advanced
For anything no field covers, Advanced takes JSON in the shape the driver's own documentation uses. It merges over the fields above, so adding one option does not discard the rest.
{ "keepAlive": true }
Reference
Errors
Every failure reaches a Catch node. The same problem gets the same name whichever database reported it, so one switch node covers all nine:
| msg.error.message begins with | Means |
|---|---|
UniqueViolationError |
Duplicate key — the row already exists. |
ForeignKeyViolationError |
A referenced row is missing, or something still references this one. |
NotNullViolationError |
A required column got NULL. |
CheckViolationError |
A CHECK constraint rejected the value. |
ParameterError |
A parameter is missing or the wrong type. The query never ran. |
SqlSyntaxError |
The SQL in the dialog could not be parsed — an unclosed quote or comment. |
ConnectionError |
Server unreachable, or credentials rejected. |
TimeoutError |
The query ran past its timeout. |
PoolClosedError |
A message arrived while the flow was being redeployed. |
ResultSetCountError |
The procedure returned a different number of result sets than the node names. A kind of
QueryError; msg.error.expected and .actual hold the two counts.
|
QueryError |
Anything else the server rejected. |
The original driver error is on msg.error.cause, for when you need the detail, and the database's
own code with it on msg.error.cause.driverCode — a SQLSTATE, an ORA- number, a SQL
Server number. (The Catch node copies only message, code, stack and
cause into msg.error; err.driverCode is there for use outside Node-RED.)
A message names parameters the way your 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 arrives as … parameter :total (an item
of a :...ids list as :...ids[1]). The driver's own words stay on
msg.error.cause.message (err.driverMessage outside Node-RED). MySQL, MariaDB, TiDB and
Firebird name no parameter in their messages, so theirs arrive unchanged.
When it does not work
Troubleshooting
The SQL uses :name but no parameter row supplies it, or the row points at a property the
message does not have. Open the node — the hint under the parameter list names every placeholder without a
value, and every value no placeholder uses.
The query node has no connection selected. Common after importing a flow without its configuration node — open the node and pick or recreate the connection.
A local or containerised server using its own certificate. On SQL Server tick
Trust the server certificate; on PostgreSQL set SSL to require. Both give up
protection against redirected traffic — use them on a trusted network only.
SQLite support uses node:sqlite, which older Node releases do not carry. The package asks for
Node 24 or newer anyway, so this message means Node-RED is running on something older than the package
supports — upgrade Node.
The identifier is a SID, not a service name. Switch Identifier is to SID, or choose full connect string and paste the descriptor.
That is Oracle folding unquoted identifiers to upper case. Rows are passed on exactly as the driver reports
them — nothing is renamed behind your back. Alias the columns for a fixed shape:
SELECT full_name AS "fullName".
Deploying reloads flows, not node code. After upgrading the package restart Node-RED, then reload the editor with a hard refresh so the browser picks up the new dialog.
Before you commit to it
What this package will not do
These are deliberate choices rather than missing features, but they are the things most likely to send you elsewhere — so they are stated plainly rather than buried.
A statement the database cannot run is refused up front
Each database carries a list of what it can do: result sets, output parameters, and statements some of them do
not have — transaction control, DELETE, UPDATE, RETURNING. The edit
dialog lists the chosen database's gaps under the SQL, the SQL Editor marks the statement, and a deployed node
shows a red status such as Transactions not supported on CrateDB and refuses every message with the
reason, before anything reaches the server. CrateDB, for one, accepts BEGIN and
COMMIT and ignores them, and has no ROLLBACK.
SQL cannot come from a message
There is no “run msg.topic as SQL” option. That switch is precisely how injection reaches a
Node-RED flow, and leaving it out is what makes the guarantee on this page true. Queries whose
shape varies — a column chosen at runtime, an optional ORDER BY — need either separate
query nodes behind a switch node, or the NULL-guard pattern from the recipes.
Table and column names cannot be parameters in any database, in any library. If you truly need a dynamic one, choose it from a fixed list in a function node and route to the matching query node.
No transactions across nodes
Each query node runs its statement on its own and commits. Two query nodes in a row are two independent transactions: if the second fails, the first is not rolled back. Where you need atomicity, do the work in one statement, or in a stored procedure the node calls.
One statement per node
A query node runs a single statement. Multi-statement batches are not supported, and on MySQL they are disabled at the driver. A stored procedure that returns several SELECTs is one statement — read it with result sets.
No streaming of huge results
A result set is read fully into memory before the message is sent. Page with
LIMIT / OFFSET for tables larger than your memory.
SQLite blocks while it runs
node:sqlite is synchronous, so a SQLite query holds the Node-RED event loop until it finishes. Fine
for local data, wrong for a multi-gigabyte table. The other six databases are fully asynchronous.
Operations
Redeploying is safe
A redeploy destroys and rebuilds every node. A careless database node leaves its connections open each time, until the server refuses new ones — and the failure shows up hours after the deploy that caused it.
What happens here instead:
- Ten query nodes sharing one connection open one pool, not ten.
- A connection nothing uses never connects at all.
- The pool belongs to the connection node and lives exactly as long as it does. Deploying only modified nodes, replacing or deleting every query node on a connection, or importing other flows leaves it open and connected.
- When the connection node itself is redeployed, queries in flight are awaited, then the pool closes — inside Node-RED's own timeout — and the new pool connects only after the old one has closed, so one connection node never holds two pools. Queries sent meanwhile wait (within their timeout) rather than fail.
- If the server goes away, reconnection backs off instead of hammering it, and every node on that connection turns red with the reason — without waiting for a message to find out.
- Under overload, queries fail with a clear error rather than queueing until memory runs out.
Tests hold it to that. One loads and unloads a flow twenty times and asserts twenty pools opened, twenty closed,
nothing left behind. Another starts a 222-node flow spread over all seventeen databases with none of them
reachable, and requires start-up to be immediate — pools connect on the first query, never at deploy. A third
deploys the real nodes against a real PostgreSQL and counts the server's own
pg_stat_activity across five restarts, because our own counters cannot prove the server got its
connections back. And one replaces nodes every way Node-RED does — modified nodes, modified flows, a full
deploy, Restart flows, an imported tab, deleted query nodes, the connection changed mid-query — and counts the
pools open at once: never two for one connection, never a closed one under a running node.
Beyond the editor
Using it outside Node-RED
The nodes are a thin layer over a plain module, usable from any Node.js code:
const { ManagedPool } = require('@aaqu/fromcubes-db');
const pool = new ManagedPool({
dialect: 'postgres',
host: 'localhost',
database: 'app',
user: 'app',
password: process.env.DB_PASSWORD,
});
const { rows } = await pool.query(
'SELECT * FROM users WHERE id = :id',
{ id: 5 },
);
await pool.close();
Same rule: the first argument is SQL, the second is values, and they never meet as text.
Legal
Licence
Apache-2.0. Full text in LICENSE, notices in NOTICE.
The node icon pairs the fromcubes cube with the database icon from
Lucide, used under the ISC License and recoloured for the palette. ISC requires
its notice to travel with every copy, so the full text ships in THIRD-PARTY-NOTICES.md.
The database drivers are ordinary npm dependencies, each under its own licence.