Registry / database / muya-sqlite

muya-sqlite

JSON →
library0.0.5jsnpmunverified

A tiny SQLite companion for muya state management library (v0.0.5). Reactive, paginated, type-safe queries over SQLite tables that auto-sync on data mutation. Uses a push-driven subscription model: views update automatically when any part of the app calls set/delete/batchSet on the underlying table. Returns TanStack-style hook result (data, status, isLoading, isFetching, isStale, isError, error, hasNextPage, fetchNextPage, refetch). Optional global cache via cacheKey persists data and subscriptions across mount/unmount cycles. Built on useSyncExternalStore, concurrent-safe, no QueryClientProvider required. Requires muya >=2.5.8 and react >=18 <20.

npm install muya-sqlite
INSTALL
IMPORT
SIG · MUYA-SQLITE
M
muya-sqlite
databasejavascriptv0.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createSqliteState
import { createSqliteState } from 'muya-sqlite'
const createSqliteState = require('muya-sqlite')
ESM-only package; no default export.
useSqliteValue
import { useSqliteValue } from 'muya-sqlite'
import { useSqliteValue } from 'muya-sqlite/dist/esm/hooks/use-sqlite-value'
Main entry re-exports the hook; do not deep-import.
bunMemoryBackend
import { bunMemoryBackend } from 'muya-sqlite'
import { bunMemoryBackend } from 'muya-sqlite/dist/esm/table/bun-backend'
Deep imports are not guaranteed stable between minor versions.

Minimal runnable example: create a SQLite-backed reactive state, insert two rows, and render a paginated list that auto-updates on mutation.

import { createSqliteState, useSqliteValue } from 'muya-sqlite' import { bunMemoryBackend } from 'muya-sqlite' interface Person { id: string name: string age: number } const people = createSqliteState<Person>({ backend: bunMemoryBackend(), tableName: 'people', key: 'id', indexes: ['age'], }) await people.batchSet([ { id: '1', name: 'Alice', age: 30 }, { id: '2', name: 'Bob', age: 25 }, ]) function PeopleList() { const { data, status, hasNextPage, fetchNextPage } = useSqliteValue(people, { sortBy: 'age', pageSize: 50, }) if (status === 'pending') return <p>Loading&hellip;</p> if (status === 'error') return <p>Failed to load</p> return ( <> <ul> {data?.map((p) => ( <li key={p.id}>{p.name} ({p.age})</li> ))} </ul> {hasNextPage && <button onClick={() => fetchNextPage()}>Load more</button>} </> ) }
Debug
Known issues
gotcha`createSqliteState` is async – you must `await` the backend Promise if `backend` option is async.
fix
Wrap the state creation in an async function or top-level await.
affects: >=0.0.1
breakingPeer dependency `react` must be >=18 <20. Using React 17 or 20+ will cause runtime errors.
fix
Install react@18 or react@19.
affects: >=0.0.0
deprecatedDeep imports like `muya-sqlite/dist/esm/hooks/use-sqlite-value` may break in patch releases. Only import from the package root.
fix
Use `import { useSqliteValue } from 'muya-sqlite'` instead.
affects: >=0.0.0
gotchaTable `key` must be a unique primary key. If the SQLite table has a different PK, you must still specify `key` matching a field in Document.
fix
Always provide `key` option – the same field will be used as the document identifier.
affects: >=0.0.1
gotchaReact strict mode in development will double-mount and double-subscribe, but the library handles deduplication internally.
fix
No user action needed, but bear in mind double renders in dev.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'muya-sqlite'
Package not installed or missing peer dependency muya.
fix
Run `npm install muya muya-sqlite` or `bun add muya muya-sqlite`.
TypeError: createSqliteState is not a function
Wrong import syntax – attempting to use the result of a default import or require().
fix
Use `import { createSqliteState } from 'muya-sqlite'`.
Error: React is not defined
React not installed or wrong version (<18).
fix
Install react@18 or react@19: `npm install react@18`.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies
muyarequiredpeer dependency for state management primitives
reactrequiredpeer dependency for hooks and JSX
Agent activity
7 hits · last 30 days
node
6
Resources
muya-sqlite — npm install muya-sqlite · libregistry