使用CouchDB / PouchDB时应用程序的体系结构 [英] Architecture of an app when using CouchDB/PouchDB

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

问题描述

我想知道当使用 PouchDB 作为移动应用中的本地存储而不是 localStorage

I am wondering how the architecture should look like when using PouchDB as a local storage in a mobile app instead of localStorage.

此时,我习惯于将应用程序的数据缓存到 localStorage API调用到后端以请求或发布数据。后端持有所有逻辑。例如:

At this moment I am used to cache my app's data into localStorage and when needed I perform an API call to the backend to request or post data. The backend is holding all logic. Such as:


  • 此用户是否具有正确的权限/角色来执行此操作?

  • 检查操作是否可以完成的任何其他逻辑

然后将所有数据存储到关系数据库中。我现在已经阅读有关NoSQL数据库,特别是 CouchDB PouchDB 。所以我想知道这个架构怎么样?此时有三个问题出现在我身上:

All data is then stored into a relational database. I have now been reading about NoSQL databases and in particular CouchDB and PouchDB. So I am wondering how would this architecture look like? Three questions arise at this point for me:


  1. 如果我有多个用户拥有自己的身份验证,我如何确保用户获得只访问他们的数据?我还在服务器端有1个数据库吗?

  2. 客户端上的PouchDB 可以与远程< $ c> PouchDB 。但是当使用Javascript构建应用程序时,如何确保人们不会通过hacking客户端Javascript将数据插入到 PouchDB 中?

  3. 后端的使用在这些类型的设置中会不会出现?如果您想拥有第三方的API,您只需要在其周围放置一个 Sails.js 后端 CouchDB

  1. If I have multiple users with there own authentication, how can I make sure that the users get access to only their data? And will I still have 1 database on server end?
  2. PouchDB on the client side can be in sync with a remote PouchDB. But when an application is build with Javascript how do you make sure that people are not inserting data into PouchDB by 'hacking' the client-side Javascript?
  3. Would the use of a backend be gone in these kinds of setups? And if you want to have an API for 3rd party, you just put for example an Sails.js backend around the CouchDB?


推荐答案

PouchDB维护者在这里,高兴地回答你的问题。 :)

PouchDB maintainer here, happy to answer your questions. :)


如果我有多个用户拥有自己的身份验证,我如何确保用户只能访问他们的数据?我还在服务器端有1个数据库?

If I have multiple users with there own authentication, how can I make sure that the users get access to only their data? And will I still have 1 database on server end?

pouchdb认证自述文件。 Cloudant和Couchbase也有自己的用于管理用户的系统。

There is a guide in the pouchdb-authentication README. Cloudant and Couchbase also have their own systems for managing users.


客户端上的PouchDB可以与远程PouchDB同步。但是当使用Javascript构建应用程序时,如何通过黑客客户端Javascript来确保人们不会将数据插入到PouchDB中?

PouchDB on the client side can be in sync with a remote PouchDB. But when an application is build with Javascript how do you make sure that people are not inserting data into PouchDB by 'hacking' the client-side Javascript?

您在服务器端写了一个 validate_doc_update 函数。当PouchDB尝试同步到CouchDB时,任何失败的文档都将发出'denied'事件,这些文档将不会同步。

You write a validate_doc_update function on the server side. When PouchDB tries to sync to CouchDB, any failed documents will emit a 'denied' event, and those documents will not sync.

对于本地数据库,你不能阻止用户写错误的数据(他们总是可以打开控制台并做任何他们想要的),但你可以使用像 pouchdb-validation 在客户端重新使用您的验证功能。或者你可以在 put()一个文档时自己做。

As for the local database, you cannot prevent users from writing bad data (they can always open up the console and do whatever they want), but you can use something like pouchdb-validation to re-use your validation function on the client side. Or you can just do it yourself when you put() a document.


后端的使用会不会在这些类型的设置?如果你想为第三方提供一个API,你只需在CouchDB附近放置一个Sails.js后端。

Would the use of a backend be gone in these kinds of setups? And if you want to have an API for 3rd party, you just put for example an Sails.js backend around the CouchDB?

人们编写没有任何后端(只使用纯CouchDB / Cloudant / Couchbase)的PouchDB应用程序,而其他人喜欢将数据库与他们选择的服务器体系结构混合。随你便。 :)

Some people write PouchDB apps without any backend (just using pure CouchDB/Cloudant/Couchbase), whereas others like to mix the database with a server architecture of their choice. It's up to you. :)

如果您使用Express,一个有趣的解决方案是使用 express -pouchdb ,因此您可以在现有体系结构中公开类似PouchDB服务器的端点。对于Sails.js,你必须自己写。

One interesting solution if you're using Express is to use express-pouchdb, so you can expose a PouchDB Server-like endpoint inside of your existing architecture. For Sails.js, though, you'd have to write your own.

这篇关于使用CouchDB / PouchDB时应用程序的体系结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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