如何将离线HTML5网络数据库与集中式数据库同步 [英] How to sync offline HTML5 webdatabase with centralised database

查看:204
本文介绍了如何将离线HTML5网络数据库与集中式数据库同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在HTML5(iPad)网络应用程序中执行以下操作:

I'd like to be able to do the following in a HTML5 (iPad) web app:


  • 将数据上传到在线

  • 将数据的子集或完整副本提取到离线Web数据库
  • / li>
  • (离开3G网络覆盖范围)

  • 对下载的数据执行一系列分析类型计算

  • 将我的计算参数保存到离线网页数据库

  • 重复,在一段时间内为不同的离线分析类型计算会话保存不同的参数集

  • (返回到具有3G网络覆盖的区域)

  • 将保存的参数从我的离线网络数据库同步到中央在线数据库

  • upload data to an online database (which would be probably <50Mb in size if I was to build the online database in something like SQLite)
  • extract either a subset or a full copy of data to an offline webdatabase
  • (travel out of 3G network coverage range)
  • perform a bunch of analytic-type calculations on the downloaded data
  • save parameters for my calculations to the offline webdatabase
  • repeat, saving different parameter sets for several different offline analytic-type calculation sessions over an extended period
  • (head back into areas with 3G network coverage)
  • sync the saved parameters from my offline webdatabase to the central, online database

我对每一步都感到舒服,直到最后一个...

I'm comfortable with every step up till the last one...

我试图找到有关是否可以将离线Web数据库与中央数据库同步,但无法找到涵盖该主题的任何内容。有可能做到这一点吗?如果是,您能否提供链接信息,或描述它将如何工作足够的细节来实现我的具体应用程序?

I'm trying to find information on whether it's possible to sync an offline webdatabase with a central database, but can't find anything covering the topic. Is it possible to do this? If so, could you please supply link/s to information on it, OR describe how it would work in enough detail to implement it for my specific app?

提前感谢

推荐答案

我没有专门使用HTML5本地数据库,但我已经使用移动设备,需要离线更新和重新同步中央数据存储。

I haven't worked specifically with HTML5 local databases, but I have worked with mobile devices that require offline updates and resyncing to a central data store.

无论数据集是在服务器上创建还是在脱机客户端上创建,我确保其主键是UUID。我也确保时间戳记录每次更新。

Whether the dataset is created on the server or on the offline client, I make sure its primary key is a UUID. I also make sure to timestamp the record each time its updated.

我也不是最后一次离线客户端同步的时间。

I also make not of when the last time the offline client was synced.

中央数据库,我首先查询离线客户端自上次同步以来更改的记录。然后我查询中央数据库以确定这些记录中的任何记录自上次同步以来是否已更改。

So, when resyncing to the central database, I first query the offline client for records that have changed since the last sync. I then query the central database to determine if any of those records have changed since the last sync.

如果中央数据库上没有更改,我将使用脱机客户端的数据更新它们。如果服务器上的记录自上次同步后更改,我将其更新到客户端。

If they haven't changed on the central database, I update them with the data from the offline client. If the records on the server have changed since last sync, I update them to the client.

如果UUID在中央服务器上不存在,但在脱机客户端上,则插入它,反之亦然。

If the UUID does not exist on the central server but does on the offline client, I insert it, and vice versa.

为了清除记录,我创建了一个purge列,当运行sysnc查询时,我从每个数据库中删除记录应用要求)。

To purge records, I create a "purge" column, and when the sysnc query is run, I delete the record from each database (or mark it as inactive, depending on application requirements).

如果两个记录自上次更新以来已更改,我必须依靠用户输入来调和或指定哪个记录胜利的规则。

If both records have changed since last update, I have to either rely on user input to reconcile or a rule that specifies which record "wins".

我通常不信任内置的数据库导入函数,除非我导入到一个完全空的数据库。

I usually don't trust built-in database import functions, unless I'm importing into a completely empty database.

这篇关于如何将离线HTML5网络数据库与集中式数据库同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆