Skip to content

Plugins

A DataStore needs one storage IDbPlugin. Start with the backend that owns your rows, then add only the capabilities your application needs.

Start here

I need to…Go to
Choose where rows are storedChoose a storage plugin
Add caching, retries, concurrency, or batchingWrapper Plugins
Measure or trace database operationsWrapper Plugins or OpenTelemetry
Sync over HTTP or build a local-first/SWR stackReplication & SWR
Store file attachments or upload directly to S3/R2Files and Blob Storage
Encrypt selected schema propertiesEncryption
Combine several plugins safelyComposition Recipes
Add a new database backendBuild a Storage Plugin

Application code does not implement query or result translation. Those are plugin-author responsibilities used only when adapting a new backend; they live under Plugins → Plugin Authors in navigation.

Choose a storage plugin

PackageEnvironment / backendConstructorImportant constraint
@routier/memory-pluginAny; volatile memorynew MemoryPlugin(databaseName?)Data ends with the process
@routier/browser-storage-pluginBrowser localStorage or sessionStoragenew BrowserStoragePlugin(name, storage)Whole-collection synchronous writes; one writer across tabs
@routier/dexie-pluginBrowser IndexedDBnew DexiePlugin(name, { version? })Bump version when index/schema layout changes
@routier/file-system-pluginNode JSON filesnew FileSystemPlugin(path, name)One process; rewrites a whole collection
@routier/sqlite-pluginNode or browser/OPFSnew SqliteDbPlugin(name, { driver? })Node default needs 22.5+; optional drivers cover older Node/browser
@routier/pglite-pluginPostgreSQL in WASM; browser/OPFS or Nodenew PGliteDbPlugin(name, { workerUrl? })About 3 MB of WASM; opfs-ahp does not work in Safari
@routier/postgresql-pluginPostgreSQL via pgnew PostgresDbPlugin(config)No automatic schema migration
@routier/mysql-pluginMySQL via mysql2new MysqlDbPlugin(config)No automatic schema migration
@routier/mongodb-pluginMongoDBnew MongoDbPlugin(driver, databaseName?)Transactions require a replica set and an explicit driver choice
@routier/pouchdb-pluginPouchDB / CouchDB replicationnew PouchDbPlugin(name, options?)One physical document store; scope logical collections

See Server Database Plugins for PostgreSQL, MySQL, and MongoDB setup and contracts.

Add behavior with wrappers

Wrappers also implement IDbPlugin, so they can be nested:

ts
const plugin = new CacheDbPlugin(
  new RetryDbPlugin(new PostgresDbPlugin(config), { attempts: 3 }),
  { max: 100 },
);
WrapperPackagePurpose
CacheDbPlugin@routier/core/pluginsRead-through LRU; invalidates writes passing through it
RetryDbPlugin@routier/core/pluginsRetries reads only
ConcurrencyDbPlugin@routier/core/pluginsHidden version column and optimistic concurrency
BatchingDbPlugin@routier/core/pluginsSerializes writes and optionally coalesces atomic saves
TelemetryDbPlugin@routier/core/pluginsOne timing event per operation, to a sink or the logger
OtelDbPlugin@routier/otel-pluginOne OpenTelemetry span per operation
BlobDbPlugin@routier/blob-pluginUploads s.file() content and stores references
HttpDbPlugin@routier/replication-pluginDirect HTTP transport
HttpSwrDbPlugin@routier/replication-pluginLocal mirror plus stale-while-revalidate HTTP reads
OptimisticUpdatesDbPlugin@routier/replication-pluginFast optimistic reads over a source plugin
PluginSyncEngine@routier/replication-pluginConfigurable source/mirror synchronization

Read Wrapper Plugins before choosing order: wrappers can observe only operations below them, and some require guarantees from the inner plugin.

Schema-level integrations

These integrate at the schema boundary rather than serving as the datastore's storage plugin:

  • @routier/blob-plugin wraps storage for s.file() and exposes memory, file-system, and S3-compatible blob stores.
  • @routier/encryption returns a two-way x.transform(...) for AES-GCM property encryption.
  • @routier/sql-plugin-core is a toolkit for plugin authors (toSql, dialects, column/update/join helpers), not an application storage plugin.

Installation

Install core, datastore, and only the integrations you use:

bash
npm install @routier/core @routier/datastore @routier/dexie-plugin

All packages expose ESM and CommonJS entry points. Optional database drivers and SDKs remain peer dependencies; each plugin page names the required peer.

Composition rules

  1. The outermost wrapper receives calls first.
  2. Destroy flows through the full stack.
  3. A cache sees only writes routed through that cache.
  4. RetryDbPlugin never retries writes; a generic wrapper cannot know whether a partial write landed.
  5. Set BatchingDbPlugin({ isAtomic: true }) only when the inner plugin guarantees a failed save applied nothing.
  6. ConcurrencyDbPlugin works only when the inner plugin enforces conditional updates. See its support table in Wrapper Plugins.

See Plugin Compositions for common stacks and Create Your Own Plugin for the IDbPlugin contract.

Released under the MIT License.