Using web sql database

955 views Asked by At

I am creating a website based on rails which uses a database based on mysql. I want my website to be available offline. For that I have to store the database on client's machine. I have the option on Web storage, Web sql database, Indexed DB. I have decided to use Wed sql database which is implemented using SQLite. I want the two database to be synchronized whenever the user is online. Please let me know how to make this possible

2

There are 2 answers

0
sichinumi On

The only way I can see this happening is for your clients to install local copies of some kind of DBMS like SQLite. You can then write to the local database from your site, although this may take more finagling.

As far as synchronization, I would synchronize via last-modified time, location, or client, as per your needs. If you use time, make sure you standardize (with UTC for example) to avoid problems with local system times.

0
umbrae On

You may want to look into persistence.js for this, particularly the sync plugin. It works well for simple cases. (I'm not sure how much data you're planning on storing or how complex it is.)

As a bonus, it's abstracted out, so you can use Web SQL now and if, down the line, IndexedDB becomes the better option, it should be less painful to switch backends.

Link: http://persistencejs.org/plugin/sync