什么是通过http和json同步2个sqlite表的最好的方法? [英] What is the best way to sync 2 sqlite tables over http and json?

查看:125
本文介绍了什么是通过http和json同步2个sqlite表的最好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当简单的同步问题。我有一个表,大约10列,我想保持同步在一个sqlite文件在3个不同的客户端:Iphone客户端,浏览器客户端和一个Ruby on Rails客户端。所以我需要一个简单的sycing解决方案,将工作所有3,即,我可以很容易地实现它在Javascript,Objective C和Ruby和它的工作与JSON通过HTTP。我看过其他同步解决方案的各种组件,如git中的一些,一些来自谷歌齿轮社区的教程,以及一个rails插件,名为acts_as_replica。我天真的方法是简单地在数据库中创建最后一个同步的时间戳,然后在创建所有删除的更改日志。 (我不允许更新表中的条目)。然后,我可以检索自上次时间戳以来的所有新条目,然后与删除组合,并在3个解决方案之间通过http发送一个changelog作为json。

I have a fairly simple sync problem. I have a table with about 10 columns that I want to keep in sync between a sqlite file on 3 different clients: an Iphone client, a browser client, and a Ruby on Rails client. So I need a simple sycing solution that will work for all 3, i.e. I can easily implement it in Javascript, Objective C, and Ruby and it works with JSON over HTTP. I have looked at various components of other syncing solutions like the one in git, some of the tutorials that have come out of the Google gears community, and a rails plugin called acts_as_replica. My naive approach would be to simply create a last synced timestamp in the database and then create a changelog of all deletes as they are made. (I don't allow updates to entries in the table). I can then retrieve all the new entries since the last timestamp, combine then with the deletes, and send a changelog as json over http between the 3 solutions.

我应该考虑使用SHA1哈希或每个条目的UUID还是最后一个同步的时间戳足够吗?如何确保没有重复的条目?有没有更简单的算法我可以跟着?

Should I consider the use of SHA1 hash or a UUID of each entry or is a last synced timestamp sufficient? How do I make sure there are no duplicate entries? Is there a simpler algorithm I could follow?

推荐答案

我假设改变可能在结束。我不知道插入和更新的性质,但这是我的想法;

I am assuming changes are likely to be at the end. I don't know the character of insert and updates but here is my idea;


  • 我会SHA1(或MD5,事件在这种情况下)当前月份和月份的天数。与这些指纹比较是一种快速的方式来看待差异是什么。

  • 如果以前的月份有差异,


    • 如果一个月的量过大,我们可以拆分月份,只需生成每日指纹,而不是整个月的比较。

    • 否则,我们可以按照处理每日变更的方式处理每月更改。

    时间类别(日,月)可以根据数据量进行调整。

    The time categories (day, month) can be adjusted according to the data volume.

    当然这是一个朴素而简单的算法。如果我正在处理敏感/关键数据,我会查找事务算法。

    Of course this is a naive and simple algorithm. If I was processing sensitive/critical data I would look for a transactional algorithm.

    这篇关于什么是通过http和json同步2个sqlite表的最好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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