From 46273631d3496586bfb1fa1713c2e9b8484bec61 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Fri, 28 May 2010 15:21:42 -0400 Subject: reorganize rpc calls, add doc_count and update_seq --- src/fabric_rpc.erl | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl index 90ee8627..fa67b13f 100644 --- a/src/fabric_rpc.erl +++ b/src/fabric_rpc.erl @@ -1,14 +1,40 @@ -module(fabric_rpc). --export([get_db_info/1]). +-export([get_db_info/1, get_doc_count/1, get_update_seq/1]). -export([open_doc/3, open_revs/4, get_missing_revs/2, update_docs/3]). --include("../../couch/src/couch_db.hrl"). +-include("fabric.hrl"). -include_lib("eunit/include/eunit.hrl"). +%% rpc endpoints +%% call to with_db will supply your M:F with a #db{} and then remaining args + +get_db_info(DbName) -> + with_db(DbName, {couch_db, get_db_info, []}). + +get_doc_count(DbName) -> + rexi:reply(case couch_db:open(DbName) of + {ok, Db} -> + {ok, {Count, _DelCount}} = couch_btree:full_reduce(Db#db.id_tree), + {ok, Count}; + Error -> + Error + end). + +get_update_seq(DbName) -> + rexi:reply(case couch_db:open(DbName) of + {ok, #db{update_seq = Seq}} -> + {ok, Seq}; + Error -> + Error + end). + open_doc(DbName, DocId, Options) -> with_db(DbName, {couch_db, open_doc_int, [DocId, Options]}). +open_revs(DbName, Id, Revs, Options) -> + with_db(DbName, {couch_db, open_doc_revs, [Id, Revs, Options]}). + get_missing_revs(DbName, IdRevsList) -> % reimplement here so we get [] for Ids with no missing revs in response rexi:reply(case couch_db:open(DbName, []) of @@ -26,15 +52,6 @@ get_missing_revs(DbName, IdRevsList) -> Error end). -open_revs(DbName, Id, Revs, Options) -> - with_db(DbName, {couch_db, open_doc_revs, [Id, Revs, Options]}). - -%% rpc endpoints -%% call to with_db will supply your M:F with a #db{} and then remaining args - -get_db_info(DbName) -> - with_db(DbName, {couch_db, get_db_info, []}). - update_docs(DbName, Docs, Options) -> with_db(DbName, {couch_db, update_docs, [Docs, Options]}). -- cgit v1.2.3