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

查看:24
本文介绍了使用 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 数据库,特别是 CouchDBPouchDB.所以我想知道这个架构会是什么样子?对我来说,此时出现了三个问题:

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. 客户端的
  3. PouchDB 可以与远程PouchDB 同步.但是,当使用 Javascript 构建应用程序时,您如何确保人们不会通过破解"客户端 Javascript 将数据插入 PouchDB?
  4. 在这些类型的设置中会不再使用后端吗?如果您想为 3rd party 提供 API,您只需在 CouchDB 周围放置一个 Sails.js 后端?
  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-authentication README.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.

在这些类型的设置中是否会停止使用后端?如果您想为第 3 方提供 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?

有些人在没有任何后端的情况下编写 PouchDB 应用程序(仅使用纯 CouchDB/Cloudant/Couchbase),而其他人则喜欢将数据库与他们选择的服务器架构混合.由你决定.:)

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天全站免登陆