Last active
January 4, 2016 20:09
-
-
Save daleharvey/8672189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function incrementalView() { | |
db.changes({ | |
since: x, | |
onChange: function(doc) { | |
// we cant do this, but lets just pretend the map returned | |
// an array of emitted [{key: akey, val: anobj}]; | |
var viewData = designDoc.map(doc); | |
// Delete all the old stuff relating to this document | |
// PROBLEM: this is missing, couchdb without a view engine | |
// only has a single index, we can index by the doc._id, or the | |
// view key but not both | |
// We need an index on the key as that is what is queried | |
// We need an index on doc._id so that when we get updates / deletions | |
// we know to delete the stale view data | |
// We cant implement our view engine with views, thats crazy | |
viewDb.getAll(doc._id, function(docs) { | |
docs.forEach(delete); | |
}); | |
// store the new viewObjects | |
viewData.each(function(viewDoc) { | |
var newKey = [viewDoc.key, doc._id]; | |
viewDb.put(newKey, viewDoc.val); | |
}); | |
} | |
}); | |
} | |
// With the above, queries are simple allDocs queries with a little processing on the way out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment