3. COUCHDB
1st NoSQL document database created in 2005
Prefer "availability" and near real-time "consistency"
Stores unstructured "documents" using JSON
Runs on the server with RESTful API's
Designed for synchronization/replication
5. POUCHDB?
JavaScript implementation of CouchDB for the
browser/nodejs
Mimics CouchDB API for consistency between client
and remote servers
JS abstraction layer over WebSQL, IndexedDB and
LevelDB etc
Build o ine apps that sync when back online
9. BIDIRECTIONAL REPLICATION
Sync data from src to target AND target to src:
localDB.replicate.to(remoteDB);
localDB.replicate.from(remoteDB);
is the same as using...
localDB.sync(remoteDB, [options]);
10. LIVE REPLICATION
Changes propagated as they occur with liveparameter
myApp.db.sync(myApp.remoteDB, {
live: true
retry: true
}).on('change', function (change) {
console.log("A db change occurred " + change);
}).on('paused', function (info) {
console.log("Replication paused " + info);
}).on('active', function (info) {
console.log("Replication resumed " + info);
}).on('error', function (err) {
console.log("Sync Error occurred " + err);
})
11. FILTERED REPLICATION
Replicate partial datasets
Use case - return certain documents based on a users
identity or role
localDb.replicate.from(remoteDB, {
filter: function (doc) {
return doc.category === role;
}
}
18. POUCHDB + SQLITE
Avoid storage limits of other solutions
Use WKWebView (WebSQL not available and
IndexedDB slow/buggy)
Allows you to bundle prepopulated database les
(avoid db init overhead)
20. POUCHDB CORDOVA SQLITE ADAPTER
Provides native SQLite support w/ WebSQL like API
Use in addition to one of 3 Cordova Plugins - (
, or
)
Requires pouchdb.js (6.0.0+)
pouchdb-adapter-cordova-sqlite
Cordova-
sqlite-storage cordova-plugin-sqlite-2 cordova-
plugin-websql
myApp.localDB = new PouchDB('tasks.db', {adapter: 'cordova-sqlite'});
24. USEFUL RESOURCES
PouchDB PhoneGap/Cordova Getting Started
PouchDB Ionic Getting Started
Cloudant DBaaS
Couchbase
PouchDB Server
Set up CouchDB Server
PouchDB Inspector
PouchDB Find
PouchDB Plugins
Database Comparison Tool