Created
June 5, 2014 16:13
-
-
Save nolanlawson/a40efe5aa730383733bb 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
<html> | |
<body> | |
<script src="//cdn.jsdelivr.net/pouchdb/2.2.3/pouchdb.js"></script> | |
<script src="index.js"></script> | |
</body> | |
</html> |
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
var db = new PouchDB('pixelpark_dev',{ | |
auto_compaction: true, | |
cache: false | |
}); | |
var remoteCouch = 'http://couchdb.simple-url.com:5984/pixelpark_dev'; | |
db.replicate.from(remoteCouch, { | |
live: true | |
}); | |
var info = function () { | |
db.info(function (err, info) { | |
console.log('DATABASE INFO', info); | |
}); | |
} | |
info(); | |
// Create design doc for indexed query | |
var postsOnly = { | |
_id: '_design/posts_only', | |
views: { | |
'posts_only': { | |
map: function (doc) { | |
if (doc.type === 'POST' || doc.type === 'IMAGE') { | |
emit([doc.created, doc._id, doc.user.id], doc.created); | |
} | |
}.toString() | |
} | |
} | |
}; | |
db.put(postsOnly).then(function () { | |
return db.query('posts_only', { | |
stale: 'update_after' | |
}); | |
}); | |
// Query the database for posts | |
db.query('posts_only').then(function (res) { | |
console.log('QUERY', res); | |
}); | |
// Fetch all latest changes | |
var changes = db.changes({ | |
live: true, | |
since: 'latest', | |
complete: function (err, changes) { | |
console.log(err, changes); | |
info(); | |
}, | |
onChange: function (change) { | |
console.log('Change', change); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment