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/Cordova­SQLitePlugin
# Cordova app
var 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 app
var replicator = require('./backend/replication');                    
replicator.runReplication …
# Node.js Backend (replication.js)
var db = new Pouch('~/.cozy­desktop/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 cozy­light ­g
$ cozy­light install cozy­labs/cozy­light­pouchdb­api
$ cozy­light install cozy­labs/cozy­light­html5­apps
$ cozy­light install mygithub/mypouchapp1
$ cozy­light install mygithub/mypouchapp2
$ cozy­light start
Cozy 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
Synchronisation de périphériques avec Javascript et PouchDB

Synchronisation de périphériques avec Javascript et PouchDB