Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status

NIF based Erlang bindings for couchbase based on libcouchbase. CBERL is at early stage of development, it only supports very basic functionality. Please submit bugs and patches if you find any. Tested on OSX, Debian Squeeze and Amazon Linux.

Quick Setup/Start

First you must have libcouchbase installed.

On OSX install homebrew if you haven't already then run:

brew update && brew install libcouchbase

On Amazon linux:

sudo wget -O/etc/yum.repos.d/couchbase.repo
sudo yum check-update
sudo yum install --enablerepo=epel libcouchbase2 libcouchbase-devel

For installing libcouchbase on other systems visit


git clone
cd cberl
# assuming you have rebar in your path
rebar get-deps compile

Or just include it as a dependency in your rebar config.


Make sure you have couchbase running on localhost or use cberl:new(Host) instead.

% create a connection pool  of 5 connections named cberl_default
% you can provide more argument like host, username, password, 
% bucket and transcoder - look at for more detail 
cberl:start_link(cberl_default, 5).
{ok, <0.33.0>}
% Poolname, Key, Expire - 0 for infinity, Value
cberl:set(cberl_default, <<"fkey">>, 0, <<"cberl">>).
cberl:get(cberl_default, <<"fkey">>).
{<<"fkey">>, ReturnedCasValue, <<"cberl">>}

For more information on all the functions -> ./rebar doc (most of documentation is out of date right now)


cberl has support for querying views via the view/4 functions:

cberl:view(cberl_default, "all", "all", []).

Shorthand for foldl, foldr and foreach are also provided.


cberl has support for N1QL queries via the n1ql/4 and n1ql/5 functions:

Dog = {[{<<"type">>,<<"dog">>},
cberl:set(cberl_default, <<"tom">>, 0, Dog).
cberl:n1ql(cberl_default, <<"SELECT * FROM default WHERE type=$1 and age=$2 and color=$3">>, [<<"\"dog\"">>, <<"5">>, <<"\"white\"">>], false).

Custom Transcoders

You can have your custom transcoders, your transcoder must export 3 functions:


Takes in an encoder|encoder list and the original value and turns it into a binary.


Takes in a flag (from couchbase) and the value (as binary) and turns it into the actual value.


Turns an encoder_name (or list of them) into an integer. This value is sent to CB during set operations and this is what you get in decode value. You must return a value for 'standard' encoder if you are not planning to specify an encoder for every set operation.

Check out cberl_transcoder.erl it is pretty straightforward.