1

我正在考虑编写另一个框架以更轻松地开发“bread'n'butter”应用程序的想法(例如创建一个具有 N 个字段的类,免费获得一个编辑器以及 DB 持久性)。

所有数据模型都可以转换为Entity-Attribute-Value形式:

TYPE VARCHAR(32)
ID LONG INT
NAME VARCHAR(32)
VALUE VARCHAR(64000)

可能有第二个表用于非常大的字段,所以我会在 VALUE 列中保留对 BLOB 表中条目的引用。如果我有心情,我可以为每个值类型创建一个表(因此 int 将是 INTEGER,避免所有转换问题),我可以使用一个表来定义有效的类型等。

这将有效地让我不必担心数据库设计,因为没有数据库设计。数据库可以通过使用简单的更新来适应我的模型中的任何变化。我什至可以拥有具有附加字段的同一类的实例。

缺点是对于每个对象,我需要读取 N 行,或者我需要从构建包含 N 个子查询的复杂查询开始。

这个事情谁有经验?有没有人以这种方式实施过更大的系统?除了普通的 SQL 之外,还有哪些其他选项可以持久化数据?我特别想听听敏捷系统很容易适应模型的变化或允许“修补”模型(通常,一个实例会有一个名字,但对于某些人,我还想添加评论) . 或者有没有人遇到过post-SQL?下一个伟大的事情?

4

4 回答 4

1

我没有使用它,但是您尝试做的事情听起来像CouchDB。在重新发明轮子之前,您可能想看看那里......

于 2009-03-10T12:54:05.100 回答
1

This approach is used by Amazon SimpleDB. You define domains and each domains has rows with a bunch of key/value pairs in it. This data is known as 'semi-structured'.

This approach has some strengths. Like your idea, you do not need to define a database schema. You can introduce new tables ad-hoc, new columns on a per-row basis, and even have columns that have more than one value (instead of creating a has_many relationship with an extra table). If your schema changes, you can introduce these changes transitionally rather than force migration.

On the other hand, you're throwing away decades of development on the relational model. You will hemorrhage speed because your indexing will either be too general or non-existent. Aggregate operations (groups, joins) will be extremely slow. Query optimisation will be difficult, etc.

Both Amazon SimpleDB and Apache CouchDB deal with this issue by making their databases highly distributed. While this ensures reliability and redundancy, it has its own set of problems, such as conflict resolution and out-of-date data.

From your question you seem dead set on an 'agile' methods, so I would recommend one of those two DB engines (depending on whether you'd rather pay Amazon - albeit not much - or build your own setup). They both allow a completely dynamic database schema. Just beware of the pitfalls.

于 2009-03-10T13:27:44.007 回答
0

看看 XML 数据库(如eXist)。您可以通过修改 xml 架构轻松更改“数据模型”。您可以使用强大的查询语言,如 XPath 和 XQuery。

于 2009-03-10T12:53:28.423 回答
0

我从未将整个应用程序基于此原则,但在几乎所有应用程序中,我确实使用某种形式的键值对集合来处理特定实体需要一些其他实体不需要的其他属性的极端情况。

我基本上序列化字典并将其与我的实体数据一起存储在数据库中。当我必须处理一些太模糊而无法保证对整个模型进行更改时,这就是我用于后期制作修补的方法。

使用键值对数据,我也确实存储了类型,因此我可以自动呈现适当的 HTML 控件。我只有基本类型:文本、多行、RTF、复选框、数字和日期。

于 2009-03-10T12:54:48.907 回答