1

我的 NodeJS 项目基于 SailsJS,它本身使用 ExpressJS。

它的 API 将被移动应用程序用来从中获取数据。

棘手的部分是我不希望客户端应用程序在每次数据库发生更改时都获取整个数据树。

客户端只需要下载它已经获得的数据和服务器上的数据之间的差异。

为了实现这一点,我想到了在服务器上使用 git。那就是创建一个存储库并将所有端点保存为存储库中的 json 文件。每次保存都会触发自动提交。

然后我可以创建一个特定的 API 端点,它将接受提交 sha 作为参数并返回它与 git HEAD 之间的差异。

William Benton 的这篇文章用这个想法安慰了我。

我现在正在寻找任何可以帮助我根据上面引用的语言和框架完成这项工作的技巧:

  • 我想看到这个概念的证明,但找不到
  • 我还没有找到一种简单的方法来使用 git 和 NodeJS。
  • 我不确定如何解析使用 IONIC 框架开发的客户端应用程序返回的差异,因此 AngularJS。

注意:该 api 将只可读。所有数据库移动都将由少数用户使用的自定义 Web 后端触发。

4

1 回答 1

0

I used the ideas in that post for an experimental configuration-management service. That code is in Erlang and I can't offer Node-specific suggestions, but I have some general advice.

Calling out to git itself wasn't a great option at the time from any of the languages I was interested in using. Using git as a generic versioned-object store actually works surprisingly well, but using git plumbing commands is a pain (and slow, due to all of the forking) and there were (again, at the time) limitations to all of the available native git libraries.

I wound up implementing my own persistent trie data structure and put a git-like library interface atop it. The nice thing about doing this is that your diffs can be sensitive to the data format you're storing; if you call out to git, you're stuck with finding a serialization format for your data that is amenable to standard diffs. (Without a diffable format, though, you can still send back a sequence of operations to the client to replay on whatever stale objects they have.)

于 2015-07-16T18:03:23.297 回答