Skip to content
pubscout

cbl

4.0.0, released 2 weeks ago by cbl-dart.dev

An offline-first NoSQL document database with SQL++ queries, full-text search, and bi-directional sync.

Rock solid
$ flutter pub add cbl
Source repository

What it does

It provides an embedded NoSQL database for Dart and Flutter applications across multiple platforms. It supports SQL++ queries, live reactive queries, full-text search, and peer-to-peer or server data synchronization.

AI-written summary of version 4.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need an offline-first NoSQL database with complex querying capabilities.
  • You require bi-directional data synchronization with Couchbase Server or peer-to-peer devices.
  • You want reactive live queries that update automatically when data changes.

Skip it when

  • You only need a simple key-value store or lightweight local SQLite database.
  • You are looking for a standard cloud backend without local offline database requirements.

Strengths

  • Supports robust offline-first functionality and local data persistence.
  • Offers bi-directional and peer-to-peer data sync features.
  • Includes powerful SQL++ query support and live queries.

Weaknesses

  • Features like vector search, peer-to-peer sync, and encryption require the Enterprise Edition.
  • Involves complex native tooling and FFI setup compared to pure Dart key-value stores.

Setup

Kind
FFI (native library)
Effort
Medium
Code generation
No
Direct dependencies
12

Add the dependency to pubspec.yaml. Community edition is default, while Enterprise edition requires configuration under hooks in pubspec.yaml.

import 'package:cbl/cbl.dart';

Future<void> main() async {
  final database = await Database.openAsync('my-database');
  final collection = await database.createCollection('tasks');

  await collection.saveDocument(
    MutableDocument({'title': 'Learn Couchbase Lite', 'done': false}),
  );

  final query = await database.createQuery(
    "SELECT * FROM tasks WHERE done = false",
  );
  final results = await (await query.execute()).allResults();
  print('Pending tasks: ${results.length}');

  await database.close();
}

Alternatives

Packages that do the same job and could replace cbl.

  • sqflite

    Pick if you prefer a traditional local SQLite relational database instead of a NoSQL document database.

  • drift

    Pick if you want a type-safe reactive SQLite database builder for Flutter.

  • shared_preferences

    Pick if you only need a simple key-value store for preferences instead of a full document database.

Works with

Packages commonly used together with cbl: ones it builds on, ones built on it, and its own family.