-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
36 lines (30 loc) · 743 Bytes
/
init.js
File metadata and controls
36 lines (30 loc) · 743 Bytes
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
require("underscore")
var
dbName = 'backbone-svg-demo'
designDocId = "_design/drawing"
couchdb = require('couchdb'),
client = couchdb.createClient(5984, 'localhost'),
db = client.db(dbName)
db.create()
var designDoc = {
views: {
circles: {
map: function(doc) {
emit(doc['sortKey'], doc);
}
}
}
}
db.saveDesign(designDocId, designDoc, function(err, succ) {
if (succ) return
if (err && err.error == 'conflict') {
// We're updating. Get the latest rev and replace
db.getDoc(designDocId, function(err, doc) {
if (doc) {
db.saveDesign(_.extend(doc, designDoc), function(err, succ) {
if (err) console.log(err)
})
}
})
}
})