summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_util.erl
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-07-20 04:11:36 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-07-20 04:11:36 +0000
commit46bf4b727f0fae37b017f194983122c50d3f34e5 (patch)
tree658da02543e8f53388d6ea427afa3e6265d5254d /src/couchdb/couch_util.erl
parentc3175ec3b2809a553cd0f45bfa39ca573676f842 (diff)
Initial checkin of _changes filters. The prime weak-spot for this approach is that it maintains an OS-process per connected filtered _changes consumer. I'm pretty sure we'll be able to work around this without changing the API, but it'll involve a lot of OS-process bookkeeping. Those enhancements should generally improve show & list performance as well. Punting on them for now, first wanted to get _changes filters implemented so people could give feedback.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@795687 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_util.erl')
-rw-r--r--src/couchdb/couch_util.erl18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl
index 817572bb..db9f937c 100644
--- a/src/couchdb/couch_util.erl
+++ b/src/couchdb/couch_util.erl
@@ -17,7 +17,7 @@
-export([new_uuid/0, rand32/0, implode/2, collate/2, collate/3]).
-export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]).
-export([encodeBase64/1, decodeBase64/1, to_hex/1,parse_term/1,dict_find/3]).
--export([file_read_size/1]).
+-export([file_read_size/1, get_nested_json_value/2, json_user_ctx/1]).
-export([to_binary/1, to_list/1]).
-include("couch_db.hrl").
@@ -75,6 +75,22 @@ parse_term(List) ->
erl_parse:parse_term(Tokens).
+get_nested_json_value({Props}, [Key|Keys]) ->
+ case proplists:get_value(Key, Props, nil) of
+ nil -> throw({not_found, <<"missing json key: ", Key/binary>>});
+ Value -> get_nested_json_value(Value, Keys)
+ end;
+get_nested_json_value(Value, []) ->
+ Value;
+get_nested_json_value(_NotJSONObj, _) ->
+ throw({not_found, json_mismatch}).
+
+json_user_ctx(#db{name=DbName, user_ctx=Ctx}) ->
+ {[{<<"db">>, DbName},
+ {<<"name">>,Ctx#user_ctx.name},
+ {<<"roles">>,Ctx#user_ctx.roles}]}.
+
+
% returns a random integer
rand32() ->
crypto:rand_uniform(0, 16#100000000).