Skip to content

Commit

Permalink
- added ability to store already encoded entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickolay Platonov committed Sep 7, 2010
1 parent 93a5997 commit 0e4cb9f
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/KiokuJS/Backend/CouchDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,35 @@ Class('KiokuJS.Backend.CouchDB', {
},


insert : function (nodesToInsert, scope, mode) {
insert : function (nodesToInsert, scope, mode, insertEntries) {

var me = this
var CONT = this.CONT

Joose.A.each(this.serializeNodes(nodesToInsert), function (entry, index) {

CONT.AND(function () {
var node = nodesToInsert[ index ]
if (insertEntries)
Joose.A.each(nodesToInsert, function (entry, index) {

me.insertDocument(node.ID, node.REV, entry, mode).andThen(function (id, rev) {
node.REV = rev
CONT.AND(function () {

this.CONTINUE(id, rev)
me.insertDocument(entry._id, entry._rev, me.serializer.serialize(entry), mode).andThen(function (id, rev) {

this.CONTINUE(id, rev)
})
})
})
else
Joose.A.each(this.serializeNodes(nodesToInsert), function (entry, index) {

CONT.AND(function () {
var node = nodesToInsert[ index ]

me.insertDocument(node.ID, node.REV, entry, mode).andThen(function (id, rev) {
node.REV = rev

this.CONTINUE(id, rev)
})
})
})
})

CONT.andThen(function () {

Expand Down Expand Up @@ -295,7 +307,7 @@ Class('KiokuJS.Backend.CouchDB', {
// id
if (typeof nodeOrId == 'string') {

this.getDocument(id, null, true).andThen(function (entry, id, rev) {
this.getDocument(nodeOrId, null, true).andThen(function (entry, id, rev) {

this.deleteDocument(id, rev).now()
})
Expand All @@ -306,7 +318,7 @@ Class('KiokuJS.Backend.CouchDB', {
})

CONT.andThen(function () {

Joose.A.each(arguments, function (res) {
if (res[0] instanceof KiokuJS.Exception) throw res[0]
})
Expand Down Expand Up @@ -398,4 +410,3 @@ Class('KiokuJS.Backend.CouchDB', {
}

})

0 comments on commit 0e4cb9f

Please sign in to comment.