RxDB Documentation

website·Indexed 36 days ago

https://rxdb.info

Authoritative reference for RxDB, a reactive, local-first NoSQL database for JavaScript with offline support. Includes guides on RxDatabase, RxCollection, RxQuery, and RxSchema, as well as various RxStorage implementations including IndexedDB, SQLite, MongoDB, OPFS, and Dexie.js.

Tokens
247K
Snippets
815
Records
1.5K
Agent score
72%

What's inside RxDB

  1. Overview of Origin Private File System (OPFS)

    The Origin Private File System (OPFS) is a native browser storage API providing a sandboxed, origin-specific virtual filesystem. It allows for byte-by-byte access and file streaming, making it significantly faster (3x-4x) than IndexedDB for high-performance file operations. It is supported by all modern browsers (Chrome, Edge, Safari, Firefox), though Internet Explorer is not supported.

    Key constraints:

    • Synchronous methods (read(), write()) and createSyncAccessHandle() are only available inside a WebWorker.
    • While there is no fixed data size limit, browsers may throw a QuotaExceededError when storage limits are reached.
  2. Overview of RxDB for local-first web applications

    RxDB (Reactive Database) is an open-source (Apache 2.0), NoSQL JavaScript database designed for local-first applications. It stores documents locally in the browser, Node.js, Electron, or React Native, using the local store as the source of truth for the UI. It features a MongoDB-style query language, JSON schema validation, and a pluggable storage layer (e.g., IndexedDB, OPFS, SQLite). Unlike mutator-based systems, RxDB allows standard database operations (insert, patch, remove) and replicates changes to remote endpoints via a flexible Sync Engine.
  3. Overview of Local Databases in JavaScript

    A local database stores data directly on the user's device (client-side) rather than on a remote server. This enables offline-first architectures where the application reads and writes data without network round trips, resulting in sub-millisecond latency and continued functionality during network outages. In a typical production setup, a local database handles the user interface state, while a remote database serves as the durable source of truth for replication across devices.
  4. Overview of RxDB Supabase Replication

    The Supabase Replication Plugin enables two-way synchronization between RxDB collections and Supabase (Postgres) tables. It utilizes PostgREST for pulling and pushing data and Supabase Realtime (logical replication) for streaming live updates. The plugin is designed for offline-first applications, providing resumable incremental sync and conflict resolution via the RxDB Sync Engine. It works in both browsers and Node.js environments.
  5. Overview of RxDB Backup Plugin

    The Backup Plugin allows you to write the current database state and ongoing changes into folders on the filesystem as plain JSON files, including attachments. This enables consuming database content with non-RxDB software or creating remote backups via mounted folders.

    Critical Constraints:

    • Works only in Node.js; it is not supported in the browser.
    • Intended for server-side use (e.g., with RxServer).
    • For client-side backups, use replication plugins or JSON dumps.
    • Currently, there is no built-in functionality to import data back from a written backup.
  6. Overview of RxDB as a local-first database

    RxDB is a reactive, local-first JavaScript database designed for applications that need to work offline and sync with a backend. It uses a pluggable storage architecture, meaning it can run on various storage engines depending on the environment. Each collection is defined by a JSON schema and is queried using a Mango (MongoDB-style) query API. All queries are observable, allowing UI components to re-render automatically when data changes locally or via synchronization.
  7. Overview of TanStack DB persistence with RxDB

    TanStack DB is an in-memory reactive client store. To make data survive page reloads, it requires a storage layer. The @tanstack/rxdb-db-collection package integrates RxDB as a durable NoSQL database underneath TanStack DB collections. Every write to a TanStack DB collection is persisted to an RxCollection and restored on the next page load.
  8. Overview of RxDB Websocket Replication

    The websocket replication plugin allows you to spawn a websocket server from an RxDB database in Node.js to enable replication.

    Critical Constraints:

    • It does not support authentication or permission handling.
    • It is designed specifically for server-to-server replication, not client-server replication.
  9. Overview of P2P WebRTC Replication in RxDB

    RxDB's WebRTC replication allows for a fully decentralized, live data flow where clients (browsers or devices) sync their local database state directly with one another. Unlike traditional client-server architectures, there is no master-slave relationship; each peer hosts its own local RxDB instance. A signaling server is required only for the initial discovery of peers to establish the connection.
  10. Overview of RxDB CRDT Plugin mechanism

    The RxDB CRDT Plugin transforms data writes into atomic mathematical operations (such as $inc or $set) instead of absolute state replacements. This ensures that when multiple offline clients modify the same document, the operations are merged in a guaranteed deterministic order upon reconnection.

    Key advantages include:

    • Familiar Syntax: Uses NoSQL query operations instead of binary data (unlike Yjs or Automerge).
    • Backend Compatibility: Because it uses NoSQL operators, it is easier to implement the same logic on custom backends.
    • Integrated Features: Provides access to RxDB's schema validation and data migration tools.
  11. Overview of WebTransport API

    WebTransport is a low-latency API leveraging the HTTP/3 QUIC protocol. It supports multiple streams, both reliable and unreliable data transfer, and out-of-order delivery.

    Current Status (as of March 2024):

    • It is a Working Draft and not widely adopted.
    • No support in Safari or native support in Node.js.
    • The API is complex and likely requires high-level libraries for practical application use.
  12. Overview of TanStack DB with SQLite via RxDB

    TanStack DB is an in-memory reactive client store. By using the @tanstack/rxdb-db-collection package, it delegates persistence to RxDB. When paired with the SQLite RxStorage, TanStack DB data is persisted into a real SQLite database. This setup allows for optimistic mutations in memory that are automatically persisted to disk, and ensures that data survives app restarts. It supports native SQLite on Node.js, Electron, React Native, and Capacitor, as well as WebAssembly (WASM) in the browser.