Skip to Content
ReferenceClient APIDrizzleAdapter

DrizzleAdapter

Storage adapter for local data persistence using Drizzle ORM.

Import

import { DrizzleAdapter } from '@gluonic/client-drizzle'

Signature

function DrizzleAdapter(config: DrizzleAdapterConfig): StorageAdapter

Parameters

config: DrizzleAdapterConfig

PropertyTypeRequiredDescription
dbDrizzleDBYesDrizzle database instance
opDbOPSQLiteDBNoOP-SQLite instance (React Native only)
tablesRecord<string, TableConfig>NoCustom table mappings

Returns

StorageAdapter instance with methods for local storage operations.

Examples

React Native (OP-SQLite)

import { drizzle } from 'drizzle-orm/op-sqlite' import { open } from '@op-rs/sqlite' import { DrizzleAdapter } from '@gluonic/client-drizzle' export const opDb = open('app.db') export const db = drizzle(opDb) const storage = DrizzleAdapter({ db, opDb })

Web (Better-SQLite3)

import { drizzle } from 'drizzle-orm/better-sqlite3' import Database from 'better-sqlite3' import { DrizzleAdapter } from '@gluonic/client-drizzle' const sqlite = new Database('app.db') export const db = drizzle(sqlite) const storage = DrizzleAdapter({ db })

With Custom Tables

import { relay, transcript } from './schema' const storage = DrizzleAdapter({ db, opDb, tables: { relay: { model: relay, idField: 'id' }, transcript: { model: transcript, idField: 'id' } } })

What It Does

DrizzleAdapter implements the StorageAdapter interface:

interface StorageAdapter { // Row operations getRow(t: string, id: string): Promise<WireRow | null> putRow(row: WireRow): Promise<void> deleteRow(t: string, id: string): Promise<void> // Bulk operations putRows(rows: WireRow[]): Promise<void> deleteRows(items: Array<{ t: string, id: string }>): Promise<void> // Query operations listByType(t: string): Promise<WireRow[]> listByIndex(t: string, indexKey: string, indexVal: string): Promise<WireRow[]> // Metadata getLastSyncId(): Promise<number> setLastSyncId(n: number): Promise<void> // Transaction queue enqueueTx(tx: Transaction): Promise<void> dequeueTx(id: string): Promise<void> listTx(): Promise<Transaction[]> // Utility clearAll(): Promise<void> }

Internal Tables

DrizzleAdapter creates these tables automatically:

sync_rows_{modelType}

Stores synced data for each model type.

CREATE TABLE sync_rows_task ( id TEXT PRIMARY KEY, data TEXT NOT NULL -- JSON serialized WireRow )

sync_tx_queue

Stores pending mutations.

CREATE TABLE sync_tx_queue ( id TEXT PRIMARY KEY, type TEXT NOT NULL, model_id TEXT NOT NULL, patch TEXT NOT NULL, prev TEXT, op TEXT, created_at INTEGER )

sync_meta

Stores metadata like lastSyncId.

CREATE TABLE sync_meta ( key TEXT PRIMARY KEY, value TEXT NOT NULL )

Platform Support

PlatformDatabasePackage
React NativeOP-SQLite@op-rs/sqlite
WebBetter-SQLite3better-sqlite3
ElectronBetter-SQLite3better-sqlite3

Same adapter works on all platforms - just use the appropriate Drizzle driver.

Performance

DrizzleAdapter is optimized for:

  • ✅ Batch operations (putRows, deleteRows)
  • ✅ Indexed queries (listByIndex)
  • ✅ Transaction support
  • ✅ Minimal overhead

Benchmarks:

  • getRow: ~1ms
  • putRow: ~2ms
  • putRows(1000): ~50ms (batched)
  • listByType(10k rows): ~30ms

See Also

Last updated on