slatedb-node
v0.2.1
Published
Node.js bindings for SlateDB via napi-rs
Readme
slatedb-node
High-performance Node.js bindings for SlateDB implemented as a native Rust extension using napi-rs.
- Native extension (no subprocess bridge)
- Async TypeScript API
- Supports SlateDB DB/Reader/Snapshot/Transaction/Admin primitives
- Compiled with
slatedbfeatureall(object store + compression feature set)
Installation
pnpm add slatedb-nodeQuick Start
import { WriteBatch, open } from "slatedb-node";
const db = await open({ path: "example-db", url: "memory:///" });
await db.put("user:1", "alice");
console.log((await db.get("user:1"))?.toString());
const batch = new WriteBatch();
batch.put("user:2", "bob");
batch.delete("user:1");
await db.write(batch);
const iter = await db.scanPrefix("user:");
for await (const [key, value] of iter) {
console.log(key.toString(), value.toString());
}
await db.close();Opening Databases
import { open } from "slatedb-node";
const db = await open({
path: "my-db",
url: "file:///tmp/slatedb-store",
settingsPath: "./SlateDb.toml", // optional
settings: {
flush_interval: "50ms",
manifest_poll_interval: "1s",
}, // optional object overrides
});Reader and Admin APIs
import { open, openAdmin, openReader } from "slatedb-node";
const db = await open({ path: "my-db", url: "file:///tmp/slatedb-store" });
const checkpoint = await db.createCheckpoint("durable");
const reader = await openReader({
path: "my-db",
url: "file:///tmp/slatedb-store",
checkpointId: checkpoint.id,
});
const admin = await openAdmin({ path: "my-db", url: "file:///tmp/slatedb-store" });
console.log(await admin.listCheckpoints());
await reader.close();
await db.close();Errors
Errors are mapped to typed classes:
TransactionErrorClosedErrorUnavailableErrorInvalidErrorDataErrorInternalError
Development
Requirements:
- Node.js 20+
- Rust toolchain
pnpm
Commands:
pnpm install
pnpm run build
pnpm testPrebuilt Binaries
The package uses @napi-rs/cli optional dependency packages (like esbuild/swc) so the main package stays small and installs only the binary for the current platform.
Generated optional packages:
- macOS x64 / arm64
- Linux x64 / arm64 (gnu + musl)
- Windows x64 / arm64 (msvc)
The generated package names are:
slatedb-node-darwin-x64slatedb-node-darwin-arm64slatedb-node-linux-x64-gnuslatedb-node-linux-x64-muslslatedb-node-linux-arm64-gnuslatedb-node-linux-arm64-muslslatedb-node-win32-x64-msvcslatedb-node-win32-arm64-msvc
Publishing
publish.yml builds all native targets, downloads artifacts, creates per-platform npm package dirs, and runs npm publish.
prepublishOnly runs napi pre-publish -t npm, which updates optionalDependencies and publishes the platform packages alongside the main package.
