@affectively/dash
v5.0.0
Published
The Local-First, AI-Native Database for the Web. Featuring WASM SQLite, Vector Embeddings, and MCP support.
Maintainers
Readme
Dash 2.0
The Local-First, AI-Native Database for the Modern Web.
Dash 2.0 isn't just a database; it's a complete data engine for building high-performance, intelligent web applications. It brings server-grade power to the client, enabling apps that feel instant, work offline, and understand your users.
The "Real" Filesystem: OPFS
If you built your local-first app a year or two ago, you probably had to persist data by serializing the whole DB to IndexedDB or localStorage. It was slow and blocked the main thread.
The Shift
The new standard is SQLite over OPFS (Origin Private File System).
Why it’s sexy
It gives the browser direct, performant handle access to a virtual file system optimized for random access.
The Result
You can run full ACID transactions on a multi-gigabyte SQLite file in the browser with near-native desktop performance, without ever blocking the UI thread (thanks to SharedArrayBuffer).
Combined with Zero-Copy (BYOB) readers and UCAN-based Zero-Trust Auth, Dash isn't just a database—it's a local-first operating system.
Features
🚀 Production-Grade Storage
- Stateful Serverless: Powered by Cloudflare Durable Objects and Native SQLite.
- Zero-Copy IO (BYOB): "Bring Your Own Buffer" readers for max throughput.
- ACID Compliant: Full transactional integrity in the browser.
🧠 Hardware-Accelerated AI
- Vector Search: Built-in vector embeddings and search.
- 3-Tier Acceleration:
- WebNN: NPU acceleration (Apple Neural Engine, etc.)
- WebGPU: High-performance GPU parallelization.
- WASM/CPU: Universal fallback.
- Semantic Queries: Find data by meaning at native speeds.
🔄 Modern Sync
- Hybrid Transport:
- WebSocket: Supports Cloudflare Durable Object Hibernation ($0 idle cost).
- WebTransport: UDP-like high-frequency streams (perfect for cursors/games).
- Zero-Trust Auth (UCANs): Decentralized authorization via User Controlled Authorization Networks.
- Lens: Bidirectional schema migrations for infinite backward compatibility.
🎨 Graphics Ready
- Direct Buffers: Zero-copy bindings allow piping data directly into 3D engines like Three.js.
- Spatial Indexing: R-Tree support for massive 3D visualizations.
Installation
npm install @affectively/dashQuick Start
1. Store & Query (Standard SQL)
Dash provides a familiar SQL interface with Promise-based execution.
import { dash } from "@affectively/dash";
await dash.ready();
// Standard SQL execution
await dash.execute("CREATE TABLE IF NOT EXISTS todos (id TEXT, text TEXT)");
await dash.execute("INSERT INTO todos VALUES (?, ?)", ["1", "Buy milk"]);
const rows = await dash.execute("SELECT * FROM todos");
console.log(rows);2. Semantic Search (AI)
Store content with automatic vector embeddings and query by meaning.
// Add an item (automatically generates and stores vector embedding)
await dash.addWithEmbedding("1", "Buy almond milk and eggs");
// Search by meaning - "breakfast ingredients" matches "eggs" and "milk"!
const results = await dash.search("breakfast ingredients");
// Result: [{ id: '1', content: '...', score: 0.85 }]3. Spatial Queries (3D R-Tree)
Filter items by 3D bounds for high-performance spatial lookups.
// Query a 3D bounding box
const items = await dash.spatialQuery({
minX: 0,
maxX: 100,
minY: 0,
maxY: 100,
minZ: 0,
maxZ: 100,
});4. Reactivity (Signals)
Bind query results directly to your application state.
import { liveQuery, effect } from "@affectively/dash";
// This signal automatically updates whenever the 'todos' table changes
const todos = liveQuery("SELECT * FROM todos");
effect(() => {
console.log("Current Todos:", todos.value);
});5. Sync & Backup (Local-First)
Enable collaboration and data safety with a single line.
import { SyncConnection, backup } from "@affectively/dash";
// 1. Peer-to-Peer Sync (WebTransport - Recommended)
// Requires a WebTransport Relay Server (Star Topology)
const connection = new SyncConnection({
type: "webtransport",
roomName: "my-room",
url: "https://relay.dash.dev/sync",
doc,
});
// OR: Peer-to-Peer Sync (WebRTC - Legacy)
// Mesh Topology (Client-to-Client)
const p2p = new SyncConnection({
type: "webrtc",
roomName: "my-room",
doc,
});
// 2. Encrypted Cloud Backup
await backup("my-room", doc, mySecretKey, cloudAdapter);Architecture
Dash uses @sqlite.org/sqlite-wasm with the OPFS backend to ensure main-thread responsiveness. Large data operations occur in the WASM heap, avoiding the serialization overhead of IndexedDB.
Vector operations utilize sqlite-vec (WASM) for high-performance similarity search.
For a deep dive into our "Stateful Serverless" Client-Relay topology using Cloudflare Durable Objects, read the Sync Architecture Guide.
Development
# Build the project
npm run build
# Run tests
npm testLicense
MIT
