如何在MySQL中表示树木及其内容?

时间:2021-10-28 12:31:37

I need to be able to store something like this: Structure http://i33.tinypic.com/f4dwea.jpg

我需要能够存储这样的东西:结构http://i33.tinypic.com/f4dwea.jpg

where the green is a template type, the gray is a field container type, and the white is field. (That being, a field has a label and some text, both mediumtext for simplicity; and a field container can store other field containers or text, and a template is a top-level field.)

其中绿色是模板类型,灰色是字段容器类型,白色是字段。 (也就是说,一个字段有一个标签和一些文本,两者都是简单的中间文本;一个字段容器可以存储其他字段容器或文本,而模板是一个*字段。)

Now, let's say I want to allow users to create any number of these structures, but it is unlikely to be more than say 10. And, of course, we need to be able to link data to it.

现在,假设我想允许用户创建任意数量的这些结构,但它不可能超过10个。当然,我们需要能够将数据链接到它。

This is all to be able to store in a database an associative array that looks for the above like, in pseudo code:

这就是能够在数据库中存储一个关联数组,它在伪代码中查找上面的内容:

my_template = {
  page_info => { description => 'hello!!!' },
  id => 0,
  content => { background_url => '12121.jpg', text => ...
}

Having an easy way to add a field to all data using the template when the template changes (say, we add a keywords to page_info) would be a big plus.

在模板更改时(例如,我们向page_info添加关键字),使用模板向所有数据添加字段的简单方法将是一个很大的优势。

I can't figure this out at all, thanks a lot!

我完全无法理解这一点,非常感谢!

1 个解决方案

#1


6  

There are several different ways to store heirarchical data structures (trees) in MySQL. You can for example choose:

有几种不同的方法可以在MySQL中存储层次数据结构(树)。你可以选择:

  • Adjacency list
  • 邻接清单
  • Nested sets
  • 嵌套集
  • Path enumeration
  • 路径枚举
  • Closure table
  • 关闭表

See Bill Karwin's presentation for more details on the pros and cons of each.

有关每种方法的优缺点的详细信息,请参阅Bill Karwin的演示文稿。

#1


6  

There are several different ways to store heirarchical data structures (trees) in MySQL. You can for example choose:

有几种不同的方法可以在MySQL中存储层次数据结构(树)。你可以选择:

  • Adjacency list
  • 邻接清单
  • Nested sets
  • 嵌套集
  • Path enumeration
  • 路径枚举
  • Closure table
  • 关闭表

See Bill Karwin's presentation for more details on the pros and cons of each.

有关每种方法的优缺点的详细信息,请参阅Bill Karwin的演示文稿。