Last active
February 23, 2020 16:29
-
-
Save mauroporras/d4f96aa6f8a9ea4c2de3fc6f79250cee 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
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