RSS feed
<< Patching the erlang.el mode | Home

Connecting to couchdb using his API

An alternative approach to use Couchdb from Erlang

Currently the couchdb wiki lists a couple of Erlang API to connect to couchdb, but I am not happy with both of them. For example, I have not yet figured out how to use them to add an attachment to a couchdb document.

Erlang however allow to connect to a remote Erlang process using his distribuited programming facilities. Damien (Katz, the Couchdb author) stated both in the Wiki and in the mailing list that you should just use a polished, cleaned up, subset of the current API  (that will be guarantee to be stable) to do such a work.

So I tried. First I had to hack the couchdb launch script, so I changed the "erl" command line adding "erl -name couch" to make the couchdb an erlang node (accessiblie from others nodes).

Then I looked to source code, and I found that there is and edoc for all the API. Well, sort of, because almost all of the are simply the function signature. But enough to do some experimentation.

So I started another erlang node (called vesia) and tried to create a new database.

(vesia@msciab)2> rpc:call(couch@msciab, couch_server, all_databases, []).  
{ok,[<<"test">>]}

Wow! it shows the current databases. Let's try to create one.

(vesia@msciab)4> rpc:call(couch@msciab, couch_server, create, [<<"demo">>,[]]).
{ok,{db,<6957.79.0>,<6957.80.0>,nil,<6957.78.0>,
        {db_header,0,0,nil,nil,nil,nil,0,0},        
{stream,<6957.81.0>,<6957.78.0>},        
{btree,<6957.78.0>,nil,#Fun<couch_db_updater.3.13881194>,
               #Fun<couch_db_updater.4.46858414>,               
#Fun<couch_db_updater.2.85617986>,               
#Fun<couch_db_updater.5.119231295>},        
{btree,<6957.78.0>,nil,#Fun<couch_db_updater.6.72262359>,
                #Fun<couch_db_updater.7.82503760>,
                #Fun<couch_btree.5.112258129>,
                #Fun<couch_db_updater.8.103814714>},
         {btree,<6957.78.0>,nil,#Fun<couch_btree.0.23070627>,
                #Fun<couch_btree.1.117278773>,
#Fun<couch_btree.2.112258129>,
                nil},
        0,0,0,<<"demo">>,      
  "/usr/local/couchdb/691737/var/lib/couchdb/demo.couch"}}

Something positive happened. The "ok" looks promising. Indeed:

(vesia@msciab)5> rpc:call(couch@msciab, couch_server, all_databases, []).     
{ok,[<<"demo">>,<<"test">>]}
Fine! We are going in the right direction. More to come. Stay tuned if interested.


romvcwct

okjoqubg [URL=http://tfxipgvv.com]qseixqto[/URL] mfbwyteq http://jqikcvmx.com fcqdnocx ahzgnbry

Add a comment Send a TrackBack