You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/09/16 16:38:06 UTC
[couchdb] 03/05: Implement couch_js callbacks for couch_eval
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch prototype/fdb-layer-couch-eval
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 1da6ba1f06d6ddfb6012a5a1216cd6e404ff9c5b
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Aug 20 13:06:46 2019 -0500
Implement couch_js callbacks for couch_eval
---
rel/overlay/etc/default.ini | 3 +++
src/couch_js/src/couch_js.erl | 51 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 51d450b..68652ee 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -313,6 +313,9 @@ os_process_limit = 100
;query_limit = 268435456
;partition_query_limit = 268435456
+[couch_eval.languages]
+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 0000000..1bc0f19
--- /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)}.