npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xnetjs/sqlite

v0.0.2

Published

Unified SQLite adapter for xNet across all platforms

Readme

@xnetjs/sqlite

Unified SQLite adapter for xNet across all platforms (Electron, Web, Expo).

Installation

pnpm add @xnetjs/sqlite

Features

  • Unified interface -- Same SQLiteAdapter API across all platforms
  • Platform adapters -- better-sqlite3 (Electron), sqlite-wasm (Web), expo-sqlite (Expo)
  • Schema management -- Version tracking and migrations
  • Full-text search -- FTS5 integration helpers
  • Diagnostics -- Query analysis and database stats

Usage

Memory Adapter (Testing)

import { createMemorySQLiteAdapter } from '@xnetjs/sqlite/memory'

const db = await createMemorySQLiteAdapter()

// Query data
const rows = await db.query('SELECT * FROM nodes WHERE schema_id = ?', ['xnet://Page/1.0'])

// Insert data
await db.run('INSERT INTO nodes (id, schema_id, ...) VALUES (?, ?, ...)', [id, schemaId, ...])

// Transactions
await db.transaction(async () => {
  await db.run(...)
  await db.run(...)
})

await db.close()

Electron (better-sqlite3)

import { createElectronSQLiteAdapter } from '@xnetjs/sqlite/electron'

const db = await createElectronSQLiteAdapter({
  path: 'xnet.db',
  // Optional WAL mode (default: true)
  walMode: true
})

Web (sqlite-wasm + OPFS)

import { createWebSQLiteAdapter } from '@xnetjs/sqlite/web'

const db = await createWebSQLiteAdapter({
  path: 'xnet.db'
})

Expo (expo-sqlite)

import { createExpoSQLiteAdapter } from '@xnetjs/sqlite/expo'

const db = await createExpoSQLiteAdapter({
  path: 'xnet.db'
})

API

SQLiteAdapter Interface

interface SQLiteAdapter {
  // Query execution
  query<T>(sql: string, params?: unknown[]): Promise<T[]>
  queryOne<T>(sql: string, params?: unknown[]): Promise<T | null>
  run(sql: string, params?: unknown[]): Promise<RunResult>
  exec(sql: string): Promise<void>

  // Transactions
  transaction<T>(fn: () => Promise<T>): Promise<T>
  beginTransaction(): Promise<void>
  commit(): Promise<void>
  rollback(): Promise<void>

  // Prepared statements
  prepare(sql: string): Promise<PreparedStatement>

  // Schema
  getSchemaVersion(): Promise<number>
  setSchemaVersion(version: number): Promise<void>
  applySchema(version: number, sql: string): Promise<boolean>

  // Lifecycle
  isOpen(): boolean
  close(): Promise<void>

  // Utilities
  getDatabaseSize(): Promise<number>
  vacuum(): Promise<void>
  checkpoint(): Promise<number>
}

FTS5 Helpers

import { updateNodeFTS, searchNodes, rebuildFTS } from '@xnetjs/sqlite'

// Update FTS index for a node
await updateNodeFTS(db, nodeId, title, content)

// Search nodes
const results = await searchNodes(db, 'search query', { limit: 10 })

// Rebuild entire FTS index
await rebuildFTS(db, (current, total) => {
  console.log(`Progress: ${current}/${total}`)
})

Diagnostics

import { getDatabaseStats, explainQuery, timeQuery } from '@xnetjs/sqlite'

// Get database statistics
const stats = await getDatabaseStats(db)
console.log(`Tables: ${stats.tableCount}, Size: ${stats.totalSizeBytes} bytes`)

// Analyze a query
const plan = await explainQuery(db, 'SELECT * FROM nodes WHERE schema_id = ?', ['xnet://Page/1.0'])
console.log(plan)

// Time a query
const { result, durationMs } = await timeQuery(db, async () => {
  return db.query('SELECT * FROM nodes')
})
console.log(`Query took ${durationMs}ms`)

Schema

The package includes a unified schema (SCHEMA_DDL) with the following tables:

Core Tables

  • nodes - Entity registry
  • node_properties - Property storage with LWW
  • changes - Event log

Yjs Tables

  • yjs_state - Document state
  • yjs_updates - Incremental updates
  • yjs_snapshots - Time travel

Storage Tables

  • blobs - Content-addressed binary storage
  • documents - Generic document storage
  • updates - @xnetjs/storage compatibility
  • snapshots - @xnetjs/storage compatibility

Metadata Tables

  • _schema_version - Schema tracking
  • sync_state - Sync metadata

FTS5 Virtual Table

  • nodes_fts - Full-text search index

Platform Support

| Platform | Adapter | SQLite Engine | FTS5 | | -------- | ----------------------- | ---------------- | ---- | | Electron | ElectronSQLiteAdapter | better-sqlite3 | Yes | | Web | WebSQLiteAdapter | @sqlite.org/wasm | Yes | | Expo | ExpoSQLiteAdapter | expo-sqlite | Yes | | Test | MemorySQLiteAdapter | sql.js | No* |

* sql.js does not include FTS5 extension. FTS-related tests are skipped.

Browser Support (Web)

The Web adapter requires:

  • Cross-Origin-Opener-Policy: same-origin
  • Cross-Origin-Embedder-Policy: require-corp
  • Chrome 102+, Firefox 111+, Safari 16.4+, Edge 102+
import { checkBrowserSupport } from '@xnetjs/sqlite'

const support = await checkBrowserSupport()
if (!support.supported) {
  console.warn('SQLite not supported:', support.reason)
}

Testing

pnpm --filter @xnetjs/sqlite test

Dependencies

  • sql.js - WebAssembly SQLite (for memory adapter)
  • better-sqlite3 - Native SQLite for Node.js (Electron)
  • @sqlite.org/sqlite-wasm - Official SQLite WASM (Web)
  • expo-sqlite - Expo SQLite (React Native)