couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benoit Chesneau <bchesn...@gmail.com>
Subject erlang rpc call in couchdb
Date Mon, 27 Jul 2009 17:02:31 GMT
Hi,

During the week-end I've writtent a toolkit to access via HTTP to
couchdb (https://github.com/benoitc/ecouchdbkit) but while annonincg
it this morning i ha d the idee to write a simple gen_server to handle
erlang rpc call in CouchDB. It's based on hovercraft from @jchris.
Currently the module lack the possibility of managing attachments and
view streaming. I would be interrested by any feedback about it. Since
erlang rpc call allow us to not convert results in json it could be
interresting.

So here it is :

http://github.com/benoitc/couchdb/tree/rpc

patch against latest trunk is attached.

Some examples of current features :

start couchdb like this : ERL_FLAGS="-name mynode" ./utils/run

## Get server/db info :

(enki@enlil.local)14> rpc:call(mynode@enlil.local, couch_rpc,
server_info, []).
[{couchdb,<<"Welcome">>},{version,<<"0.10.0a">>}]
(enki@enlil.local)15> rpc:call(mynode@enlil.local, couch_rpc, db_info,
[<<"testdb">>]).
{ok,[{db_name,<<"testdb">>},
     {doc_count,5},
     {doc_del_count,0},
     {update_seq,5},
     {purge_seq,0},
     {compact_running,false},
     {disk_size,4185},
     {instance_start_time,<<"1248688499953918">>},
     {disk_format_version,4}]}


## open/save doc :
(enki@enlil.local)18> rpc:call(mynode@enlil.local, couch_rpc,
save_doc, [<<"testdb">>, {[{<<"testfield">>, <<"somevalue">>}]}]).
{ok,{[{id,<<"7b069de98df234d5b6af4fa5b9125ea1">>},
      {rev,<<"1-73dd06cfa1487a6f79bfcd5d54eb3c9c">>}]}}
(enki@enlil.local)19> rpc:call(mynode@enlil.local, couch_rpc,
open_doc, [<<"testdb">>, <<"7b069de98df234d5b6af4fa5b9125ea1">>]).
{ok,{[{<<"_id">>,<<"7b069de98df234d5b6af4fa5b9125ea1">>},
      {<<"_rev">>,<<"1-73dd06cfa1487a6f79bfcd5d54eb3c9c">>},
      {<<"testfield">>,<<"somevalue">>}]}}

Get a view :
(enki@enlil.local)64> rpc:call(mynode@enlil.local, couch_rpc,
query_view, [<<"inditeweb">>, <<"inditeweb">>, <<"alias">>]).
{ok,{3,0,
     [{{[<<"www">>,<<"benoitc">>,<<"im">>],
        <<"828cd24913a8436a6091249471658f25">>},
       <<"node0">>},
      {{[<<"inditeweb">>,<<"local">>],
        <<"b9e9bb0768627880ece6976aaf98dd92">>},
       <<"node0">>},
      {{[<<"benoitc">>,<<"im">>],
        <<"d2d298c8cf8a3c6ce666f6648f20d248">>},
       <<"node0">>}]}}

- benoƮt

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message