Skip to content

sql-reactive-ormReactive ORM for SQLite, built on MobX

Entity fields are Promises. React `use()`-native. Aggregate queries that re-run — and re-render only the leaves whose data moved.

Reactive ORM bridging a SQLite database to React components via Promise-typed fieldsReactive ORM bridging a SQLite database to React components via Promise-typed fields

At a glance

tsx
// orm.ts
import { Orm } from "sql-reactive-orm";
import { SqlJsDriver } from "sql-reactive-orm/drivers/sqljs";
import wasmUrl from "sql.js/dist/sql-wasm.wasm?url";
import { Account, Transaction } from "./entities";

const driver = await SqlJsDriver.open({ locateFile: () => wasmUrl });
export const orm = new Orm(driver);
await orm.register(Account, Transaction);

// TransactionList.tsx
import { use } from "react";
import { orm } from "./orm";
import { Transaction } from "./entities";

export function TransactionList() {
  const txs = use(
    orm.findAll(Transaction, {
      orderBy: [["id", "desc"]],
      with: { account: true },
      limit: 50,
    }),
  );
  return <ul>{txs.map(tx => <li key={tx.id}>{use(tx.amount)}</li>)}</ul>;
}

Released under LGPL-3.0-or-later. Source, full license text, and issue tracker on GitHub.