Enabling ForestDB for CBL Android

Since version 1.2.0, Couchbase Lite supports ForestDB as a storage. This post explains how to enable forestdb storage for Couchbase Lite Android.

What is ForestDB? From forestdb README:

ForestDB is a key-value storage engine that is developed by Couchbase Caching and Storage Team, and its main index structure is built from Hierarchical B+-Tree based Trie, called HB+-Trie. Compared with traditional B+-Tree based storage engines, ForestDB shows significantly better read and write performance with less storage overhead.

Installing ForestDB module:

ForestDB is a optional. It is not part of default dependencies of couchbase-lite-android. You needs to add forestdb as a dependency in the application level build.gradle file.

dependencies {
  compile 'com.couchbase.lite:couchbase-lite-android:1.2.1'
  compile 'com.couchbase.lite:couchbase-lite-android-forestdb:1.2.1'

How to enable ForestDB:

Couchbase Lite’s default storage is SQLite. You needs to specify ForestDB as your database storage type. When open the database, please specify ForestDB with using DatabaseOptions.

DatabaseOptions options = new DatabaseOptions();
Database database = manager.openDatabase(DATABASE_NAME, options);

NOTE: Internal implementations of ForestDB and SQLite are different, but both should behave same. So you don’t need to do anything else to use ForestDB with Couchbase Lite

Sample App:

Please refer GrocerySync-Android forestdb branch as a sample Android application.

Written on May 8, 2016