Mary
Mary

Reputation: 572

How to access database in an HTML5/JS app online and offline with one code base?

I'm working on an HTML/JavaScript GUI application that will run on mobile devices (using Cordova) and also as a hosted web page that's accessible from a desktop web browser. I want to give the option to read and store data in a local offline database (SQL database most likely), as well as the option to connect to a web server and read/update data from the server as well.

If anyone has done something similar without having to write the data access routines twice (once for the server side, and once for the client offline storage side), I'd like to get some suggestions.

One solution I am thinking about (which has some unresolved issues still): I could write the server in any platform (PHP, Java, Js, etc.), but don't want to replicate the data access code for the offline version, so am thinking to do the data access portion in JavaScript--maybe write a node.js server, and use sqlite for local/offline databases (which Cordova supports). I can't figure out how to provide similar local data functionality on a web browser.

The simplest option would be to run a server on the local machine, but I don't think that is easy in Cordova or on a desktop browser.

Upvotes: 1

Views: 1310

Answers (1)

Jeff Sloyer
Jeff Sloyer

Reputation: 4964

Check out PouchDB. PouchDB is compatible with CouchDB and is 100% Javascript. You can do some cool offline syncing to online syncing with CouchDB.

Check out https://cloudant.com/blog/pouchdb/ and http://pouchdb.com/faq.html.

Upvotes: 4

Related Questions