Couchbase Lite는 Flutter 앱용 가벼운 임베디드 NoSQL 데이터베이스로, 오프라인 데이터 저장 및 장치 간 실시간 동기화를 가능하게 합니다. 모바일 플랫폼을 위해 설계되어 Android와 iOS를 지원하며, Couchbase Sync Gateway를 통해 원활한 동기화 기능을 제공합니다. 이 플러그인은 Couchbase Lite Community Edition을 Flutter 프로젝트에 통합하여 개발자가 구조화된 데이터를 로컬에 저장하고 연결이 복구되면 변경 사항을 동기화할 수 있도록 합니다. 신뢰할 수 있는 오프라인 기능과 장치 간 일관된 데이터가 필요한 애플리케이션에 적합합니다.
사용 사례
오프라인 우선 모바일 애플리케이션
실시간 데이터 동기화
모바일 앱에서의 로컬 데이터 지속성
로컬 데이터베이스가 필요한 하이브리드 앱
디바이스 간 데이터 일관성
주요 기능
임베디드 NoSQL 데이터베이스
Sync Gateway와의 실시간 동기화
강력한 오프라인 지원
크로스 플랫폼(안드로이드 및 iOS)
경량이고 빠른 성능
적합한 대상
오프라인 데이터가 필요한 모바일 앱 개발자
실시간 동기화가 필요한 앱
오프라인 기능을 갖춘 스타트업
NoSQL 데이터 모델을 사용하는 팀
제한된 백엔드 인프라를 갖춘 프로젝트
고려 사항
완전한 동기화를 위해서는 Couchbase Sync Gateway가 필요합니다
Android 및 iOS 플랫폼에 한정
싱크 게이트웨이 통합을 위한 추가 설정
NoSQL 스키마 설계의 학습 곡선
간단한 데이터 요구 사항에 대한 잠재적 과부하
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
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.