-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.js
61 lines (50 loc) · 1.11 KB
/
data.js
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
57
58
59
60
61
var cradle = require('cradle')
, util = require('util');
var conn = new(cradle.Connection)('http://localhost', 5984, {});
var db = conn.database('events');
/*
db.get(‘vader', function (err, doc) {
doc.name; // 'Darth Vader'
assert.equal(doc.force, 'dark');
});
*/
/*
db.save('_design/user', {
views: {
force: {
map: "function (doc, force) { if(doc.force && doc.force == force) { emit(doc.username, doc) } }"
}
}
}, function (err, res) {
if (err) {
console.log(err);
} else {
// Handle success
console.log("well done");
console.log(res);
}
});
*/
db.save([
{ name: "Serg", date: new Date(2012, 2, 21, 7, 30, 0) }
// { name: "matt", date: new Date() }
], function (err, res) {
if (err) {
// Handle error
} else {
// Handle success
console.log("well done");
console.log(res);
}
});
db.view('events/all',function(error, result) {
if( error ){
util.log(error);
}else{
result.forEach(function (doc){
util.log(util.inspect(doc))
util.log(util.inspect(doc.date))
util.log(typeof(doc.date))
});
}
});