简体   繁体   English

离线优先的Webapp本地存储同步到MySQL

[英]Offline-first webapp local storage sync to MySQL

I'm developing an offline-first webapp (HTML5 & JS) for data collecting which should sync to a MySQL server when online. 我正在开发一个脱机优先的webapp(HTML5和JS)以收集数据,在线时应同步到MySQL服务器。 I also need to get a subset from the MySQL DB to search in offline (selecting categories/attributes for the data collecting). 我还需要从MySQL数据库中获取一个子集,以进行离线搜索(选择用于数据收集的类别/属性)。

To summarize things: 总结一下:

  1. Get categories from MySQL and store in queryable client-side db 从MySQL获取类别并将其存储在可查询的客户端数据库中
  2. Collect data and store in client-side db 收集数据并存储在客户端数据库中
  3. When online sync data to MySQL (via a PHP script preferrably) 在线将数据同步到MySQL时(最好通过PHP脚本)

I've looked into PouchDB but I don't think it is the right solution because the server side applications all depend on MySQL and it's not an option to rewrite all. 我已经研究了PouchDB,但我认为这不是正确的解决方案,因为服务器端应用程序都依赖于MySQL,并且不是全部重写的选择。

What solution would you suggest? 您会提出什么解决方案?

Let's say you are having JS blogging app with Redux (for example) on top. 假设您的JS博客应用程序的顶部是Redux(例如)。

Your Data Layer (Redux) persists data into LocalStorage and vice-versa, when app is loaded it checks LocalStorage and if there are data - data loaded into Redux. 您的数据层(Redux)将数据持久保存到LocalStorage中,反之亦然,加载应用程序时,它会检查LocalStorage以及是否有数据-数据已加载到Redux中。

Your Redux contains Posts and NewPosts . 您的Redux包含PostsNewPosts

When app is online, you send requests to the server, server responds with some data, you store this data into the Posts . 当应用在线时,您向服务器发送请求,服务器响应一些数据,然后将这些数据存储到Posts中

When app is offline you don't send any requests, you just store new posts into the NewPosts . 当应用离线时,您不发送任何请求,只需将新帖子存储到NewPosts中

When your app is back online - you send every item from NewPosts to the server, and if they are successfully stored - remove them from NewPosts and update Posts with new stuff. 当应用程式重新联机-你从NewPosts发送到服务器的每个项目,如果他们成功地存储-从NewPosts和更新的帖子有新的东西删除它们。

In the application you are rendering NewPosts first (probably with not synced icon or something) then Posts after. 在应用中,你首先渲染NewPosts(可能与不同步图标或东西),然后之后

Hopefully I understood your question correctly. 希望我能正确理解您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM