使用PouchDB / CouchDB模式设计的Cordova Web应用程序 [英] Cordova Web App using PouchDB / CouchDB Schema Design

查看:92
本文介绍了使用PouchDB / CouchDB模式设计的Cordova Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将PouchDB与CouchDB一起使用,因为我的Web应用程序具有出色的同步和复制功能,但是很难找到为我的数据建模的最佳方法。



该应用程序允许用户在日历中创建活动,该活动只能与他们选择的用户共享。与该事件关联的用户可以添加评论并对该事件进行更改。



1)到目前为止,我所了解的每个用户都应该拥有自己的数据库来如果所有用户数据都存储在一个数据库中,则避免访问其他用户数据。在这种情况下,如何从不同的数据库更新或共享文档数据?



2)是否应在使用SQL数据库的另一台服务器上管理用户登录? API?



任何指导将不胜感激!



Danio

解决方案

如果我正确理解您的应用,则您的文档看起来像这样:

  {
_id: event- {timestamp / name / something},
organizer: alice,
与会者:[
alice, bob, charlie
]
}

如果大致正确,那么我建议采用以下架构,使其与



所有这些-* 数据库都被连续(理想地)复制到云托管(最可能)的CouchDB(或兼容)数据库中。 Bob和Charlie将他们的应用程序连接到同一个云托管的CouchDB(或兼容)数据库,并将Alice的事件复制到他们的 alice-shared 数据库中。



然后该应用程序将这些事件提供给Bob和Charlie,让他们进行编辑,将这些更改复制回 alice-shared 数据库,然后(最终;由于网络)备份到云,再回到Alice。



在所有这些中,云位是可选的。 ;)根据部署情况,这些设备可能是同一网络上的三台设备以某种方式彼此找到对方并进行复制并复制。



根据我对您应用的了解, 应该起作用。 :)您提到过,还有其他评论文档,它们需要以类似的方式建模-否则应用程序将利用其与事件文档的关系来对相关评论进行正确处理。



我很想知道这听起来像是一条可行的道路,因为我自己正在为一些项目进行探索。



希望其中有所帮助。 :)


I'd like to use PouchDB with CouchDB because of the great syncing and replication features for my web app but have a difficult time finding the best way to model my data for what I need to do.

The app lets a user create events in a calendar which can be shared only with users they choose. The users that are associated to that event can add comments and make changes to that event.

1) So far from what I understand, each user should have their own database to avoid accessing other user data if all stored in one db. If this is the case, how would one update or share a documents data from different databases?

2) Should the user login be managed on another server using an sql database with an API?

Any guidance would be greatly appreciated!

Danio

解决方案

If I understand your app correctly, you have docs that look something like this:

{
  "_id": "event-{timestamp/name/something}",
  "organizer": "alice",
  "attendees": [
    "alice", "bob", "charlie"
  ]
}

If that's roughly right, then I'd propose the following architecture to make it work with PouchDB & CouchDB's replication.

The goal here is to "cut with the grain" of CouchDB's replication protocol, compartmentalize permissions into containers (database-per-user and database-per-share/relationship), and provide a latent-friendly sharing/distribution model...because the cloud goes away sometimes. ;)

In the flowchart below, you can see Alice's "device" (or app, etc) on the left. Alice keeps events in a private-user-space database. Any event document (like the one above) with attendees on it, gets copied (possibly via a background, filtered replication process) to share databases based on the user identifiers used in the attendees key (or however you model your stuff).

Each of those share-with-* database is continuously (ideally) replicated to a cloud-hosted (most likely) CouchDB (or compatible) database. Bob and Charlie have their apps connected to the same cloud-hosted CouchDB (or compatible) database, and get Alice's event replicated into their share-with-alice database.

The app then provides those events to Bob and Charlie, let's them make their edits, replicates those changes back to the share-with-alice database, and then (eventually; because network) back up to the cloud and back to Alice.

In all of this, the cloud bit is optional. ;) Depending on the deployment these could be three devices on the same network finding each other someway or other and replicating as available.

From what I understand of your app, this should work. :) You mentioned that there are other comment documents also, and they'd need to be modeled in a similar way--or the app would leverage their relationship with the event document to do the Right Thing with the related comments.

I'd be very curious to know if this sounds like a possible path as I'm exploring it myself for a few projects.

Hope something in there's helpful regardless. :)

这篇关于使用PouchDB / CouchDB模式设计的Cordova Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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