Skip to content

Instantly share code, notes, and snippets.

@mauroporras
Last active February 23, 2020 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauroporras/d4f96aa6f8a9ea4c2de3fc6f79250cee to your computer and use it in GitHub Desktop.
Save mauroporras/d4f96aa6f8a9ea4c2de3fc6f79250cee to your computer and use it in GitHub Desktop.
const PouchDB = require('pouchdb')
const db = new PouchDB('zeainc')
const remote = 'http://admin:password@localhost:5984/zeainc/projets'
db.changes({
since: 'now',
live: true,
}).on('change', listProjects)
function addProject(project) {
const theProject = {
...project,
type: 'project',
}
db.post(theProject, function callback(err, result) {
if (!err) {
console.log('Project created')
}
})
}
function listProjects() {
console.log('Projects:')
db.allDocs({ include_docs: true, descending: true }, function(err, doc) {
console.log(doc.rows)
})
}
function sync() {
const opts = { live: true }
db.replicate.to(remote, opts)
db.replicate.from(remote, opts)
}
if (remote) {
sync()
}
addProject({ type: 'project', name: 'The new one' })
listProjects()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment