Created
December 23, 2022 19:35
-
-
Save nickva/2027f36ebb3ca1c7ae93b314e60b2440 to your computer and use it in GitHub Desktop.
Luerl for CouchDB Views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1> application:start(luerl), | |
1> F1 = "function(doc) emit('key1', doc) \n emit('key2', 'val2') end", | |
1> F2 = "function(doc) emit('key3', 'val3') end", | |
1> S0 = luerl_sandbox:init(), | |
1> {_, S1} = luerl:do("emits = {} \n function emit(k, v) \n table.insert(emits, {k, v}) end", S0), | |
1> {ok, C1, S2} = luerl:load("f = " ++ F1 ++ " \n f(...) \n return emits", S1), | |
1> {ok, C2, S3} = luerl:load("f = " ++ F2 ++ " \n f(...) \n return emits", S2), | |
1> {R1, _} = luerl:call_chunk(C1, [#{<<"_id">> => <<"1">>, <<"a">> => <<"b">>}], S3), | |
1> {R2, _} = luerl:call_chunk(C2, [#{<<"_id">> => <<"1">>, <<"a">> => <<"b">>}], S3), | |
1> #{<<"r1">> => R1, <<"r2">> => R2}. | |
#{<<"r1">> => | |
[[{1, | |
[{1,<<"key1">>}, | |
{2,[{<<"_id">>,<<"1">>},{<<"a">>,<<"b">>}]}]}, | |
{2,[{1,<<"key2">>},{2,<<"val2">>}]}]], | |
<<"r2">> => [[{1,[{1,<<"key3">>},{2,<<"val3">>}]}]]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment