[erlang-questions] How to access CouchDB?
Yves S. Garret
yoursurrogategod@REDACTED
Fri Aug 9 22:47:44 CEST 2013
On Fri, Aug 9, 2013 at 3:36 PM, Yves S. Garret
<yoursurrogategod@REDACTED>wrote:
> On Fri, Aug 9, 2013 at 12:57 PM, Benoit Chesneau <bchesneau@REDACTED>wrote:
>
>> not sure if it can help but you can use http://github.com/benoitc/couchcwhich abstract the internal couchdb api .
>>
>> - benoitc
>>
>>
>> On Friday, August 9, 2013, Yves S. Garret wrote:
>>
>>> Hello,
>>>
>>> I have a small database that's running right now in CouchDB, it's called
>>> sample_database. What I'd
>>> like to do is to read, create, delete, update documents and run some of
>>> the views inside from an
>>> Erlang app. I looked online and found this example:
>>>
>>> http://www.softwarepassion.com/importing-data-to-couchdb-java-ruby-and-erlang-way/
>>>
>>> From that, I proceeded to make the following little script:
>>> -module(test).
>>>
>>> -import(queue,[in/1,out/1,new/0]).
>>> -export([start/0]).
>>> -include("../couch_db.hrl").
>>>
>>> -define(ADMIN_USER_CTX, {user_ctx, #user_ctx{roles = [<<"_admin">>]}}).
>>>
>>> start() ->
>>> io:format("Hello world!~n~n"),
>>>
>>> couch_db:open(<<"sample_database">>, [?ADMIN_USER_CTX]).
>>>
>>> However, when I run this, I get the following error:
>>> 18> test:start().
>>> Hello world!
>>>
>>> ** exception error: undefined function couch_db:open/2
>>>
>>> It's obvious I'm not including a library of some sort. I'm curious how
>>> I can connect to my little
>>> database in the simplest way possible just to start with. Has anyone
>>> done this before?
>>>
>>
> And I've spoken too soon :) .
>
> This is the code that I currently have:
>
> -module(test).
>
> -import(queue,[in/1,out/1,new/0]).
> -export([start/0]).
> % /opt/local/lib/couchdb/erlang/lib/couch-1.3.1/ebin
>
> -include("/opt/local/lib/couchdb/erlang/lib/couch-1.3.1/include/couch_db.hrl").
>
> -define(ADMIN_USER_CTX, {user_ctx, #user_ctx{roles = [<<"some_user">>]}}).
>
> start() ->
> io:format("Hello world!~n~n"),
>
> couch_db:open(<<"sample_database">>, [?ADMIN_USER_CTX]).
>
> It compiles just fine, but when I run it, this is the error that I get:
> > c(test).
> {ok,test}
> > test:start().
> Hello world!
>
> ** exception error: bad argument
> in function ets:lookup/2
> called as ets:lookup(couch_config,{"replicator","db"})
> in call from couch_config:get/3 (couch_config.erl, line 62)
> in call from couch_server:maybe_add_sys_db_callbacks/2
> (couch_server.erl, line 89)
> in call from couch_server:open/2 (couch_server.erl, line 64)
> in call from couch_db:open/2 (couch_db.erl, line 79)
>
> I'll be digging into why this is happening.
>
As a work around, I'm thinking of using os:cmd("curl -i -X GET ..."), but
that seems like it could
be done better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130809/5db872d8/attachment.htm>
More information about the erlang-questions
mailing list