RxDB API Documentation

website·Indexed 29 days ago

https://rxdb.aiao.io

API reference for RxDB and its ecosystem, including rxdb-vue for Vue.js integration, rxdb-adapter-sqlite-core, and rxdb-adapter-sqlite-wasm for SQLite browser adapters. The documentation covers hooks like useRepositoryQuery and useInfiniteScroll, SQLite client interfaces, and various utility types and variables.

Tokens
382.5K
Snippets
2.6K
Records
3.6K
Agent score
50%

What's inside RxDB

  1. Overview of @aiao/rxdb-client-generator

    The @aiao/rxdb-client-generator automatically generates type-safe client code by reading @aiao/rxdb decorators such as @Entity, @TreeEntity, and @GraphEntity. It produces entity types, static type mappings, Repository query method signatures (e.g., get, find, findAll, findByCursor), and relation field rule types that support dot-syntax relation queries. By default, it supports a relation query depth of 3 layers.
  2. Overview of @aiao/rxdb and Local-first Architecture

    @aiao/rxdb is an engineering infrastructure designed to implement a "Local-first" architecture in the browser. Unlike traditional web apps that rely on network requests for availability and speed, a Local-first approach treats the user's device as the primary location for data, ensuring the application is available and responsive first, then handling synchronization and consistency with a remote server.

    Key goals of @aiao/rxdb include:

    1. Declarative Modeling: Defining entities, fields, relationships, and constraints via a declarative model to prevent data code from becoming fragmented as business complexity grows.
    2. Framework Agnostic Data Layer: Providing a consistent set of models, queries, and entity semantics that can be reused across Angular, React, and Vue, separating the data layer from the UI binding layer.
    3. Decoupling Data and UI: Creating clear boundaries between local persistence, reactive queries, and the interface to reduce "glue code" related to caching and API transformations.
    4. Data as an Asset: Treating local data structures, complex queries, and derived views as reusable assets rather than temporary state.
    # Visit the project repository for implementation details
    git clone https://github.com/aiao-io/aiao
  3. Overview of EventDispatcher

    The EventDispatcher is a type-safe synchronous event dispatcher. Its dispatch semantics are aligned with the DOM EventTarget:

    • Snapshot-based Dispatch: dispatchEvent takes a snapshot of the listener set before iterating. Listeners added during dispatch will not receive the current event; listeners removed during dispatch will still be called for the current event.
    • Error Handling: Exceptions thrown by listeners are not swallowed; they bubble up to the caller, and subsequent listeners in the queue are not executed.
    • Memory Management: Event sets are only created when addEventListener is called. Once a set is empty, the event name is removed from the internal map to prevent unbounded growth.
  4. Overview of RxDB Collaboration Capabilities

    RxDB provides collaboration features focused on versioning, synchronization, and recoverability. These capabilities are designed to be implemented after the local data link is stable. The current MVP implementation supports branching, undo/redo, conditional synchronization, and cross-tab synchronization.

    Key capabilities include:

    • Branching: Used for isolating changes, organizing workflows, and handling parallel edits.
    • Synchronization: Manages the data exchange mechanisms between local and remote storage.
    • Undo/Redo: Provides reversibility and recoverability for user operations.
  5. Overview of RxDB Workspace Plugin

    The RxDB Workspace plugin provides local recovery capabilities for NEW entity drafts that have not yet been committed to the database. Drafts are stored in memory and IndexedDB and synchronized across same-origin tabs via BroadcastChannel. This allows drafts to be automatically recovered after a page refresh or restart, where they can be continued, saved, or discarded.

    Scope and Limitations:

    • Only covers NEW drafts.
    • Does NOT support unsaved UPDATEs for existing entities, rolling back existing entities to pre-edit states, or undoing DELETE operations.
    • Nested object modifications do not trigger change tracking because RxDB Entity Proxy only intercepts top-level property assignments. To track changes in nested objects, assign a new object to the top-level field (e.g., draft.meta = { ...draft.meta, nested: { value: 'x' } }).
  6. Overview of @aiao/rxdb-plugin-workspace

    @aiao/rxdb-plugin-workspace is a workspace plugin designed to handle drafts of NEW entities that have not yet been committed to the main database. It stores these drafts in memory and IndexedDB (via idb-keyval) and synchronizes them across same-origin browser tabs using the BroadcastChannel API. This allows drafts to persist across page refreshes or restarts, enabling users to continue editing, save, or discard them.
  7. Overview of RxDB PGlite Adapter

    The @aiao/rxdb-adapter-pglite adapter enables running a full PostgreSQL instance in the browser using WebAssembly (PGlite). It is a local-first, serverless solution that supports standard PostgreSQL syntax, JSONB, tsvector full-text search, and advanced indexing. It is ideal for applications requiring strong SQL standard compatibility, complex queries, or those planning a future migration to a PostgreSQL backend.
  8. Overview of QueryCacheRepository

    The QueryCacheRepository is an experimental repository used for the QueryCache synchronization strategy. It implements a remote-first write policy and a sophisticated read process that synchronizes local and remote metadata to minimize data transfer.

    Warning: This class currently has no production instantiation path and is primarily used in tests. It is not yet integrated into the unified Repository and should not be depended upon in application code due to several unverified fallback behaviors (e.g., issues with inflight keys for different modes, empty array fallbacks for findByIds, and offline fallback error handling).

  9. Overview of RepositoryBase

    RepositoryBase is the base class for all RxDB repositories. Its primary purpose is to act as a thin wrapper for entity references. It delegates the creation, lookup, and existence checks of entities to the EntityManager's LRU cache. It handles updates by using EntityStatus.replace or falling back to Object.assign while preserving the origin for diffing and change inversion. Business logic regarding queries, synchronization, and change orchestration is implemented in subclasses or adapters to keep the base class complexity low.
  10. Overview of RxDB wa-sqlite adapter

    The @aiao/rxdb-adapter-wa-sqlite adapter enables RxDB to run a full SQLite database in the browser via WebAssembly. It is a local-first, zero-server solution that supports standard SQLite syntax and provides high performance by utilizing Web Workers to avoid blocking the main thread. It is particularly suitable for applications requiring a lightweight local database, FTS5 full-text search, and compatibility with the SQLite ecosystem.