summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2010-05-28 10:17:50 -0400
committerAdam Kocoloski <adam@cloudant.com>2010-05-28 10:24:21 -0400
commita0823f1861d2b571537f75b151e936824dac068b (patch)
tree74401a21d6eaca53116e87b20c1b6c53efb8641a /src
parenta60895fedef53626b622f04af4d20a5792cfbd7d (diff)
more forgiving interface for fabric
Diffstat (limited to 'src')
-rw-r--r--src/fabric.erl59
1 files changed, 46 insertions, 13 deletions
diff --git a/src/fabric.erl b/src/fabric.erl
index 0957387e..e0ffe16b 100644
--- a/src/fabric.erl
+++ b/src/fabric.erl
@@ -1,7 +1,8 @@
-module(fabric).
--export([all_databases/1, create_db/2, delete_db/2, open_doc/3, open_doc/4,
- get_db_info/2, db_path/2]).
+-export([all_databases/1, create_db/2, delete_db/2, get_db_info/2,
+ db_path/2]).
+-export([open_doc/3, open_revs/4, update_docs/3]).
-include("../../couch/src/couch_db.hrl").
@@ -17,26 +18,58 @@ all_databases(Customer) ->
fabric_db:all_databases(Customer).
get_db_info(DbName, Customer) ->
- fabric_db:get_db_info(DbName, Customer).
+ fabric_db:get_db_info(dbname(DbName), Customer).
create_db(DbName, Options) ->
- fabric_db:create_db(DbName, Options).
+ fabric_db:create_db(dbname(DbName), Options).
delete_db(DbName, Options) ->
- fabric_db:delete_db(DbName, Options).
+ fabric_db:delete_db(dbname(DbName), Options).
-% doc operations
-open_doc(Db, DocId, Options) ->
- fabric_doc:open_doc(Db, DocId, Options).
-open_doc(Db, DocId, Revs, Options) ->
- fabric_doc:open_doc(Db, DocId, Revs, Options).
+open_doc(DbName, Id, Options) ->
+ fabric_doc:open_doc(dbname(DbName), docid(Id), Options).
+open_revs(DbName, Id, Revs, Options) ->
+ fabric_doc:open_revs(dbname(DbName), docid(Id), Revs, Options).
+
+update_docs(DbName, Docs, Options) ->
+ fabric_doc:update_docs(dbname(DbName), docs(Docs), Options).
+
+
+%% some simple type validation and transcoding
+
+dbname(DbName) when is_list(DbName) ->
+ list_to_binary(DbName);
+dbname(DbName) when is_binary(DbName) ->
+ DbName;
+dbname(DbName) ->
+ erlang:error({illegal_database_name, DbName}).
+
+docid(DocId) when is_list(DocId) ->
+ list_to_binary(DocId);
+docid(DocId) when is_binary(DocId) ->
+ DocId;
+docid(DocId) ->
+ erlang:error({illegal_docid, DocId}).
+
+docs(Docs) when is_list(Docs) ->
+ [doc(D) || D <- Docs];
+docs(#doc{} = Doc) ->
+ [Doc];
+docs({_} = Doc) ->
+ [couch_doc:from_json_obj(Doc)];
+docs(Docs) ->
+ erlang:error({illegal_docs_list, Docs}).
+
+doc(#doc{} = Doc) ->
+ Doc;
+doc({_} = Doc) ->
+ couch_doc:from_json_obj(Doc);
+doc(Doc) ->
+ erlang:error({illegal_doc_format, Doc}).
-%%
-%% internal
-%%
generate_customer_path("/", _Customer) ->
"";
generate_customer_path("/favicon.ico", _Customer) ->