Developer beta 0.1.0-beta.1 documentation. The build is not available for download yet; these pages describe the beta as built and tested on Linux x86-64.
TypeScript SDK
Package @holadb/client, version 0.1.0-beta.1. Node 20 or later, no
runtime dependencies. It ships ES modules and CommonJS, both with type
declarations, and speaks the native protocol (port 7433 by default).
Install
The package is not on the npm registry in this beta. Build it from the repository and install the resulting file into your project:
cd rust/clients/typescript
npm ci
npm pack # builds dist/ and writes holadb-client-0.1.0-beta.1.tgz
cd /path/to/your/project
npm install /path/to/holadb/rust/clients/typescript/holadb-client-0.1.0-beta.1.tgz
npm pack runs the build first (prepack). Installing the source
directory itself (npm install ../typescript) only links it: run
npm ci && npm run build there first.
In ES modules and TypeScript:
import { HolaDB } from "@holadb/client";
In CommonJS:
const { HolaDB } = require("@holadb/client");
A TypeScript project also needs Node’s type definitions, because the
package’s declarations use Buffer: npm install --save-dev @types/node,
and with TypeScript 6 or later "types": ["node"] in the compiler options
(TypeScript 6 no longer loads them on its own).
Example
The examples on this page run as written against the server of the
quick start: it listens on 127.0.0.1:7433, has the
table products, an administrator admin and the user app with the role
readwrite. Save an example as example.mjs (or example.ts) in the
project where you installed the package and run node example.mjs.
app can read and write rows but cannot create tables, so this example
uses the table the quick start created. It can be run any number of times.
import { HolaDB, ServerError } from "@holadb/client";
const db = await HolaDB.connect("holadb://app:app-secret@127.0.0.1:7433");
console.log(await db.whoami()); // { user: 'app', roles: [ 'readwrite' ], authRequired: true }
// insert, read, update: values travel as parameters ($1, $2, ...)
await db.execute("DELETE FROM products WHERE sku IN ($1, $2)", ["C3", "D4"]);
await db.query("INSERT INTO products (sku, name, price, stock) VALUES ($1, $2, $3, $4)", ["C3", "washer", 0.05, 1200]);
const cheap = await db.query("SELECT sku, name, price FROM products WHERE price < $1 ORDER BY sku", [0.2]);
for (const row of cheap) console.log(row.sku, row.name, row.price);
const products = db.table("products"); // helpers that generate SQL
await products.insert({ sku: "D4", name: "screw", price: 0.3 });
await products.update("sku", "D4", { stock: 40 });
console.log(await products.get("sku", "D4")); // { sku: 'D4', name: 'screw', price: 0.3, stock: 40 }
// a transaction: COMMIT when the callback resolves ...
await db.transaction(async (tx) => {
await tx.execute("UPDATE products SET stock = stock - $1 WHERE sku = $2", [10, "D4"]);
await tx.execute("UPDATE products SET stock = stock + $1 WHERE sku = $2", [10, "C3"]);
});
// ... ROLLBACK when it throws; the error is thrown on to the caller
try {
await db.transaction(async (tx) => {
await tx.execute("DELETE FROM products WHERE sku = $1", ["D4"]);
throw new Error("changed my mind");
});
} catch (e) {
if (e instanceof Error) console.log("rolled back:", e.message);
}
console.log(await products.count()); // 4: D4 is still there
// a statement the server refuses: the connection stays usable
try {
await db.query("INSERT INTO products (sku, name) VALUES ($1, $2)", ["A1", "duplicate"]);
} catch (e) {
if (!(e instanceof ServerError)) throw e;
console.log(e.codeName, "-", e.message); // constraint - ...
}
// a large result, one page of 500 rows at a time
for await (const row of await db.cursor("SELECT * FROM products ORDER BY sku", [], 500)) console.log(row.sku);
await db.close();
Creating tables
Schema changes need a user who may run DDL. This example connects as the
quick start’s administrator for that one step, then works as app. It can
also be run any number of times.
import { HolaDB, Timestamp } from "@holadb/client";
const admin = await HolaDB.connect("holadb://admin:change-me-now@127.0.0.1:7433");
await admin.query(
"CREATE TABLE IF NOT EXISTS events (id BIGINT PRIMARY KEY, at TIMESTAMP, kind TEXT NOT NULL, detail JSON, payload BYTEA, counter UBIGINT)",
);
await admin.close();
// the password comes from the options here; it could also come from HOLADB_PASSWORD
const db = await HolaDB.connect("holadb://127.0.0.1:7433", { user: "app", password: "app-secret", timeoutMs: 5000 });
const events = db.table("events");
await events.delete("id", 1);
await events.insert({
id: 1,
at: new Date("2026-01-02T03:04:05.500Z"), // Date or Timestamp
kind: "login",
detail: { ip: "192.0.2.7", tags: ["web"] }, // objects and arrays are JSON
payload: Uint8Array.of(0, 255),
counter: 2n ** 64n - 1n, // 64-bit integers are exact as bigint
});
const row = await events.get("id", 1);
if (row && row.at instanceof Timestamp) console.log(row.at.toDate().toISOString()); // 2026-01-02T03:04:05.500Z
console.log(row?.detail, row?.payload, row?.counter);
await db.close();
Connection options
HolaDB.connect(url, options). Everything can be written in the URL; an
option overrides the same part of the URL. A number in place of options
is the timeout in milliseconds. The Python SDK takes the
same URL.
| Setting | In the URL | In options |
Default |
|---|---|---|---|
| Plaintext or TLS | holadb:// or holadbs:// |
(a ca also means TLS) |
|
| Host and port | host:port |
127.0.0.1, 7433 |
|
| User | user@ |
user |
none: no login |
| Password | user:password@, percent-encoded |
password |
the environment variable HOLADB_PASSWORD, else empty |
| CA file (PEM) for TLS | ?ca=FILE |
ca |
Node’s bundled roots |
| Name the certificate must carry | ?servername=NAME |
servername |
the host |
| Timeout | ?timeout=SECONDS |
timeoutMs (milliseconds) |
30 s; 0: none |
- Example of a TLS URL:
holadbs://app@db.example.com:7433?ca=/etc/holadb/ca.pemwith the password inHOLADB_PASSWORD. The server needs a certificate (Security); the quick-start server has none. - The server certificate chain and name are always verified. There is no
insecure mode and no fallback to plaintext. Over TLS the login is
SCRAM-SHA-256-PLUSwithtls-server-end-pointchannel binding; without TLS it isSCRAM-SHA-256.db.isTlstells which. - When the host is an IP address and no
servernameis given, the certificate must list that address. - The timeout covers the TCP and TLS connect and then every request (login
steps, statements, cursor pages): when the server sends nothing for that
long while a request waits, the connection is closed and the call fails
with
TimeoutError. The request may or may not have run on the server. - The server cancels a statement itself after
--statement-timeout-ms(30 s by default) and answers with the errortimeout(code 25). Both defaults are 30 s: give the client a longer timeout if you want the server’s answer rather than a closed connection. - URL parameters other than
ca,servernameandtimeoutare ignored. db.authenticate(user, password)logs in on an open connection.- Differences from the Python SDK: the option is
timeoutMsin milliseconds (Python:timeoutin seconds,Nonefor none) andservername(Python:server_name).
Values
| JavaScript | Sent as | Read back as |
|---|---|---|
null, undefined |
NULL | null |
boolean |
boolean | boolean |
number, a safe integer |
integer | number |
number, any other |
float | number |
bigint from −2^63 to 2^64−1 |
integer | number inside ±(2^53−1), bigint outside |
string |
text | string |
Uint8Array |
bytes | Uint8Array |
Date, Timestamp |
timestamp (microseconds, UTC) | Timestamp (.micros, .toDate()) |
plain object, array, Json |
JSON | the parsed value |
Integers are exact over the whole signed and unsigned 64-bit range when
you pass them as bigint. A bigint outside that range, or a statement
text over 1 MiB, throws a RangeError before anything is sent. A number
that is an integer above 2^53 is not a safe integer and is sent as a
float: use bigint for such values.
Errors
| Class | Meaning |
|---|---|
ServerError |
The server refused the statement or the login. code and codeName say why (table below). The connection stays usable. |
ConnectionError |
The connection could not be made (refused, unknown host, TLS failure, unreadable CA file), was lost, or is closed. cause holds the Node error. Open a new connection. |
TimeoutError |
A ConnectionError: no answer within the timeout. |
ProtocolError |
The peer did not speak the HolaDB protocol. ConnectionError is a subclass. |
RangeError, TypeError |
A parameter that cannot be sent. Nothing was sent; the connection stays usable. |
All SDK classes extend HolaDBError.
code |
codeName |
Meaning |
|---|---|---|
| 3 | too_large |
request or result over the 16 MiB frame limit: read large results with db.cursor |
| 4 | no_such_table |
unknown table |
| 8 | invalid_argument |
a value that does not fit, a missing parameter, a limit |
| 14 | shutting_down |
the server is stopping |
| 16 | sql |
syntax error, unknown column, unsupported SQL |
| 17 | constraint |
primary key, unique index or NOT NULL violation |
| 18 | transaction |
transaction misuse, or a conflict detected at COMMIT: run the transaction again |
| 19 | cursor |
unknown cursor or prepared statement |
| 20 | unauthorized |
log in first; also sent to a plaintext client by a server that requires TLS |
| 21 | forbidden |
the user lacks the privilege |
| 22 | auth_failed |
wrong user or password |
| 23 | busy |
connection limit reached, or logins from this address are delayed after failed attempts: retry later |
| 24 | uncertain_outcome |
the outcome of a write is unknown: do not retry blindly; the server refuses writes until it is restarted |
| 25 | timeout |
the statement ran longer than the server’s statement timeout and was cancelled; nothing of it was applied and the connection stays usable. This is a ServerError, not the client’s TimeoutError |
ERROR_CODES holds all 25 names (the others are malformed,
unsupported_version, table_exists, no_such_entity, entity_exists,
invalid_state, corruption, storage, rollover, internal,
unknown_op). A code this SDK version does not know has the name
code_N.
API summary
HolaDB.connect(url?, options?) |
a Database; HolaDB.version and VERSION are the SDK version |
db.query(sql, params?) |
a Result: iterable rows, .rows, .columns, .tag, .affected, .one(), .first(), .scalar() |
db.execute(sql, params?) |
the number of affected rows |
db.explain(sql, params?) |
the plan as text |
db.table(name) |
insert, get, update, delete, select, count, cursor |
db.transaction(fn) |
commit or roll back around fn; db.begin(), db.commit(), db.rollback() for explicit control |
db.cursor(sql, params?, batch?) |
an async iterable of rows; nextPage(), close() |
db.whoami(), db.ping(), db.authenticate(user, password) |
identity, liveness, login |
db.isTls, db.isClosed, db.close() |
state; close() never throws |
db.raw |
the low-level Connection (prepare, call) |
A row is an object keyed by column name; row.$values is the same row as
an array. One connection runs one request at a time; calls made while
another is running are queued in order.
Known limitations in this beta
- Parameters beyond the statement’s placeholders are ignored by the server without an error.
- There is no bulk-insert helper and no automatic paging: a result over
16 MiB fails with
too_large; read it withdb.cursor. - Tested with Node 22 on Linux x86-64.
Checks
In rust/clients/typescript: npm run typecheck, npm run test:unit (no
server needed) and npm run test:e2e (a server without users on
127.0.0.1:7433, or HOLADB_TEST_HOST / HOLADB_TEST_PORT;
node --experimental-strip-types test/e2e.ts HOST PORT [--ca CA_PEM] [--user NAME]
for TLS and a login). npm test runs both. The tests run the TypeScript
sources directly and need Node 22.6 or later.