-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcdb-view.js
More file actions
56 lines (49 loc) · 1.46 KB
/
Copy pathcdb-view.js
File metadata and controls
56 lines (49 loc) · 1.46 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var sys = require("sys");
var BNJ = require("./benejson");
/* CouchDB view response parser to incrementally parse each row. */
var viewParser = {
/* Force distinct callback for beginning of map.
* Key will be null here. */
"{":function(key){
sys.puts("Beginning couchdb response..");
},
/* Catchall for other data.
* Because we have an expectation of the couchdb view format, we know
* that the "rows" key will be last. */
"*":function(data){
sys.puts("Total Rows: " + data.total_rows);
sys.puts("Offset : " + data.offset);
},
/* The '.' character prefixes a key.
* In this case, just match key "rows". It must be an array.
*
* -When specifying array callbacks:
* The first element is the callback when the array starts (before 0th elem).
* The second element is the callback for each element in the array
* The third callback is for the array end.
* The fourth callback is to handle a parsing exception found in a row. */
".rows":[
function(key){
sys.puts("Starting Rows:");
},
function(row){
sys.puts(row);
},
function(){
sys.puts("Ended Rows.");
}
],
/* Force distinct callback for end of map. */
"}":function(){
sys.puts("Ending couchdb response..");
}
}
/* */
var couchTest = new BNJ.JSONParser(viewParser);
var tokenizer = new BNJ.JSONTokenizer();
tokenizer.setCallback(btest.getBindFn());
var stdin = process.openStdin();
stdin.setEncoding("utf8");
stdin.on("data", function(chunk){
tokenizer.process(chunk);
});