Open lasselaakkonen opened 8 years ago
+1
+1
Is there any hard way to use ForestDB at the moment?
I tried to build couchbase-lite-android with hard coded storage type as ForestDB in Manager.java (getDefaultOptions and in openDatabase), and replaced aar and jars in this plugin's lib directory, and also add forestdb aar to plugin.xml, after reinstalled the plugin from local, seems ForestDB is not used, i can not observe any changes.
@HanzhiDou I was able to use ForestDB using these steps:
1) Update the method do_PUT_Database in src/main/java/com/couchbase/lite/router/Router.java and generate the jar file by running ./gradlew build
. The jar file will appear at couchbase-lite-java-core/build/libs
Updated do_PUT_Database
if (db.exists()) {
return new Status(Status.DUPLICATE);
}
try {
// note: synchronized
Map<String, Object> body = getBodyAsDictionary();
if (body == null) {
Log.i(TAG, "No body for do_PUT_Database");
db.open();
}
else{
DatabaseOptions options = new DatabaseOptions();
// ForestDB || SQLite
if(body.containsKey("storageType")){
String storageType = (String) body.get("storageType");
if(storageType.equals(Manager.SQLITE_STORAGE) || storageType.equals(Manager.FORESTDB_STORAGE)){
Log.d(TAG, "Storage type: " + storageType);
options.setStorageType(storageType);
}
}
db.open(options);
}
} catch (CouchbaseLiteException e) {
return e.getCBLStatus();
}
setResponseLocation(connection.getURL());
return new Status(Status.CREATED);
2) add the forestdb dependency to plugins\com.couchbase.lite.phonegap\src\android\build.gradle
dependencies {
compile(name:'couchbase-lite-android-1.3.0', ext:'aar')
compile(name:'couchbase-lite-android-sqlite-custom-1.3.0', ext:'aar')
compile(name:'couchbase-lite-android-forestdb-1.3.0', ext:'aar')
}
3) add the couchbase-lite-android-forestdb-1.3.0.aar to\ plugins\com.couchbase.lite.phonegap\lib\android\lib**
(downloaded from http://files.couchbase.com/maven2/com/couchbase/lite/couchbase-lite-android-forestdb/1.3.0/)
4) Update to plugins\com.couchbase.lite.phonegap\plugins.xml
5) When you are creating the database on the client side, pass the configuration as the request body:
var data = {
storageType : "ForestDB"
//ForestDB
//SQLite
};
6) Finally, a very important step is to recreate the project in cordova so the plugin gets updated
cordova platform rm android
cordova platform add android
@swaheed2 thanks a lot for the detail instruction! I will try it.
It would be good, if this plugin included a configuration option for using ForestDB.