← Back to archive

Repo of the Day

pubkey/rxdb

Published: Sep 26, 2022

Open repository ↗

I'm interested in using this to maybe persist the dexie db to my web app. It integrates via REST, CouchDB, or a GraphQL endpoint, and seems pretty popular. I'm wondering if it would give me any other benefits.

Summary

RxDB is a local-first, reactive NoSQL database written in TypeScript that runs in JavaScript environments including browsers, Node.js, React Native, Electron, and Capacitor. It exposes observable queries so applications can subscribe to state changes, and it provides a sync engine that replicates with existing backends instead of tying you to a single cloud vendor.

What it is useful for

RxDB fits when an application must keep working offline and later merge changes when connectivity returns, such as field tools, PWAs, and mobile apps. It is also useful for realtime UIs where the view should reflect database changes automatically, because query results can be subscribed to rather than manually refetched. Teams that want to keep their current server (GraphQL, CouchDB, Postgres, and so on) but move reads and writes onto the client can use RxDB as the local store. The storage layer is pluggable, so the same code can target LocalStorage, IndexedDB, OPFS, SQLite, LokiJS, Dexie.js, in-memory storage, DenoKV, or FoundationDB depending on the runtime, which helps share logic across browser, server, and native targets.

How engineers can use it

The README documents the quickstart. Install with npm install rxdb rxjs. Then create a database by importing createRxDatabase from rxdb/plugins/core and a storage adapter (for example getRxStorageLocalstorage from rxdb/plugins/storage-localstorage for browsers). Collections are added with a JSON schema; the example defines a heroes collection with a name primary key, an integer healthpoints field, and required fields. Documents are inserted with db.heroes.insert({ name: 'Bob', healthpoints: 100 }). One-time reads use db.heroes.find({ selector: { healthpoints: { $gt: 0 } } }).exec(). Live reads append .$ to the same query and .subscribe(...) to receive updates whenever the matching set changes. Replication is added through separate plugins for GraphQL, CouchDB, WebSocket, WebRTC, Supabase, Firestore, NATS, and Google Drive, or by implementing three HTTP endpoints against an existing server. Detailed setup beyond the quickstart (such as encryption, schema migration, CRDT conflict handling, and WebWorker storage) lives in the docs linked from the README at https://rxdb.info/, so readers should consult those pages for environment-specific configuration. One documented caveat: the README advertises premium plugins sold separately, so some capabilities are not included in the open-source package.