Couchbase Lite for Dart Documentation

website·Indexed 32 days ago

https://cbl-dart.dev/

Documentation for Couchbase Lite for Dart, an embedded NoSQL document database for building offline-enabled applications. Features include data synchronization, SQL++ for mobile, QueryBuilder API, full-text search, vector search, and support for Android, iOS, macOS, Windows, and Linux. Requires Dart SDK ^3.10.0.

Tokens
34.6K
Snippets
178
Records
251
Agent score
66%

What's inside Couchbase Lite for Dart

  1. Overview of Live Queries in Couchbase Lite for Dart

    A live query monitors the database for changes and refreshes its result set whenever a change occurs. This allows developers to build reactive user interfaces (such as tables or lists) that update automatically without requiring a manual refresh. When a live query is activated, it executes immediately and dispatches an initial change notification, followed by subsequent notifications as data changes.
  2. Overview of Couchbase Lite Peer-to-Peer Synchronization

    Couchbase Lite's Peer-to-Peer (P2P) synchronization allows bidirectional data sync between edge devices over IP-based networks using WebSockets, without requiring a centralized cloud control point. It uses an Active-Passive architecture where one peer acts as a Listener (Passive Peer/Server) and the other acts as a Replicator (Active Peer/Client). Key features include Delta Sync for bandwidth optimization, TLS encryption, and built-in conflict management.
  3. Overview of the QueryBuilder API

    Couchbase Lite for Dart provides the QueryBuilder API to construct database queries. The structure and semantics are based on the SQL++ query language. A typical query follows this format:

    1. SELECT: Specifies the data to be returned.
    2. FROM: Specifies the collection to query.
    3. JOIN: Specifies criteria for joining multiple documents.
    4. WHERE: Specifies filtering criteria.
    5. GROUP BY: Specifies grouping criteria.
    6. ORDER BY: Specifies ordering criteria.
  4. Overview of Pre-built Databases in Couchbase Lite

    Pre-built databases allow developers to pre-load an application with data, avoiding a bulk initial sync from Sync Gateway or Capella App Services. This is ideal for public, shared, or mostly static data. When the app launches, the replicator uses the pre-built database's checkpoint to pull only the changes that occurred after the database was packaged, ensuring the data is brought up to date efficiently.
  5. Couchbase Lite for Dart Overview

    Couchbase Lite for Dart is a community-maintained, embedded, document-style NoSQL database designed for building offline-enabled applications. It provides a platform implementation for Dart and Flutter, aiming for feature parity with other Couchbase Lite platform implementations.
  6. Implement an active peer for peer-to-peer replication

    In Couchbase Lite for Dart, an active peer is the side of a peer-to-peer replication that initiates the connection to a passive peer. This is implemented using the Replicator class pointed at a passive peer's UrlEndpointListener. This feature is available in the Enterprise Edition.
  7. Migrate dependencies from cbl v3 to v4

    Version 4 replaces the multi-package architecture (cbl, cbl_dart, cbl_flutter, etc.) with a single cbl package powered by Dart native assets. Native libraries are now handled automatically by the Dart build system.

    Important Compatibility Notes:

    • Database Migration: v4 uses version vector architecture. Once a database is upgraded to v4, it cannot be opened by v3.x.
    • Sync Gateway: Requires Sync Gateway 4.0 or later.
    • Couchbase Server: Requires version 7.6.6 or later for XDCR interoperability with Sync Gateway 4.0.
    • P2P Sync: Both peers must be on v4.
    dependencies:
      cbl: ^4.0.0-dev.9
  8. Understand Couchbase Lite document structure

    In Couchbase Lite, a document is a record in the database. Each document consists of:

    • ID: A unique primary key (UUID or programmatically specified) that cannot be changed once set.
    • Value: The application data stored as a dictionary collection of key-value pairs. Values can be scalars (numbers, strings), arrays, or nested objects.
  9. Update Dart SDK and package dependencies for v4

    Couchbase Lite v4 requires Dart SDK ^3.10.0 due to the use of Dart native assets. The multi-package architecture (cbl_dart, cbl_flutter, etc.) has been replaced by a single cbl package.
    # Remove these from pubspec.yaml:
    # cbl_dart
    # cbl_flutter
    # cbl_flutter_ce or cbl_flutter_ee
    
    # Add/Keep this:
    dependencies:
      cbl: ^4.0.0 # Use latest v4 version
  10. Understand Couchbase Lite database hierarchy

    Couchbase Lite uses a hierarchical structure compatible with Capella databases, allowing for efficient data syncing. The structure maps to relational database terms as follows: Database maps to Database, Scope maps to Schema, and Collection maps to Table. This allows developers to partition data into logical scopes (e.g., a 'local' scope for device-specific configuration and a 'syncing' scope for user data).
  11. Manage Sync Gateway and Peer-to-Peer compatibility for Couchbase Lite v4

    Couchbase Lite for Dart v4 uses the version vector architecture. Adhere to these sync requirements:

    • Sync Gateway: Version 4.0 or later is required. Older versions are not supported.
    • Couchbase Server: Version 7.6.6 or later is required for XDCR interoperability with Sync Gateway 4.0.
    • Peer-to-Peer Sync: Both sides of the connection must use Couchbase Lite v4. Syncing with v3.x peers is not supported.
    • Backward Compatibility: Couchbase Lite 3.x clients can sync with Sync Gateway 4.0, but they lack v4 cluster-switching behavior.
    • Database Migration: Upgrades to version vectors are one-way. Once a database is opened by Couchbase Lite for Dart v4, it cannot be opened by Couchbase Lite 3.x.
  12. SQL++ Query Structure Overview

    SQL++ queries in Couchbase Lite for Dart follow a specific sequence of optional and mandatory clauses:

    1. SELECT: Specifies returned data (Mandatory).
    2. FROM: Specifies the collection (Mandatory).
    3. JOIN: Criteria for joining documents.
    4. WHERE: Filtering criteria.
    5. GROUP BY: Aggregation grouping.
    6. ORDER BY: Result ordering.
    7. LIMIT: Maximum number of results.
    8. OFFSET: Number of results to skip.