Permalink
Browse files

some doc

  • Loading branch information...
benoitc committed Jun 23, 2011
1 parent bbcecf5 commit b73c576fcb0a8a159feac3018de56d82f61dfd63
Showing with 59 additions and 0 deletions.
  1. +59 −0 README.md
View
@@ -14,6 +14,65 @@ This api is compatible with CouchDb 1.1.x and trunk (1.2.x) .
Note: Move it in couchdb beam folder if you want to use it easily.
+## Getting started
+
+### Create a database
+
+ Options = [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}],
+ {ok, Db} = couchc:create_db("couchc_testdb", Options).
+
+
+### Save a document
+
+ Doc = {[{<<"_id">>, <<"doc1">>}, {<<"v">>, 1}]},
+ {pk, DocID, DocRev} = couchc:save_doc(Db, Doc).
+
+### Open a document
+
+ {ok, Doc1} = couchc:open_doc(Db, DocId).
+
+### Delete a document
+
+ {ok, DocID, NewDocRev} = couchc:delete_doc(Doc, {DocId, DocRev}).
+
+### Save multiple documents
+
+ Docs = [
+ {[{<<"_id">>, <<"a">>}, {<<"v">>, 1}, {<<"t">>, <<"test">>}]},
+ {[{<<"_id">>, <<"b">>}, {<<"v">>, 2}, {<<"t">>, <<"test">>}]}],
+ Results = couchc:save_docs(Db, Docs),
+
+### Get all documents
+
+ {ok, {TotalRowsCount, Offset, Results1}} = couchc:all(Db).
+
+### Views
+
+ DesignDoc = {[
+ {<<"_id">>, <<"_design/test">>},
+ {<<"language">>,<<"javascript">>},
+ {<<"views">>,
+ {[{<<"v1">>,
+ {[{<<"map">>,
+ <<"function (doc) {\n if (doc.t == \"test\") {\n emit(doc._id, doc);\n}\n}">>
+ }]}
+ }]}}]},
+
+ {ok, _, _} = couchc:save_doc(Db, DesignDoc),
+ {ok, {TotalRowsCount, Offset, Results1}} = couchc:all(Db, {<<"test">>, <<"v1">>})
+
+This function get all documents in the view. You can use fold instead of
+all to fold documents. the all function is written like this:
+
+
+ collect_results(Row, Acc) ->
+ {ok, [Row | Acc]}.
+
+ all(Db, ViewName, Options) ->
+ fold(Db, ViewName, fun collect_results/2, Options).
+
+That's it. More documentation is coming soon.
+
## Test it
$ ERL_FLAGS="-pa /path/to/couchc" ./util/run -i

0 comments on commit b73c576

Please sign in to comment.