Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions packages/adapters/graph/sqlite-wasm/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Sqlite3Static,
} from "@sqlite.org/sqlite-wasm";
import type { Exclusive } from "@exadev/process-graph-store-sqlite";
import { sqlJsCodecs } from "drizzle-orm/sql-js/codecs";
import { drizzle, type SqliteRemoteDatabase } from "drizzle-orm/sqlite-proxy";

/** Where the database lives: an OPFS `opfs-sahpool` pool and a file in it. */
Expand Down Expand Up @@ -38,24 +39,28 @@ export const openWorkerDatabase = (
let pool: Promise<SAHPoolUtil> | undefined;
let open: Database | undefined;

// The store reads through `values`, `all` and query builders, never `.get()`, so `get` is refused rather than answered: the proxy's declared result type has no way to say "no row", which Drizzle's `get` signals with a missing `rows`.
const db = drizzle(async (statement, params, method) => {
if (method === "get") {
throw new Error("The graph store's worker database does not serve get");
}
if (open === undefined) {
throw new Error(
"The database was used outside a store operation; only the store's exclusive section may run statements",
);
}
const rows = open.exec(statement, {
bind: params,
rowMode: "array",
returnValue: "resultRows",
});
/* The store reads through `values`, `all` and query builders, never `.get()`, so `get` is refused rather than answered: the proxy's declared result type has no way to say "no row", which Drizzle's `get` signals with a missing `rows`.
The proxy driver decodes nothing by itself: the codecs say how SQLite's stored values become the columns' types (JSON text, booleans, timestamps). SQLite wasm answers in array mode with native JavaScript values and `Uint8Array` blobs, which is what sql.js answers with, so its codecs apply. */
const db = drizzle(
async (statement, params, method) => {
if (method === "get") {
throw new Error("The graph store's worker database does not serve get");
}
if (open === undefined) {
throw new Error(
"The database was used outside a store operation; only the store's exclusive section may run statements",
);
}
const rows = open.exec(statement, {
bind: params,
rowMode: "array",
returnValue: "resultRows",
});

return Promise.resolve({ rows });
});
return Promise.resolve({ rows });
},
{ codecs: sqlJsCodecs },
);

const exclusive: Exclusive = async (operation) =>
navigator.locks.request(location.pool, { mode: "exclusive" }, async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/graph/store-sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A private workspace package, not published on its own: it is bundled into [`process-graph`](../../../targets/process-graph/README.md), which exposes it as `process-graph/store`, beside the store contract.

The `GraphStore` port from `@exadev/process-graph-store-contract` on SQLite through [Drizzle](https://orm.drizzle.team) (`drizzle-orm` 1.0.0-rc.4). It is written against Drizzle's async SQLite database type, so any Drizzle SQLite driver plugs in: `@exadev/process-graph-sqlite-node` supplies `node:sqlite`, `@exadev/process-graph-sqlite-wasm` supplies SQLite in a browser worker on OPFS. `src/` imports nothing Node-only.
The `GraphStore` port from `@exadev/process-graph-store-contract` on SQLite through [Drizzle](https://orm.drizzle.team). It is written against Drizzle's async SQLite database type, so any Drizzle SQLite driver plugs in: `@exadev/process-graph-sqlite-node` supplies `node:sqlite`, `@exadev/process-graph-sqlite-wasm` supplies SQLite in a browser worker on OPFS. `src/` imports nothing Node-only.

```ts
import { createGraphStoreRouter } from "@exadev/process-graph-store-contract";
Expand Down
16 changes: 8 additions & 8 deletions packages/targets/process-graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@
"@exadev/process-graph-store-sqlite": "1.2.2",
"@exadev/process-graph-sync": "1.0.1",
"@exadev/process-graph-ui": "1.1.2",
"@orpc/client": "2.0.0-beta.41",
"@orpc/contract": "2.0.0-beta.41",
"@orpc/server": "2.0.0-beta.41",
"@orpc/client": "2.0.0-beta.42",
"@orpc/contract": "2.0.0-beta.42",
"@orpc/server": "2.0.0-beta.42",
"@sqlite.org/sqlite-wasm": "3.53.4-build2",
"@stryker-mutator/core": "10.0.0",
"@stryker-mutator/typescript-checker": "10.0.0",
Expand All @@ -153,7 +153,7 @@
"@vitest/coverage-v8": "4.1.11",
"@xyflow/react": "12.12.0",
"commander": "15.0.0",
"drizzle-orm": "1.0.0-rc.4",
"drizzle-orm": "1.0.0-rc.5-5935859",
"elkjs": "0.12.0",
"eslint": "10.12.0",
"playwright": "1.63.0",
Expand All @@ -169,15 +169,15 @@
"zod": "4.6.5"
},
"peerDependencies": {
"@orpc/client": "2.0.0-beta.41",
"@orpc/contract": "2.0.0-beta.41",
"@orpc/server": "2.0.0-beta.41",
"@orpc/client": "2.0.0-beta.42",
"@orpc/contract": "2.0.0-beta.42",
"@orpc/server": "2.0.0-beta.42",
"@sqlite.org/sqlite-wasm": "3.53.4-build2",
"@vanilla-extract/css": "^1.21.2",
"@vanilla-extract/recipes": "^0.5.7",
"@xyflow/react": "^12.12.0",
"commander": "^15.0.0",
"drizzle-orm": "1.0.0-rc.4",
"drizzle-orm": "1.0.0-rc.5-5935859",
"elkjs": "^0.12.0",
"react": "^19.3.0",
"react-dom": "^19.3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const consumerOf = (tarball: string, specifiers: readonly string[]): string => {
join(consumer, "package.json"),
JSON.stringify({ name: "consumer", private: true, type: "module" }),
);
// pnpm rather than npm: npm 11.19.0, the npm the pinned Node ships, cannot resolve drizzle-orm 1.0.0-rc.4's optional `effect` peer range at all (ERESOLVE, with or without this package), which npm 11.19.1 fixes.
// pnpm rather than npm: npm 11.19.0, the npm the pinned Node ships, cannot resolve the `effect` peer range of drizzle-orm's 1.0.0 release candidates at all (ERESOLVE, with or without this package), which npm 11.19.1 fixes.
execFileSync("pnpm", ["add", "--ignore-scripts", tarball, ...specifiers], {
cwd: consumer,
// Output is captured rather than shown, and a failure's error carries pnpm's own report of why.
Expand Down
Loading
Loading