[英]User-created database structure: non-relational or relational databases?
I want to have dynamic fields in my database records. 我想在数据库记录中包含动态字段。
For example: I want to build an application for users to create their own forms. 例如:我想构建一个应用程序,供用户创建自己的表单。
A user could create the following forms: 用户可以创建以下表单:
Personal profile: 个人资料:
Work: 工作:
Countries: 国家:
As you can see this is a very dynamical structure: 如您所见,这是一个非常动态的结构:
So I wonder, what is the best database for this: relational (mysql/postgresql) or non-relational like mongodb/couchdb/cassandra or even xml databases like xindice? 所以我想知道,最好的数据库是什么:关系型(mysql / postgresql)或非关系型(如mongodb / couchdb / cassandra)甚至是xml数据库(如xindice)?
And even if I choose non-relational databases for this, would it be smart to store security-critical information on it like customer and billing information? 即使我为此选择了非关系型数据库,将诸如客户和账单信息之类的安全关键信息存储在其上是否明智?
I have heard people say that if your information require uniqueness then use relational database. 我听说有人说,如果您的信息需要唯一性,请使用关系数据库。 "We don't want to risk to bill our customers twice".
“我们不想冒两次向客户收费的风险”。 What problems on non-relational databases do they actually mean?
非关系数据库实际上意味着什么问题? Can't you store unique data in non-relational databases?
您不能在非关系数据库中存储唯一数据吗?
Another thing I was thinking about: Won't saving data in non-relational databases mean that I will have duplicated entries? 我正在考虑的另一件事:是否将数据保存在非关系数据库中意味着我将有重复的条目?
Consider this example: 考虑以下示例:
Categories: 分类:
Office 办公室
Office 办公室
As you see there are situations for identical entries. 如您所见,存在相同条目的情况。 How do non-relational databases handle these?
非关系数据库如何处理这些? Im so used to relational databases.
我是如此习惯于关系数据库。
I sum up my questions: 我总结一下我的问题:
I highly recommend you check out CouchDB for this. 我强烈建议您为此查看CouchDB 。
submission:user:5:form:a3df2a712
submission:user:5:form:a3df2a712
Using CouchDB you can avoid the pain of dynamically creating unique tables for every form a user might create. 使用CouchDB,您可以避免为用户可能创建的每种表单动态创建唯一表的麻烦。
If your data fits the relational model pretty well, but you need to store some dynamically formatted data that isn't enormous, then you will probably be better off storing JSON, XML, or similar into a column. 如果您的数据非常适合关系模型,但是您需要存储一些动态格式化的数据,这些数据不是很大,那么最好将JSON,XML或类似的数据存储到列中。 Although you lose some advantages of first-class SQL typing by doing this (indexing, foreign key constraint checking, type checking, etc.), it's good for storing dynamically-structured documents when your queries don't care much about their internals.
尽管这样做会使您失去一流SQL输入的某些优势(索引编制,外键约束检查,类型检查等),但是当您的查询不太在意它们的内部时,它对于存储动态结构化文档非常有用。
If you're interested in storing mostly relational data with a touch of JSON/XML/etc., I recommend looking to PostgreSQL. 如果您有兴趣通过JSON / XML / etc等来存储大部分关系数据,建议您使用PostgreSQL。 PostgreSQL has an XML data type, but I don't recommend using it since I hate XML :P .
PostgreSQL有XML数据类型,但是我不推荐使用它,因为我讨厌XML:P。 Nobody's stopping you from storing JSON in a TEXT field, but PostgreSQL will soon have a JSON data type with supporting functions.
没有人阻止您将JSON存储在TEXT字段中,但是PostgreSQL很快将具有支持功能的JSON数据类型。 The hstore contrib module provides an efficient way to store key/value pairs, and also provides full-text index support.
hstore contrib模块提供了一种存储键/值对的有效方法,并且还提供了全文本索引支持。
Although shoving JSON or similar into a SQL database column flies in the face of the relational model, you're usually better off doing it anyway (when it makes sense!). 尽管将JSON或类似的东西推到SQL数据库列中虽然是关系模型的事,但是您通常还是最好这么做(在有意义的时候!)。 Otherwise, you have to explain the entire schema of your application to the database, resulting in a lot of SQL and database mapping code that really doesn't do anything.
否则,您必须向数据库解释应用程序的整个架构,从而导致很多SQL和数据库映射代码实际上什么也没做。
The database to choose depends more on what and how you want to query something moreso than what you want to store. 选择的数据库更多地取决于您要查询的内容和方式,而不是要存储的内容。 All the DBs will let you store pretty much whatever you want.
所有的数据库将使您几乎存储任何您想要的东西。
RDBMS are particularly good at querying based on the relational model, and doing so reasonably arbitrarily. RDBMS特别擅长基于关系模型的查询,并且可以合理地任意进行。 Through ad hoc filters and joins, you can do all sorts of magic.
通过临时过滤器和联接,您可以进行各种魔术。
The NOSQL DBs tend to be less flexible on their queries, but do well at other tasks (such as working better on "unstructured" data for example). NOSQL DB的查询灵活性较差,但在其他任务上却做得很好(例如,对“非结构化”数据的处理更好)。
Given what you've posted here, I'd just use a SQL database and define the tables as the user wants them defined. 鉴于您在此处发布的内容,我将只使用一个SQL数据库并按照用户想要的定义表。 Set up the indexes, set up the queries.
设置索引,设置查询。 Sounds like a real no brainer to me.
听起来对我来说真是不费吹灰之力。 SQL DBs handle all of that "defining fields on the fly" stuff handily, because...that's what they do.
SQL DB可以轻松处理所有这些“动态定义字段”的内容,因为...这就是它们的工作。 So use that.
所以用那个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.