Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
EASY DATA FOR PHONEGAP
APPS
HOLLY SCHINSKY
PHONEGAP TEAM AT ADOBE
SOCIAL INFO
@devgirl
devgirl.org
https://github.com/hollyschinsky
COUCHDB
1st NoSQL document database created in 2005
Prefer "availability" and near real-time "consistency"
Stores unstruct...
COUCHDB CONT...
CAP theorem ~ Partitioned, every node is
Available, and it's only eventually
Consistent.
POUCHDB?
JavaScript implementation of CouchDB for the
browser/nodejs
Mimics CouchDB API for consistency between client
and...
SAMPLE "DOCUMENT"
{
"_id": "mittens",
"name": "Mittens",
"occupation": "kitten",
"age": 3,
"hobbies": [
"playing with ball...
DATA SYNCHRONIZATION
Credit: http://www.ibm.com/developerworks/library/wa-couchdb/
Multiple options to replicate data betw...
UNIDIRECTIONAL REPLICATION
Sync data from source to target or target to source...
localDB.replicate.to(remoteDB);
OR...
lo...
BIDIRECTIONAL REPLICATION
Sync data from src to target AND target to src:
localDB.replicate.to(remoteDB);
localDB.replicat...
LIVE REPLICATION
Changes propagated as they occur with liveparameter
myApp.db.sync(myApp.remoteDB, {
live: true
retry: tru...
FILTERED REPLICATION
Replicate partial datasets
Use case - return certain documents based on a users
identity or role
loca...
DESIGN FOR OFFLINE FIRST
Better user experience (o ine and online)
Allow users to continue to work o ine
Avoid discontinue...
WHEN OFFLINE?
Rural Areas
3rd World Countries
Limited, Sporadic or No Access (airplanes)
OFFLINE APP USE CASES
Inspection Apps
Content Publishing (books, music, videos)
Health Care
Social Media
Location/Mapping ...
BROWSER STORAGE OPTIONS
HTML5 Storage - local storage
IndexedDB - new standard
WebSQL - deprecated
DATABASE BROWSER SUPPORT
Current defaults (can use adapters to change)
POUCHDB ADAPTERS
POUCHDB + SQLITE
Avoid storage limits of other solutions
Use WKWebView (WebSQL not available and
IndexedDB slow/buggy)
All...
Credit: http://www.html5rocks.com/en/tutorials/o ine/quota-research/#toc-mobile
MOBILE DATA STORAGE LIMITS
POUCHDB CORDOVA SQLITE ADAPTER
Provides native SQLite support w/ WebSQL like API
Use in addition to one of 3 Cordova Plugi...
POUCHDB SERVER
https://github.com/pouchdb/pouchdb-serve
A simple server to mimic a CouchDB implementation
to get started q...
LOCAL/REMOTE DATABASE SETUP
// Create the local database
if (ons.platform.isIOS() || ons.platform.isAndroid())
myApp.local...
SAMPLE APP
Source Project:
https://github.com/hollyschinsky/PouchDB-Sample
USEFUL RESOURCES
PouchDB PhoneGap/Cordova Getting Started
PouchDB Ionic Getting Started
Cloudant DBaaS
Couchbase
PouchDB S...
Upcoming SlideShare
Loading in …5
×

Easy Data for PhoneGap apps with PouchDB

549 views

Published on

Why you may want to use PouchDB for handling your data storage and synchronization needs in your mobile apps.

Published in: Mobile
  • Be the first to comment

  • Be the first to like this

Easy Data for PhoneGap apps with PouchDB

  1. 1. EASY DATA FOR PHONEGAP APPS HOLLY SCHINSKY PHONEGAP TEAM AT ADOBE
  2. 2. SOCIAL INFO @devgirl devgirl.org https://github.com/hollyschinsky
  3. 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
  4. 4. COUCHDB CONT... CAP theorem ~ Partitioned, every node is Available, and it's only eventually Consistent.
  5. 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
  6. 6. SAMPLE "DOCUMENT" { "_id": "mittens", "name": "Mittens", "occupation": "kitten", "age": 3, "hobbies": [ "playing with balls of yarn", "chasing laser pointers", "lookin' hella cute" ] }
  7. 7. DATA SYNCHRONIZATION Credit: http://www.ibm.com/developerworks/library/wa-couchdb/ Multiple options to replicate data between source and target.
  8. 8. UNIDIRECTIONAL REPLICATION Sync data from source to target or target to source... localDB.replicate.to(remoteDB); OR... localDB.replicate.from(remoteDB);
  9. 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. 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. 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; } }
  12. 12. DESIGN FOR OFFLINE FIRST Better user experience (o ine and online) Allow users to continue to work o ine Avoid discontinued use of your apps
  13. 13. WHEN OFFLINE? Rural Areas 3rd World Countries Limited, Sporadic or No Access (airplanes)
  14. 14. OFFLINE APP USE CASES Inspection Apps Content Publishing (books, music, videos) Health Care Social Media Location/Mapping Apps Retail Games
  15. 15. BROWSER STORAGE OPTIONS HTML5 Storage - local storage IndexedDB - new standard WebSQL - deprecated
  16. 16. DATABASE BROWSER SUPPORT Current defaults (can use adapters to change)
  17. 17. POUCHDB ADAPTERS
  18. 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)
  19. 19. Credit: http://www.html5rocks.com/en/tutorials/o ine/quota-research/#toc-mobile MOBILE DATA STORAGE LIMITS
  20. 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'});
  21. 21. POUCHDB SERVER https://github.com/pouchdb/pouchdb-serve A simple server to mimic a CouchDB implementation to get started quickly Includes Web UI admin tool $ pouchdb-server -p 15984
  22. 22. LOCAL/REMOTE DATABASE SETUP // Create the local database if (ons.platform.isIOS() || ons.platform.isAndroid()) myApp.localDB = new PouchDB('tasks.db', {adapter: 'cordova-sqlite'}); else myApp.localDB = new PouchDB('tasks.db'); // Create the remote database myApp.remoteDB = new PouchDB("http://localhost:15984/tasks"); // Start Syncing myApp.localDB.sync(myApp.remoteDB, {live: true, retry: true});
  23. 23. SAMPLE APP Source Project: https://github.com/hollyschinsky/PouchDB-Sample
  24. 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

×