skaidb — Node.js / TypeScript driver
Repository: github.com/porcupin26/skaidb-node — this page is the driver's README at
v1.5.2; the repository also holds its docs, examples and changelog. Install:
npm install @skaidb/client
The official skaidb driver for Node.js. The API is
modeled on node-postgres (pg): new Client(…),
await client.query(…), { rows, rowCount, fields }. Zero dependencies
(pure net, tls, crypto), one file, TypeScript declarations included.
- Node.js 18 or newer, CommonJS (
require) and ESM/TypeScript (import) both work. - Speaks skaidb's binary protocol directly: SCRAM-SHA-256 auth, server-side prepared statements with typed parameters, streaming result sets, one-round-trip batches, full type fidelity (bigint, Decimal, UUID, Bytes, Timestamp, Array, Document).
- Multi-seed failover, transparent reconnect, TLS, connection pooling balanced across the cluster's members (policies, health ejection, discovery).
- Transactions: a
transaction()helper that runs again when the server refuses theCOMMITfor a conflict, and a typed error for that refusal.
Full documentation: this README, the docs/ folder
(getting started · API reference ·
types and TypeScript), runnable examples/, the
wire protocol specification and the
skaidb documentation.
Install
npm install @skaidb/client
The package is @skaidb/client on the npm registry and is required as
@skaidb/client. To install straight from GitHub instead, pin a tag with
npm install github:porcupin26/skaidb-node#v1.5.2 (#main follows the
development branch); the module name is the same whatever the install
source.
Quick start
const { Client } = require('@skaidb/client');
const client = new Client({
host: 'localhost', port: 7000,
user: 'skaidb', password: 'secret',
});
await client.connect();
await client.query('CREATE TABLE users (PRIMARY KEY (id))');
await client.query('INSERT INTO users (id, name) VALUES ($1, $2)', [1, 'Ada']);
const res = await client.query('SELECT id, name FROM users WHERE id = $1', [1]);
console.log(res.rows); // [ { id: 1, name: 'Ada' } ]
console.log(res.rowCount); // 1
await client.end();
TypeScript:
import { Client, QueryResult } from '@skaidb/client';
interface User { id: number; name: string }
const client = new Client({ seeds: ['db1:7000', 'db2:7000'], user: 'app', password: 'secret' });
await client.connect();
const res: QueryResult<User> = await client.query<User>('SELECT id, name FROM users');
Connecting
new Client({
// Where. Either host/port, or a seed list (which wins when both are given).
host: 'localhost', // default 'localhost'
port: 7000, // default 7000; also the port for seeds given without one
seeds: ['db1:7000', 'db2:7000', 'db3'],
// Who.
user: 'skaidb', // default 'anonymous'
password: 'secret', // default '' (anonymous)
database: 'app', // optional: `USE app` right after the handshake
// How.
consistency: 'QUORUM', // 'ONE' | 'QUORUM' | 'ALL' (or 0 | 1 | 2); default QUORUM
connectTimeout: 10000, // ms per seed: TCP, TLS and the login handshake
// TLS (see below).
tls: false, tlsCa: undefined, tlsInsecure: false, tlsServerName: 'skaidb',
tlsClientCert: undefined, tlsClientKey: undefined, // PEM paths; imply tls
authMechanism: 'scram', // or 'certificate': log in with the client certificate
});
Every option is also accepted by Pool.
Seeds and failover
skaidb is leaderless: every node accepts reads and writes, so a seed list is
only "somewhere to land". connect() shuffles the seeds and tries them in
turn until one connects and authenticates (a node that accepts TCP while
unhealthy does not swallow the attempt). If none works it throws
no reachable endpoint in <list>: <last error> — unless a node was reached
and refused the session (the database to enter does not exist): then the
error is that node's answer, as the server gave it. Bare hosts take port.
The same walk runs again on reconnect (below), so a client survives the node it was talking to going away. A pooled connection re-dials in the pool's order instead: usable members first, the one it just lost last.
TLS modes
| Option | Meaning |
|---|---|
| (none) | Plaintext. A server with client_tls = required refuses this. |
tls: true |
TLS, server certificate verified against the system trust store. |
tlsCa: '/path/ca.pem' |
TLS, certificate verified against this PEM bundle. Implies tls. |
tlsInsecure: true |
TLS with no certificate verification: encrypts, authenticates nothing. Development only. Implies tls. |
tlsServerName |
SNI / hostname to verify (default skaidb). Must match a SAN on the server certificate, which is usually not the address you dialled — skaidb's own certificates carry DNS:skaidb. |
new Client({ seeds, user, password, tlsCa: '/etc/skaidb/skai-ca.crt' }); // recommended
Client certificates and certificate login
tlsClientCert / tlsClientKey (PEM file paths, given together) present a
client certificate in the TLS handshake, which a server that verifies
clients needs. Either implies tls. On its own the certificate only opens
the TLS session; the login is still the SCRAM user/password.
With authMechanism: 'certificate' the certificate is the login (wire
mechanism EXTERNAL): the server maps its Common Name to a role and no
password is sent. The server needs auth.x509_enabled, and its client CA
must have signed the certificate. Pass user only to assert the expected
identity: a certificate mapped to a different role fails the connect.
new Client({ seeds, tlsCa: '/etc/skaidb/ca.crt',
tlsClientCert: '/etc/app/app.crt', tlsClientKey: '/etc/app/app.key',
authMechanism: 'certificate', database: 'app' });
Consistency
consistency selects how many replicas must acknowledge a write or be
consulted for a read: ONE, QUORUM (the default) or ALL. Set it per client
or per statement:
const client = new Client({ ..., consistency: 'ONE' });
await client.query({ text: 'SELECT ...', consistency: 'ALL' });
for await (const row of client.stream('SELECT ...', { consistency: 'ONE' })) { ... }
batch(sql, rows, { consistency }) takes it per batch too. The CONSISTENCY export holds the
numeric constants ({ ONE: 0, QUORUM: 1, ALL: 2 }).
SET CONSISTENCY { ONE | QUORUM | ALL } sent as a statement is something
else: an override on the connection, under which every statement runs at
that level whatever level it was sent with, until SET CONSISTENCY DEFAULT
clears it (server ≥ 0.349). Like a SET SCAN BUDGET …, it is state of the
session: the client gives both to a connection it re-dials,
and a pool takes both off a connection before
the next borrower gets it.
Queries
client.query(text, values?) / client.query({ text, values, consistency, rowMode })
Runs one statement and resolves to a result:
{
command: 'SELECT' | 'MUTATION' | 'DDL' | 'CALL',
rowCount: number | null, // rows returned, rows affected, or null for DDL
rows: [...], // objects keyed by column name (default) or arrays
fields: [{ name }], // column descriptors, pg-style
columns: ['id', 'name'], // column names, for row-producing statements
resultSets?: [...] // only for a CALL whose body EMITs; see below
}
rowMode: 'array' yields each row as a cell array in column order (like pg).
Statements on one client are serialized: one request/response is in
flight at a time and further calls queue. Use a Pool (or several clients)
for concurrency.
Parameters and prepared statements
Placeholders are $1, $2, … (pg style). A parameter may be referenced more
than once; $N inside a string literal is left alone.
await client.query('UPDATE users SET name = $2, seen = $3 WHERE id = $1', [1, 'Ada', new Date()]);
With parameters, the driver prepares the statement on the server (once per
distinct SQL text per connection, cached up to 240 entries) and sends the
values as typed binary — no string interpolation, no injection surface,
and JavaScript arrays and plain objects travel as skaidb Array and
Document values, which have no SQL literal form. The statement's parameter
count must match what you pass (missing ones throw before anything is sent).
There is no separate prepare()/execute() API: preparing is automatic.
Statements the server declines to prepare (DDL, USE and other session
statements) fall back to safe client-side quoting of the same $N
parameters, so every statement kind accepts parameters. Prepared ids are
scoped to a connection and the cache is dropped on reconnect.
client.batch(sql, rows, opts?) — many rows, one round-trip
const n = await client.batch('INSERT INTO t (id, tags) VALUES ($1, $2)',
[[1, ['a']], [2, []], [3, ['b', 'c']]]); // n === 3
Runs a prepared statement once per row in a single request and returns the
total affected count. Rows autocommit individually: on the first
failing row the server answers with an error naming the row index and how
many rows applied before it, and those earlier rows stay applied — so use
idempotent statements. Only preparable statements (SELECT/INSERT/
UPDATE/DELETE) can be batched; the whole request must fit one 64 MiB
frame. An empty rows resolves to 0 without a round-trip. opts is
{ consistency } (default: the client's).
Multiple result sets
A CALL of a procedure whose body runs EMIT <select> answers with every
emitted set plus the call's final result:
const r = await client.query('CALL report()');
r.resultSets // every set, in emission order, each { rows, fields, columns, rowCount }
r.rows // the LAST set (the call's own result)
Transactions
A transaction is plain SQL on one connection: BEGIN, the statements,
then COMMIT or ROLLBACK. A standalone server opens one with BEGIN, a
cluster with BEGIN ATOMIC or BEGIN ATOMIC PARTITION (col = literal);
outside one, every statement autocommits. client.transaction(body, opts?)
runs the whole sequence:
const left = await client.transaction(async (tx) => {
const { rows } = await tx.query('SELECT qty FROM stock WHERE id = $1', [7]);
await tx.query('UPDATE stock SET qty = $2 WHERE id = $1', [7, rows[0].qty - 1]);
return rows[0].qty - 1;
});
It sends BEGIN, awaits body — handing it the client, so its statements
go out on the same connection — then sends COMMIT and resolves to what
body returned. If body throws, it sends ROLLBACK and throws that same
error, whatever the ROLLBACK itself answers. If BEGIN fails, body
never runs and nothing else is sent.
Conflicts. A standalone server refuses a COMMIT when another writer
changed a row the transaction writes after its BEGIN: nothing was
applied, the transaction is over, and the connection is back in autocommit
and stays usable. The driver raises that as a TransactionConflictError —
a SkaidbError subclass carrying the server's message, raised by
query(), batch() and stream() alike — and transaction() answers it
by running everything again from BEGIN, at once, until it has run
attempts times in all (default 3); the last conflict is thrown. So
body must be safe to run more than once and should do nothing outside
the database that a retry would repeat. Nothing else is retried: not an
error body throws (a conflict included), not any other COMMIT error
(the transaction is over, so no ROLLBACK is sent either), not a lost
connection.
opts is { attempts: 3, begin: 'BEGIN' }; begin is the opening
statement, sent verbatim:
await client.transaction(body, { begin: 'BEGIN ATOMIC PARTITION (tenant = 7)', attempts: 5 });
On a pool, pool.transaction(body, opts?) checks out one connection, runs
the whole transaction on it (body gets that connection) and returns it;
opts also takes affinity.
Written by hand, the same thing is:
const { TransactionConflictError } = require('@skaidb/client');
await client.query('BEGIN'); // if this throws, stop here
try {
await client.query('UPDATE accounts SET balance = balance - $2 WHERE id = $1', [1, 10]);
await client.query('UPDATE accounts SET balance = balance + $2 WHERE id = $1', [2, 10]);
} catch (e) {
await client.query('ROLLBACK').catch(() => {}); // its own error must not replace e
throw e;
}
try {
await client.query('COMMIT');
} catch (e) {
if (e instanceof TransactionConflictError) {
// nothing was applied: run the whole thing again from BEGIN
}
throw e; // a failed COMMIT ended the transaction: no ROLLBACK
}
Two rules, either way:
- One connection for the whole transaction. On a pool that is one
checkout around all of it —
pool.transaction(), or a singlewithConnection()/acquire()— never a checkout per statement. And nothing else may use that client meanwhile: its statements would join the transaction.transaction()refuses a second call on a client that has one running, and it never reconnects mid-transaction: when the connection is lost, the statement that finds it gone (theCOMMITincluded) fails withconnection lost during a transactionand nothing more is sent. - Stop if
BEGINfails. With no transaction open, every statement after it autocommits on its own.
A transaction written by hand is guarded the same way. The client notes a
BEGIN the server accepted (BEGIN, BEGIN TRANSACTION, BEGIN ATOMIC …,
sent as one statement of its own) and the COMMIT or ROLLBACK that ends
it. If the connection is lost in between, it is not replaced: a new one
has no transaction open, and the rest of yours would commit statement by
statement. Instead the statement under which the connection went fails with
the connection error, and every later one with connection lost during a
transaction, sent nowhere — until you end the transaction, which the
client then settles itself, the server having dropped the transaction with
the connection:
ROLLBACKsucceeds without being sent;COMMITfails withconnection lost during a transaction: COMMIT was not sent and nothing was committed.
After either, the next statement re-dials as usual. One case is different:
when the connection goes while the COMMIT itself is in flight, the server
may have applied it before its answer went missing, and the error says so —
connection lost under COMMIT: it is not known whether the transaction was
committed (…), with the connection error as its cause.
A stream opened in
body has to be finished or closed before body ends — a for await loop
does that on every way out. One left open would keep the COMMIT or
ROLLBACK waiting behind it, so transaction() closes the connection
instead, which makes the server drop the transaction, and rejects: with
body's own error if it threw, otherwise with the transaction body left a
stream open: …. The next statement reconnects.
batch() is not a transaction: its rows autocommit one by one, as
described above.
Streaming large results — client.stream(sql, values?, opts?)
query() buffers the whole result; a large scan is also bounded by the
server's scan budgets. stream() asks the server to deliver the rows in
chunks and yields them one at a time, holding one chunk in memory. The
server executes a plain SELECT page by page, and no scan budget applies to
a streamed page (server ≥ 0.330; EXPLAIN says whether a statement pages,
and PROTOCOL.md §3.4
gives the rules):
for await (const row of client.stream('SELECT id, v FROM readings')) {
process(row);
}
console.log(client.stream.columns); // column names, set once the header arrives
values bind $1, $2, … exactly as query(text, values) binds them —
typed, arrays and objects included:
for await (const ev of client.stream(
'SELECT id, ts, body FROM events WHERE ts >= $1 AND ts < $2', [start, end])) {
save(ev);
}
They travel with the statement in one request, which needs a server ≥
0.330: an older one refuses it with server does not support parameterised
streaming (skaidb >= 0.330): …, and the connection stays usable. A stream
without values sends the original request and works against every server
with streaming. Values bind the statement kinds that can be prepared
(SELECT/INSERT/UPDATE/DELETE); unlike query(), a stream has no
client-side quoting fallback for the others.
Options: { consistency, rowMode, values } — values given there wins
over the argument, as config.values does for query(), and
stream(sql, opts) is the call without values. A non-row statement
streamed this way yields nothing; client.stream.command is then
'MUTATION' or 'DDL', client.stream.affected holds a mutation's
affected-row count and client.stream.columns is null (a row result sets
command to 'SELECT'). A CALL whose body EMITs result sets is answered
with all of them in one frame even when streamed: the stream yields the rows
query() would return (the last set), command is 'CALL', and
client.stream.resultSets holds every set, as query()'s resultSets does.
Like columns, these describe the stream started most recently. An error before any row is an ordinary statement error; an
error partway through (a node dying mid-scan, a scan budget tripping) is
thrown after the rows already yielded, which are valid.
The abandon rule
The connection is busy for the whole stream, and closing the iterator is
what frees it. break, return, a throw out of the loop body and an
explicit iterator.return() all close it. On an early close the driver reads
the rest of the result out (up to 8 MB) so the socket is left at a request
boundary; past that it drops the connection instead, and the next statement
transparently reconnects. Either way the next statement reads its own reply.
An iterator that is merely dropped half-read is closed by nobody — JavaScript
has no finalizer that could do it — and that connection stays busy, with
every queued statement behind it, until the client is ended (end() rejects
them with connection is closed). Always iterate to the end or close it.
const it = client.stream('SELECT ...');
try {
const first = await it.next();
...
} finally {
await it.return(); // releases the connection
}
Other query()/batch() calls made while a stream is open queue behind
it rather than failing.
Following a stream — client.subscribe(name, { after, pollMs })
For tables with a CREATE STREAM, subscribe() yields the stream's events
as they arrive, forever:
for await (const ev of client.subscribe('big_orders', { after: lastSeenId, pollMs: 500 })) {
// ev = { id, op, k, ts, doc }
save(ev.id); // pass it back as `after` to resume exactly here
}
It polls the stream's log (_stream_<name>) with a keyset cursor, 500 events
per page; id is the position — an opaque string that sorts in log order
("00000001789857620741-0000000000-0902800000000000000100"), not a number, so
after takes a saved id string or null. For push delivery subscribe to
$stream/<db>/<name> with any MQTT client instead — the events are identical.
To stop, break out of the loop, call .return() on the iterator, or pass an
AbortSignal as signal and abort it; each ends the iteration within a tick
while it is idle between polls (an aborted signal ends it cleanly, without an
error):
const ac = new AbortController();
setTimeout(() => ac.abort(), 60_000);
for await (const ev of client.subscribe('big_orders', { signal: ac.signal })) {
handle(ev);
} // the loop exits when the signal fires
Pooling — new Pool(options)
const { Pool } = require('@skaidb/client');
const pool = new Pool({ seeds: ['h1:7000', 'h2:7000'], user, password, database: 'app', maxsize: 8 });
const res = await pool.withConnection((c) => c.query('SELECT 1'));
const conn = await pool.acquire();
try { await conn.query('...'); } finally { await pool.release(conn); }
await pool.end();
maxsize (default 10) bounds the connections kept idle, not the number
checked out: a burst opens extras and the surplus is closed on release.
acquire() validates an idle connection before handing it out and discards
one the server closed meanwhile; release() closes a broken connection
instead of pooling it, and likewise one that a transaction() may still be
open on, or that a stream left open still holds. Every Client option passes through; seeds (or host/port)
name the starting members. pool.transaction() runs a
transaction on one checked-out connection.
Every borrower gets the pool's own session: the pool's database — without
the option the server's default database, where every new connection
starts — with no scan budget, no consistency override and no transaction
open. What a borrower did to the session is undone when its connection
comes back: a transaction it opened with BEGIN and never ended is rolled
back, a USE is answered with USE <the pool's database>, a SET SCAN
BUDGET with SET SCAN BUDGET DEFAULT, a SET CONSISTENCY with SET
CONSISTENCY DEFAULT. Only what is needed is sent, so a borrower that
changed nothing costs no round trip, and a connection that cannot be put
back is closed instead of pooled (a server before 0.349 has no SET
CONSISTENCY DEFAULT). So choose the database in the pool's options, or
with a USE at the start of each checkout: it does not outlive the
checkout.
Balancing across members
By default (loadBalancing: 'random') each new connection dials the members
in random order and stays on the member it reached — fine for many
processes, but one process can end up with most of its connections on one
member. A policy spreads a single process's load:
const pool = new Pool({
seeds: ['db1:7000', 'db2:7000', 'db3:7000'], user, password, database: 'app',
loadBalancing: 'least_latency', // or 'round_robin'
discover: true, // learn the members from the cluster
readYourWrites: 2000, // ms; see below
idleOrder: 'fifo',
});
| Option | Default | What it does |
|---|---|---|
loadBalancing |
'random' |
'round_robin': checkouts rotate over the usable members in endpoint order. 'least_latency': of two members picked at random, the one with the lower round-trip average × (checked-out connections + 1), so near and idle members win; a member not measured in the last 2 s scores 0, so every member keeps being re-measured. |
idleOrder |
'lifo' |
'fifo' hands out the longest-idle connection first, so every idle connection keeps being used and a server-side idle timeout never finds one. |
discover |
false |
Reads the members with SHOW ENDPOINTS (server ≥ 0.327; no privilege needed) when a member is first reached and every refreshInterval (60000 ms) after — every 5 s while one is resyncing or unreachable. New members are added, members that left are dropped (seeds are kept, marked unlisted), and members reported resyncing or unreachable get no new connections until they are ready again, when they start with a fresh latency average. An older or standalone server leaves the seeds as they are and is not asked again. |
ejectErrors |
3 |
Consecutive transport failures (a failed dial, an I/O error mid-request, a capacity refusal) that eject a member. Statement errors and refused logins do not count. |
ejectLatencyFactor, ejectLatencyFloor |
3, 50 (ms) |
A member whose round-trip average is above factor × the other members' median and more than floor ms above it is ejected (after 10 samples on it and on another member). The fastest of a member's first three round trips seeds its average, so a statement that stalls in your own process — a CPU-bound start-up blocking the event loop — cannot get a healthy member ejected; the 'eject' event's reason names the average, the median and the slowest of the member's last 10 round trips. Factor 0 disables. |
ejectBackoff, ejectBackoffMax |
5000, 60000 (ms) |
How long an ejection lasts, doubling per repeat (back to the base after a healthy ejectBackoffMax). When it is up, a background probe dials the member and runs one statement; success re-admits it. The last usable member is never ejected. |
readYourWrites |
0 (off) |
Milliseconds after a write during which checkouts with the same affinity go to the member that took it. |
Read-your-writes. The member that coordinated a write reads it back at
any consistency, ONE included; another member may not have applied it yet.
With readYourWrites set, pass an affinity key — a user or session id —
when you check out:
await pool.withConnection({ affinity: userId }, (c) =>
c.query('INSERT INTO notes (id, owner, body) VALUES ($1, $2, $3)', [id, userId, body]));
// the next request for the same user, within the window, reaches the same member:
const note = await pool.withConnection({ affinity: userId }, (c) =>
c.query('SELECT body FROM notes WHERE id = $1', [id]));
const conn = await pool.acquire({ affinity: userId }); // acquire() takes it too
Checkouts without a key share one pool-wide key, so with constant writes
everything follows the latest writer — pass a key when you balance. A
statement is a write unless its first keyword is SELECT, SHOW,
EXPLAIN, DESCRIBE/DESC, VALUES, WITH or USE.
Derive the key without touching the pool: if it comes from something that itself queries the database through the same pool (a web framework's "current user" loader), a helper that checks out a connection and computes the key inside it re-enters itself. Read the raw id from the session or token instead.
Watching it. pool.members() returns one entry per member, in endpoint
order:
[{ endpoint: 'db1:7000', canonical: '10.0.0.1:7000', state: 'ready',
latencyMs: 0.8, inUse: 2, idle: 3, seed: true }, ...]
state is ready, ejected, resyncing, unreachable or unlisted. The
pool is an EventEmitter: 'eject' ({ endpoint, reason }) and
'readmit' ({ endpoint }) fire as members leave and rejoin the rotation.
The probe/discovery timer is unref()'d, so it never keeps the process
alive, and pool.end() stops it. The rules are the same in every skaidb
driver (PROTOCOL.md §6.1).
Reconnect and errors
Every error the driver raises is a SkaidbError (an Error subclass).
- Statement errors (
SELECT nope→no such column …) reject the call; the connection stays usable. One whose message starts withtransaction conflict:— aCOMMITthe server refused — is aTransactionConflictError, aSkaidbErrorsubclass (Transactions); like any statement error it neither drops the connection nor counts against a pool member's health. - Transport errors reject the in-flight statement with
connection lost/connection closed(connection lost: read ECONNRESETand the like when the socket reported an error, which is then thecause) and mark the client broken, not closed. The next statement re-dials (through the seed walk), re-authenticates, puts the new connection back into the session — the database (thedatabaseoption, or the one last entered with aUSEstatement), then theSET CONSISTENCY …andSET SCAN BUDGET …last sent as statements — and clears the prepared-statement cache — except while a transaction is open,transaction()'s or one opened with aBEGINstatement, which is never carried to another connection (Transactions). If the database cannot be entered any more (it was dropped meanwhile) the statement fails with the server's error for it and runs nowhere; aUSEto another database is not held back by that and gets the client out. Because the failed statement may have executed, the driver never retries it for you: retry a write only if it is idempotent.isUsable()reports the state. - A connection closed while it was idle — a member restarted, failed over, or timed the connection out — costs no statement: the client hears of the close before it writes the next request, re-dials, and the statement runs with no error (inside a transaction it is reported as the lost connection it is). A connection that has been silent for more than a millisecond is looked at first, which takes a turn of the event loop and no round trip, so a close that arrived while your code kept the event loop busy is seen as well.
- Protocol desync (an unexpected frame, or data waiting on a connection
that no statement asked for): the driver drops the connection
(
isUsable()→ false) rather than hand the next caller a misaligned reply, and the next statement reconnects. end()is terminal: a closed client never reconnects (connection is closed).- A client that has not connected dials nothing on its own: until
connect()has resolved — and after one that failed, however it failed — a statement rejects withnot connected: await connect() first.
Common messages: connect failed: …, connect timeout, no reachable
endpoint in …, authentication denied: …, server signature mismatch
(mutual auth failed), cannot read tlsCa …, cannot read tlsClientCert …, server does not support
streaming: …, server does not support parameterised streaming (skaidb >=
0.330): …, statement expects N parameters, got M, no parameter for
$N, cannot bind value of type …, cannot bind NaN/Infinity, cannot bind
an invalid Date, bigint … does not fit a 64-bit integer, stream
abandoned with too much data left to drain, not connected: await connect()
first, connection lost during a transaction, connection lost during a
transaction: COMMIT was not sent and nothing was committed, connection lost
under COMMIT: it is not known whether the transaction was committed (…),
the transaction body left a stream open: …, a transaction is already
running on this connection, attempts must be >= 1, every new connection
broke during member discovery.
Type mapping
| skaidb | JavaScript (results) | Bind (parameters) |
|---|---|---|
| Null | null |
null, undefined |
| Bool | boolean |
boolean |
| Int (i64) | number, or bigint when outside ±2^53 |
integer number within 64 bits, bigint |
| Float | number |
non-integer number, -0, and an integer too large for an Int (NaN/Infinity refused) |
| Decimal | string (exact, e.g. '123.45') |
bind as string |
| String | string |
string |
| Bytes | Buffer |
Buffer |
| Uuid | string (canonical 8-4-4-4-12) |
bind as string |
| Timestamp | Date (millisecond precision) |
Date |
| Array | Array |
Array (nested) |
| Document | plain object, key order preserved | plain object |
An integer-valued number binds as Int (as Float when it is too large for
one, such as 1e21) and a fractional one as Float; pass a bigint to force
Int. In the client-side fallback (unpreparable statements)
a Date renders as its epoch milliseconds, a Buffer as a hex string, and
arrays/objects cannot be bound at all.
Compatibility
- Node.js ≥ 18. No build step, no native code.
- Server: any skaidb. Prepared statements need server ≥ 0.17.0 (older
servers get the client-side fallback automatically),
batch()≥ 0.87.0,stream()a server with the streaming opcode (an older one answersserver does not support streaming) and, with values, ≥ 0.330 (an older one answersserver does not support parameterised streaming), multiple result sets a server withEMIT. ACOMMITrefused for a conflict (TransactionConflictError) comes from a standalone server ≥ 0.346.0. The Hello frame that fills the server'sdriverstable (client_namenodejs,client_version= this package's version) is ignored by older servers. - Wire protocol: https://skaidb.org/docs/PROTOCOL.html.
Conformance
test/conformance.test.js runs the shared skaidb wire-protocol conformance
suite, conformance/vectors.json (generated from the server's reference
encoders; contract in conformance/README.md), as
part of npm test:
- every value vector decodes to the documented JavaScript form (above) and, where JavaScript can bind that value, encodes to the reference bytes;
- the SCRAM vectors against the driver's own SCRAM code;
- a scripted fake server that verifies the client proof independently,
checks every request byte for byte and replays the reference responses,
for every case through the public API (
query,streamwith and without values, parameterizedquery,batch), plus the auth outcomes (ok, a bad server signature must fail, denied).
Skipped: no call method. Encoding is not checked for the values JavaScript
has no parameter form for: Decimal and Uuid (they surface as strings, which
bind as String) and integral Floats such as 0.0 (an integer-valued
number binds as Int). The vectors' ? placeholders are given in this
driver's $1, $2, … form, which it sends as ?. CI fails when the vendored
conformance/vectors.json differs from https://skaidb.org/conformance/vectors.json.
Development
npm test # node:test unit tests + conformance suite, no server needed (~3 s)
npm run typecheck # compiles test/types/consumer.ts against skaidb.d.ts
npm run pack:check # what a publish would ship
node examples/basic.js host 7000 user password # against a real node
CI runs the suite on Node 18, 20 and 22 and the TypeScript check on every
push and pull request. Tagging vX.Y.Z runs the publish workflow, which
publishes to npm when the NPM_TOKEN secret is present and otherwise exits
with a notice.