使用Web SQL数据库
我正在创建一个基于rails 的网站,它使用基于mysql 的数据库。我希望我的网站可以离线使用。为此,我必须将数据库存储在客户端的计算机上。我可以选择 Web 存储、Web sql 数据库、索引数据库。我决定使用 Wed sql 数据库,它是使用 SQLite 实现的。我希望只要用户在线就可以同步两个数据库。请让我知道如何实现这一点
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要研究 persistence.js,特别是同步插件。它适用于简单的情况。 (我不确定您计划存储多少数据或它有多复杂。)
作为奖励,它被抽象出来,因此您现在可以使用 Web SQL,如果将来 IndexedDB 成为更好的选择,切换后端应该不会那么痛苦。
链接:http://persistencejs.org/plugin/sync
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
我能看到这种情况发生的唯一方法是让您的客户安装某种 DBMS(如 SQLite)的本地副本。然后,您可以从您的站点写入本地数据库,尽管这可能需要更多的技巧。
至于同步,我会根据您的需要通过上次修改的时间、位置或客户端进行同步。如果您使用时间,请确保标准化(例如使用 UTC)以避免本地系统时间出现问题。
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.