diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-08-20 13:06:46 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-09-25 09:42:45 -0500 |
commit | 87379c2beafd495583cec3afbf275841ede50be2 (patch) | |
tree | 66b53f27dfff9437645de46610167f265c331007 | |
parent | 41b72111b130fa0c5e04eb9b670f5d575eacb62e (diff) | |
download | couchdb-87379c2beafd495583cec3afbf275841ede50be2.tar.gz |
Implement couch_js callbacks for couch_eval
-rw-r--r-- | rel/overlay/etc/default.ini | 6 | ||||
-rw-r--r-- | src/couch_js/src/couch_js.erl | 51 |
2 files changed, 57 insertions, 0 deletions
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini index 51d450bd7..79555f3c0 100644 --- a/rel/overlay/etc/default.ini +++ b/rel/overlay/etc/default.ini @@ -313,6 +313,12 @@ os_process_limit = 100 ;query_limit = 268435456 ;partition_query_limit = 268435456 +[couch_eval.languages] +; The list of modules that implement the couch_eval +; beahvior for executing provided code in design +; documents. +javascript = couch_js + [mango] ; Set to true to disable the "index all fields" text index, which can lead ; to out of memory issues when users have documents with nested array fields. diff --git a/src/couch_js/src/couch_js.erl b/src/couch_js/src/couch_js.erl new file mode 100644 index 000000000..1bc0f1927 --- /dev/null +++ b/src/couch_js/src/couch_js.erl @@ -0,0 +1,51 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + + +-module(couch_js). +-behavior(couch_eval). + + +-export([ + acquire_map_context/1, + release_map_context/1, + map_docs/2 +]). + + +-include_lib("couch/include/couch_db.hrl"). + + +-define(JS, <<"javascript">>). + + +acquire_map_context(Opts) -> + #{ + map_funs := MapFuns, + lib := Lib + } = Opts, + couch_js_query_servers:start_doc_map(?JS, MapFuns, Lib). + + +release_map_context(Proc) -> + couch_js_query_servers:stop_doc_map(Proc). + + +map_docs(Proc, Docs) -> + {ok, lists:map(fun(Doc) -> + {ok, RawResults} = couch_js_query_servers:map_doc_raw(Proc, Doc), + Results = couch_js_query_servers:raw_to_ejson(RawResults), + Tupled = lists:map(fun(ViewResult) -> + lists:map(fun([K, V]) -> {K, V} end, ViewResult) + end, Results), + {Doc#doc.id, Tupled} + end, Docs)}. |