[英]What database system to use? (EAV with FK?)
I'm working on an app and I was wondering what sort of database would be best for me. 我正在开发一个应用程序,我想知道什么样的数据库最适合我。
I'm trying to model listings but attributes/structure vary depending on locale. 我正在尝试对列表进行建模,但属性/结构因区域设置而异。 I'd like to compare, search, etc these listings/attributes across the different locale specific structures.
我想在不同的特定于语言环境的结构中比较,搜索等这些列表/属性。 There is always the option of creating a table for each locale but it'd be nice to refer to something like
price = 100
instead of price_us = 100 OR price_de = 100 OR etc..
总是可以选择为每个语言环境创建一个表,但是引用诸如
price = 100
而不是price_us = 100 OR price_de = 100 OR etc..
是很好的price_us = 100 OR price_de = 100 OR etc..
I've read a lot of the questions here regarding EAV in MySQL and it seems that it might not be an ideal solution for me (number of attributes; overly complex). 我在这里阅读了很多关于MySQL中EAV的问题,似乎它对我来说可能不是一个理想的解决方案(属性数量;过于复杂)。
Is there anything out there that gives me the that flexibility but also something like FK constraints? 那里有什么东西可以给我灵活性但也有类似FK约束的东西吗? (limiting to certain attributes or values?)
(限于某些属性或值?)
Well .. i would go with something like : 嗯..我会用以下的东西:
Products Locales Prices
---- ----------- -----------
product_id PK locale_id PK product_id FK
name title locale_id FK
descriptions amount
if needed >> currency_id FK
Seems like a sensible structure. 看起来像一个明智的结构。 For the
Prices
table the PRIMARY KEY
would be composite. 对于
Prices
表, PRIMARY KEY
将是复合的。
As for selecting product with all the data: 至于选择包含所有数据的产品:
SELECT
Procucts.product_id
Products.name
Price.amount
FROM Products
LFFT JOIN Prices USING(price_id)
LEFT JOIN Locales USING(locale_id)
WHERE Locale.title = 'uk'
EAV modelling is considered an sql anti-pattern and for a host of valid reasons although it is workable and fairly common place in certain sectors ie clinical systems. EAV建模被认为是一种sql反模式,并且出于许多有效的原因,尽管它在某些部门即临床系统中是可行且相当常见的。 However it goes against a number of principles that relational databases are based on (hence the term anti-pattern) and adds complexity/overhead to queries whilst making it difficult to maintain the relational context of the data.
然而,它违背了关系数据库所基于的许多原则(因此称为反模式)并且增加了查询的复杂性/开销,同时使得难以维护数据的关系上下文。
Perhaps a few years ago there was little choice but to implement this pattern in MySQL and indeed I have worked on a system that chose this approach. 也许几年前,除了在MySQL中实现这种模式之外别无选择,事实上我已经开发了一种选择这种方法的系统。 However 12 months ago we switched to a schemaless backend (mongoDB), which is a natural fit for storing records with variable attributes.
然而,12个月前我们切换到无模式后端(mongoDB),这非常适合存储具有可变属性的记录。
IMHO - If you're considering implementing an EAV pattern in MySQL consider a schemaless DB architecture first. 恕我直言 - 如果你正在考虑在MySQL中实现EAV模式,首先考虑无模式数据库架构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.