Browser Quickstart
PrimaDB supports two browser build profiles:
- default WASM build
- opt-in threaded WASM build
The default build is the compatibility-first path. The threaded build is the performance path.
Default Browser Flow
Build:
cd /home/bitnom/Code/gunport/primadb
./build-wasm.sh
Minimal usage:
import init, { Primadb } from "./pkg/primadb.js";
await init();
const db = new Primadb("browser-a");
db.useBrowserStorage("primadb-demo");
db.chain("users").field("alice").put({
name: "Alice",
profile: { timezone: "America/New_York" },
});
Threaded Browser Flow
Build:
cd /home/bitnom/Code/gunport/primadb
./build-wasm-threads.sh
Bootstrap:
import init, * as primadb from "./pkg/primadb.js";
await init();
await primadb.initThreadPool(Math.max(2, navigator.hardwareConcurrency || 4));
const db = new primadb.Primadb("threaded-browser");
Relay And Mesh
Relay:
const relay = db.connectRelay({
url: "ws://127.0.0.1:9010",
retryIntervalMs: 1500,
});
Mesh:
const mesh = db.connectMesh({
room: "demo-room",
relayUrl: "ws://127.0.0.1:9010",
iceServers: [{ urls: "stun:stun.cloudflare.com:3478" }],
});
PrimaDB core does not hard-code STUN servers. The examples explicitly provide them.