Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SaltechSystems/couchbase_lite
Flutter plugin for the Community edition of Couchbase Lite. Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine.
https://github.com/SaltechSystems/couchbase_lite
android couchbase dart flutter flutter-package flutter-plugin ios nosql package plugin
Last synced: 3 months ago
JSON representation
Flutter plugin for the Community edition of Couchbase Lite. Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine.
- Host: GitHub
- URL: https://github.com/SaltechSystems/couchbase_lite
- Owner: SaltechSystems
- License: mit
- Created: 2019-06-10T13:20:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-20T14:32:14.000Z (over 2 years ago)
- Last Synced: 2024-06-28T01:46:48.194Z (5 months ago)
- Topics: android, couchbase, dart, flutter, flutter-package, flutter-plugin, ios, nosql, package, plugin
- Language: Dart
- Size: 9.28 MB
- Stars: 61
- Watchers: 10
- Forks: 29
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# couchbase_lite plugin
[![Build Status](https://travis-ci.org/SaltechSystems/couchbase_lite.svg?branch=master)](https://travis-ci.org/SaltechSystems/couchbase_lite)
[![Coverage Status](https://coveralls.io/repos/github/SaltechSystems/couchbase_lite/badge.svg?branch=master)](https://coveralls.io/github/SaltechSystems/couchbase_lite?branch=master)
[![pub package](https://img.shields.io/pub/v/couchbase_lite.svg)](https://pub.dartlang.org/packages/couchbase_lite)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](https://docs.couchbase.com/mobile/2.5.0/couchbase-lite-swift/) for Couchbase Lite.
*Note*: This plugin is still under development, and some APIs might not be available yet.
[Feedback](https://github.com/SaltechSystems/couchbase_lite/issues) and [Pull Requests](https://github.com/SaltechSystems/couchbase_lite/pulls) are most welcome!This project forked from [Fluttercouch](https://github.com/oltrenuovefrontiere/fluttercouch)
## Getting Started
In your flutter project add the dependency:
```yaml
dependencies:
couchbase_lite: ^2.7.1
flutter:
sdk: flutter
```For help getting started with Flutter, view the
[online documentation](https://flutter.dev/docs)## Supported Versions
### iOS
| Platform | Minimum OS version |
| -------- | ----------------------- |
| iOS | 10.0 (9.0 - DEPRECATED) |### Android
| Platform | Runtime architectures | Minimum API Level |
| -------- | --------------------- | ------------------- |
| Android | armeabi-v7a | 22 (19 - DEPRECATED)|
| Android | arm64-v8a | 22 (21 - DEPRECATED)|
| Android | x86 | 22 (19 - DEPRECATED)|
| Android | x86_64 | 22 |## API References
[Swift SDK API References](https://docs.couchbase.com/mobile/2.7.0/couchbase-lite-swift/)
[Java SDK API References](https://docs.couchbase.com/mobile/2.7.0/couchbase-lite-java)
*Note*: Syntax follows the Swift SDK but these are the SDKs used for the platform code.
## Local Server Setup
Download and setup Couchbase Server / Sync Gateway Community Editions on your local machine the following link
- [Sync Gatway Getting Started](https://docs.couchbase.com/sync-gateway/current/getting-started.html)
- [Couchbase Downloads](https://www.couchbase.com/downloads)Setup beer-sample database [Local Couchbase Server](http://127.0.0.1:8091/):
- Add the beer-sample bucket: Settings > Sample Buckets
- Create a sync_gateway user in the Couchbase Server under Security
- Give sync_gateway access to the beer-sampleStart Sync Gateway:
~/Downloads/couchbase-sync-gateway/bin/sync_gateway ~/path/to/sync-gateway-config.json
*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 )
```dart
// Initialize the database
try {
database = await Database.initWithName("gettingStarted");
} on PlatformException {
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);
} on PlatformException {
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);var document = await database.document(mutableDoc.id);
// Log the document ID (generated by the database)
// and properties
print("Document ID :: ${document.id}");
print("Learning ${document.getString("language")}");
} on PlatformException {
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}");
} on PlatformException {
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](https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted).
```xml
```
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](https://docs.couchbase.com/sync-gateway/2.7/security.html#connection-to-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.
```xml
NSAppTransportSecurityNSAllowsArbitraryLoads
```