LocalStorage & # 8596; Relational database on the server

I created a simple web application that works completely autonomously - all data is stored in HTML5 localStorage. Now I want the data to be synchronized with the server so that the user can simultaneously use the application on multiple devices.

What i have done so far:

For each operation that the user performs, a log entry is added. When a user is connected to the network, all logs are transferred from localStorage to PHP via AJAX. Corresponding changes have been made to the SQL database. All logs are deleted from localStorage. In this way, all localStorage data is backed up properly on the server.

In any case, changes made from one device are not reflected on the other device and vice versa, for this we will need to get some data from SQL to localStorage.

Now, my question is: what would be the appropriate and best way to do this?

After the four steps above, I

  • Clear all local storage data and save the SQL data in localStorage.

  • Keep a log of changes made to the database and run them on local storage.

  • Any other approach.

Also, what about timestamps? What if there are conflicts?

+4
source share
2 answers

It depends on your logic when you want to synchronize data.

, , , .

( ), . . .

, .

, 1- . SQL localStorage.

, . , . , SQL localStorage.

+1

. Hood.ie ( Node.js CouchDB), .

. , , . , . , .

, , , . API ( ).

- , Hood.ie . , , , . - .

+1

Source: https://habr.com/ru/post/1533947/