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

本文是小编为大家收集整理的关于如何将离线的HTML5网络数据库与集中式数据库进行同步的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我希望能够在HTML5(iPad)Web应用程序中执行以下操作:

  • 将数据上传到在线数据库(如果我要在SQLITE之类的东西中构建在线数据库,则大小可能<50MB)
  • )
  • 将数据或完整的数据副本提取到离线WebDatabase
  • (从3G网络覆盖范围出发)
  • 在下载的数据上执行一堆分析类型的计算
  • 将我的计算参数保存到离线WebDatabase
  • 重复,保存不同的参数集,用于在延长期间为几个不同的离线分析类型计算会话
  • (回到具有3G网络覆盖范围的区域)
  • 同步从我的离线WebDatabase到中央,在线数据库的保存参数

我对每个步骤都很满意直到最后一个...

我试图找到有关是否可以将离线网络数据库同步的信息,但找不到任何涵盖该主题的东西.是否有可能做到这一点?如果是这样,您可以向信息提供链接,或描述它如何用足够的详细信息来实施我的特定应用程序?

预先感谢

推荐答案

我尚未专门与HTML5本地数据库合作,但是我已经使用了需要离线更新并重新同步到中央数据存储的移动设备.

是在服务器上还是在离线客户端上创建数据集,我确保其主要密钥是UUID.我还确保每次更新记录时都会记录记录.

我也不是最后一次离线客户同步.

因此,当重新同步到中央数据库时,我首先向离线客户端查询自上次同步以来已更改的记录.然后,我查询中央数据库以确定自上次同步以来的任何记录是否已更改.

如果它们在中央数据库上没有更改,请使用离线客户端的数据更新它们.如果服务器上的记录自上次同步以来已更改,则将其更新为客户端.

如果中央服务器上不存在UUID,而是在离线客户端上进行的,则我插入它,反之亦然.

要清除记录,我创建了一个"清除"列,当运行SYSNC查询时,我会从每个数据库中删除记录(或根据应用程序要求将其标记为无活动).

如果两个记录自上次更新以来都发生了变化,我必须依靠用户输入来调和,或者指定记录"赢"的规则.

我通常不信任内置数据库导入函数,除非我要导入完全空的数据库.

其他推荐答案

步骤:

  1. 在本地数据库上保留更改列表.
  2. 连接到远程数据库时,请检查自上次同步以来的任何更改.
  3. 如果偏远方面的更改与本地更改发生冲突,请告知用户做什么.
  4. 对于所有其他更改,请继续同步:
    1. 下载所有在本地没有更改的在线更改.
    2. 上传所有没有远程更改的本地更改.

此方法实际上可以在数据库的任何组合上使用,只要一侧有数据转换器.

其他推荐答案

在我看来,从我访问过的一些网站上看(只要您为服务器db使用sqlite),就应该有可能.

HTML5 WebDatabases也使用SQLITE(尽管并非所有浏览器都支持它,并且W3C似乎已经放弃了对其的支持)

所以...

如果您使用.dump命令导出数据,然后使用$ sqlite mydb.db

然后,当您要将"离线"数据同步到服务器时,只需从WebDatabase进行相反的转储到dump.sql文件并导入服务器数据库

本网站解释从SQLite转储导出并导入

来源:倾倒和还原sqlite db

本文地址:https://www.itbaoku.cn/post/597594.html

问题描述

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

  • 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...

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?

Thanks in advance

推荐答案

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.

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.

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

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.

其他推荐答案

Steps:

  1. Keep a list of changes on the local database.
  2. When connected to remote database, check for any changes since last sync on remote.
  3. If changes on remote side has conflicts with local changes, inform the user on what to do.
  4. For all other changes, proceed with sync:
    1. download all online changes which did not change locally.
    2. upload all local changes which did not change remotely.

This method can actually work on any combination of databases, provided there is a data convertor on one side.

其他推荐答案

It looks to me, from a few sites I visited, that (as long as you are using SQLite for your Server db) it should be possible.

HTML5 webdatabases also use SQLite (although not all browsers support it and W3C seems to have dropped support for it)

so...

If you export the data using the .dump command and then import the data into the webdatabase using the $sqlite mydb.db < mydump.sql syntax you should be able to do this with some fidgeting with a php or java backend?

Then when you want to sync the "offline" data to your server just do the opposite dump from the webdatabase to a dump.sql file and import to the server database

This site explains exporting to and importing from SQLite dumps

SOURCE: dumping and restoring an SQLite DB