Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Configuration option for using ForestDB #79

Open
lasselaakkonen opened this issue Jun 7, 2016 · 5 comments
Open

Configuration option for using ForestDB #79

lasselaakkonen opened this issue Jun 7, 2016 · 5 comments
Labels

Comments

@lasselaakkonen
Copy link

lasselaakkonen commented Jun 7, 2016

It would be good, if this plugin included a configuration option for using ForestDB.

@keithdmoore
Copy link

+1

1 similar comment
@swaheed2
Copy link
Contributor

+1

@HanzhiDou
Copy link

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.

@swaheed2
Copy link
Contributor

swaheed2 commented Aug 17, 2016

@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);
  1. 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')
}
  1. 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/)

  1. Update to plugins\com.couchbase.lite.phonegap\plugins.xml
  1. 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

@HanzhiDou
Copy link

@swaheed2 thanks a lot for the detail instruction! I will try it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants