Giter Club home page Giter Club logo

cberl's Introduction

CBERL

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 http://packages.couchbase.com/rpm/couchbase-centos62-x86_64.repo
sudo yum check-update
sudo yum install --enablerepo=epel libcouchbase2 libcouchbase-devel

For installing libcouchbase on other systems visit http://www.couchbase.com/develop/c/current.

Then:

git clone [email protected]:chitika/cberl.git
cd cberl
# assuming you have rebar in your path
rebar get-deps compile

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

Example

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 https://github.com/wcummings/cberl/blob/master/src/cberl.erl 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">>).
ok
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)

Views

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

cberl:view(cberl_default, "all", "all", []).
{ok,{1,
    [[{<<"id">>,<<"test">>},
    {<<"key">>,<<"test">>},
    {<<"value">>,null}]]}}

Shorthand for foldl, foldr and foreach are also provided.

N1QL

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

Dog = {[{<<"type">>,<<"dog">>},
  {<<"name">>,<<"tom">>},
  {<<"age">>,5},
  {<<"color">>,<<"white">>}]}.
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).
{ok,{[{<<"requestID">>,
       <<"a00b80e8-aea8-4a23-a0a9-5aba26d2b48f">>},
      {<<"signature">>,{[{<<"*">>,<<"*">>}]}},
      {<<"results">>,[]},
      {<<"status">>,<<"success">>},
      {<<"metrics">>,
       {[{<<"elapsedTime">>,<<"21.644116ms">>},
         {<<"executionTime">>,<<"21.60625ms">>},
         {<<"resultCount">>,1},
         {<<"resultSize">>,171}]}}]},
    [{[{<<"default">>,
        {[{<<"age">>,5},
          {<<"color">>,<<"white">>},
          {<<"name">>,<<"tom">>},
          {<<"type">>,<<"dog">>}]}}]}]}

Custom Transcoders

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

encode_value/2:

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

decode_value/2:

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

flag/1:

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.

cberl's People

Contributors

aliyakamercan avatar aoeking avatar divolgin avatar hlieberman avatar mcredjay avatar n1rvana avatar nakrakiiya avatar sideshowcoder avatar soup-in-boots avatar teh-cmc avatar vincentdephily avatar wcummings avatar xuthief avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.