Upload
gelnior
View
222
Download
2
Embed Size (px)
Citation preview
Vos appareils méritent plus que vos fichiers
v
Setup
$ npm install pouchdb save
var pouchdb = require('pouchdb');
<script src="pouchdb.min.js"></script>
Synchronization
var db = new PouchDB('todos');var remoteCouch = 'https://mycouch/todos';var opts = {live: true};
db.sync(remoteCouch, opts) .on('change', onChange) .on('uptodate', onUpdate) .on('error', onError);
Conflicts
var opts = {conflicts: true};db.get('docid', opts, function (err, doc) { var rev = doc._rev; var conflictRev = doc._conflicts[0]; rev = selectRevision(rev, conflictRev);
opts = {rev: rev}; db.get('docid', opts, function (err, doc) { db.put(doc); });};
Messaging (pub/sub)
function onChange (change) {
if(change.doc.type === 'message' && change.doc.chan === 'mychan') { console.log(doc.content);
db.put({ type: 'message', chan: 'mychan' content: 'Got it! Now I publish' }); }
cozy-labs/cozy-mobile
Cozy Mobile
# Add WebSQL plugin$ cordova plugin add https://github.com/brodysoft/CordovaSQLitePlugin
# Cordova appvar db = new PouchDB('cozy', {adapter: 'websql'});
db.replicate.from({https://mycozy/cozy, { batch_size: 5, batches_limit: 1, filter: function (doc) { return doc.docType === 'Folder' || doc.docType === 'File'; }, live: true since: checkpoint});
cozy-labs/cozy-desktop
Cozy Desktop
# NodeWebkit appvar replicator = require('./backend/replication'); replicator.runReplication …
# Node.js Backend (replication.js)var db = new Pouch('~/.cozydesktop/db');
db.replicate.from({ https://mycozy/cozy, filter: function (doc) { return doc.docType === 'Folder' || doc.docType === 'File'; }, since: checkpoint})db.replicate.to(…) ;
cozy-labs/cozy-light
Cozy Light
$ npm install cozylight g
$ cozylight install cozylabs/cozylightpouchdbapi$ cozylight install cozylabs/cozylighthtml5apps
$ cozylight install mygithub/mypouchapp1$ cozylight install mygithub/mypouchapp2
$ cozylight startCozy Light is listening on port 19104…
# In your app… PouchDB.replicate('http://' + window.location.host + '/db/cozy', 'db')
pouchdb/pouchdb
pouchdb/pouchdb-server
colinskow/pouch-mirror
natevw/PeerPouch
nolanlawson/pouchdb-quick-search
pouchdb.com