couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michele Sciabarra <msc...@eprometeus.com>
Subject A modest proposal for an erlang api for couchdb, v2
Date Mon, 15 Sep 2008 10:32:35 GMT
Sorry I am afraid my previous email was not clear enough.
I should not write an email at 1pm in the night!
I was very excited because I have finished my work on defining the API, 
and posted it immediatly.

Anyway, now I try to explain me better.

As I stated previously, I am trying to use CouchDb from another erlang 
application.
For this reason I am bypassing the http layer, and I am trying to talk 
straight to couchdb internals, using the distribuited programming 
features of erlang.
Just starting couchdb adding "-s couch" to the erlang command line was 
enough to access to the internals of couchdb.

But I realized that the internals of CouchDb are, of course, internals. 
Too low level to be useful.
So I started to think about an API to be exposed that is simple enough 
to be used.

To do so, I decided to start from the exposed layer, that is implemented 
in the couch_http.erl file.

My idea was to write a couch_api.erl module that is doing essentially 
the same things that couch_httpd.erl does, only translated in an 
Erlang-ish API.

At the end of this email I am writing the API that I defined.

I will then continue implementing it (just mimicking the work that has 
ben already done in the couch_http.erl file).
I will do it anyway for my own use.

What I am asking, such a module could be interesting/useful enough to be 
contribuited?

If so, I will put much more effort in documenting, writing clean code 
and so on.

----
This is the API I defined:

As a general rule, to get the api I used the HTTP verb (get, post, put ) 
, added a suffix that is the "_xxx" meta operation when available, 
otherwise I added an arbitrary but descriptive suffix.
This is the result of my efforts:

-module(couch_api)

% List all databases
get_all_dbs()

% Generate a new unique id
post_uuid()

% Generate Count new unique ids
post_uuid(Count)

% Create a database
put_db(DbName) when is_binary(DbName)

% Delete a database.
delete_db(DbName)

% Informations on a database
get_status(Db)
% or get_db_status?

% Compact the database
compact_db(Db)
%or get_compat_db?

% All documents
get_all_docs()
get_all_docs(Start, Count)
get_all_docs(Start, Count, Desc)

% Get a document
get_doc(Db, Doc)
get_doc(Db,Doc,revs)   % with revisions
get_doc(Db,Doc,Rev)   % of the specified revision

% Get an attachment
get_attachment(Db, Doc, AttachmentId)

% Create a new named document
put_doc_named(Db, Doc, Term)

% Insert or Replace and attachment
put_attachment(Db, Doc, Attachment) % insert
put_attachment(Db, Doc, Attachment, Rev)  % replace the given revision
 
% Create an unnamed document
post_doc(Db)   

% Bulk insert/update
post_bulk_docs(DbName, Docs)




Mime
View raw message