Flutter-Plugin für Couchbase Lite Community Edition, eine eingebettete, leichte NoSQL-Datenbank mit Live-Synchronisierung und Offline-Unterstützung für Android und iOS.
Aus öffentlichen Paketdaten erstellte Orientierung.
Couchbase Lite ist eine leichte, eingebettete NoSQL-Datenbank für Flutter-Anwendungen, die Offline-Datenspeicherung und Echtzeit-Synchronisierung über Geräte hinweg ermöglicht. Für mobile Plattformen entwickelt, unterstützt sie Android und iOS mit nahtloser Synchronisierung über den Couchbase Sync Gateway. Das Plugin integriert die Community-Edition von Couchbase Lite in Flutter-Projekte, sodass Entwickler strukturierte Daten lokal speichern und Änderungen synchronisieren können, sobald die Verbindung wiederhergestellt ist. Ideal für Anwendungen, die zuverlässige Offline-Funktionalität und konsistente Daten über Geräte hinweg erfordern.
Anwendungsfälle
Offline-first-Mobile-Anwendungen
Echtzeit-Daten-Synchronisierung
Lokale Datenpersistenz in mobilen Apps
Hybrid-Apps, die eine lokale Datenbank benötigen
Konsistenz von Daten über Geräte hinweg
Hauptmerkmale
Eingebettete NoSQL-Datenbank
Echtzeit-Synchronisierung mit dem Sync Gateway
Robuste Offline-Unterstützung
Plattformübergreifend (Android & iOS)
Leicht und schnelle Leistung
Geeignet für
Mobile App Entwickler, die Offline-Daten benötigen
Apps, die Echtzeit-Synchronisation erfordern
Startups, die offline-fähige Funktionen entwickeln
Teams, die NoSQL-Datenmodelle verwenden
Projekte mit begrenzter Backend-Infrastruktur
Hinweise
Benötigt Couchbase Sync Gateway für vollständige Synchronisierung
Beschränkt auf die Plattformen Android und iOS
Zusätzliche Einrichtung für die Sync Gateway-Integration
Lernkurve für NoSQL-Schemadesign
Potenzielle Überhead für einfache Dateneinsätze
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
couchbase_lite plugin
A Flutter plugin for Couchbase Lite Community Edition. An embedded lightweight, noSQL database with live synchronization and offline support on Android and iOS.
The goal of this project is to align this library with the Swift SDK API for Couchbase Lite.
Note: This plugin is still under development, and some APIs might not be available yet.
Feedback and Pull Requests are most welcome!
Note: Included in this example is sync-gateway-config.json (Login => u: foo, p: bar)
Usage example
Below is an example for the database using the BLoC pattern ( View <-> BLoC <-> Repository <-> Database )
// Initialize the databasetry {
database = awaitDatabase.initWithName("gettingStarted");
} onPlatformException {
return"Error initializing database";
}
// Create a new document (i.e. a record) in the database.var mutableDoc = MutableDocument()
.setDouble("version", 2.0)
.setString("type", "SDK");
// Save it to the database.try{
await database.saveDocument(mutableDoc);
} onPlatformException {
return"Error saving document";
}
// Update a document.
mutableDoc = (await database.document(mutableDoc.id))?.toMutable()?.setString("language", "Dart");
if (mutableDoc != null) {
// Save it to the database.try {
await database.saveDocument(mutableDoc);
vardocument = await database.document(mutableDoc.id);
// Log the document ID (generated by the database)// and propertiesprint("Document ID :: ${document.id}");
print("Learning ${document.getString("language")}");
} onPlatformException {
return"Error saving document";
}
}
// Create a query to fetch documents of type SDK.var query = QueryBuilder
.select([SelectResult.all().from("mydocs")])
.from("gettingStarted", as: "mydocs")
.where(Expression.property("type").from("mydocs").equalTo(Expression.string("SDK")));
// Run the query.try {
var result = await query.execute();
print("Number of rows :: ${result.allResults().length}");
} onPlatformException {
return"Error running the query";
}
// Note wss://10.0.2.2:4984/my-database is for the android simulator on your local machine's couchbase database// Create replicators to push and pull changes to and from the cloud.ReplicatorConfiguration config =
ReplicatorConfiguration(database, "ws://10.0.2.2:4984/beer-sample");
config.replicatorType = ReplicatorType.pushAndPull;
config.continuous = true;
// Add authentication.
config.authenticator = BasicAuthenticator("foo", "bar");
// Create replicator (make sure to add an instance or static variable named replicator)var replicator = Replicator(config);
// Listen to replicator change events.
_listenerToken = replicator.addChangeListener((ReplicatorChange event) {
if (event.status.error != null) {
print("Error: " + event.status.error);
}
print(event.status.activity.toString());
});
// Start replication.await replicator.start();
For this getting started guide, you will need to allow using ws protocol.
As of Android Pie, version 9, API 28, cleartext support is disabled, by default. Although wss: protocol URLs are not affected, in order to use the ws: protocol, applications must target API 27 or lower, or must configure application network security as described here.
App Transport Security is enabled by default since iOS 9 and enforces applications to use HTTPS exclusively. For this getting started guide, you will disable it but we recommend to enable it in production (and enable HTTPS on Sync Gateway). In the Xcode navigator, right-click on Info.plist and open it as a source file.
Append the following inside of the XML tags to disable ATS.