Revision 376138333761 () - Diff

Link to this snippet: https://friendpaste.com/3jKO3YtxApmRlLChPgJ5kf
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
couchbeam:start(),
Connection = couchbeam_server:start_connection_link(),
Db = couchbeam_server:open_db("couchbeam_tests"),
Doc = {[{<<"test">>, <<"blah">>}, {<<"type">>, <<"test">>}]},
Doc0 = {[
{<<"_id">>, <<"test0">>},
{<<"type">>, <<"test">>}
]},
Doc01 = couchbeam_db:save_doc(Db, Doc),
DesignDoc = {[
{<<"_id">>, <<"_design/test">>},
{<<"language">>,<<"javascript">>},
{<<"views">>,
{[{<<"test">>,
{[{<<"map">>,
<<"function (doc) {\n if (doc.type == \"test\") {\n emit(doc._id, doc);\n}\n}">>
}]}
}]}
}]},
couchbeam_db:save_doc(Db, DesignDoc),
Doc1 = {[
{<<"_id">>, <<"test">>},
{<<"type">>, <<"test">>}
]},
Doc2 = {[
{<<"_id">>, <<"test2">>},
{<<"type">>, <<"test">>}
]},
Doc3 = {[
{<<"_id">>, <<"test3">>},
{<<"type">>, <<"test">>}
]},
couchbeam_db:save_doc(Db, Doc1),
couchbeam_db:save_doc(Db, Doc2),
couchbeam_db:save_doc(Db, Doc3),
ViewPid = couchbeam_db:query_view(Db, {"test", "test"}, []),
NbResults = couchbeam_view:count(ViewPid).