我正在尝试构建一个交互式表格,显示有关人们购物习惯的数据,LHS上的过滤器会动态更改显示的数据。如果未选中过滤器,则会显示所有数据。因此,在默认状态下,表可能如下所示:
State State | Person | Spend / Mo | Gender |
[ ] CA ---------------------------------------
[ ] NY CA | Kathy | $500 | Female |
[ ] AZ NY | Dianne | $600 | Female |
CA | Jeff | $1000 | Male |
Gender CA | Chris | $800 | Male |
[ ] Male AZ | Kristen | $750 | Female |
[ ] Female NY | Zachary | $2500 | Male |
Monthly Spend
[ ] <$500
[ ] $500-$1000
[ ] $1000-$5000
另一种配置(已检查过滤器)可能如下所示:
State State | Person | Spend / Mo | Gender |
[ ] CA ---------------------------------------
[X] NY NY | Dianne | $600 | Female |
[X] AZ AZ | Kristen | $750 | Female |
Gender
[ ] Male
[X] Female
Monthly Spend
[X] <$500
[X] $500-$1000
[ ] $1000-$5000
我希望能够在MySQL数据库中为用户保存此过滤器配置,但我在如何设计架构时遇到问题。到目前为止,我有两种可能性。第一个是:
table MyTable
id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
// a serialized list of all filters for the table, e.g.,
// "{State:CA,AZ}, {Gender:Female}, {Spend:,<500,500-1000}"
filters TEXT,
PRIMARY KEY (id)
我知道将列表序列化为文本通常是不受欢迎的,所以第二种可能性是:
table MyTable
id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
// one row would correspond to one checked filter for a table.
table Filters
filter_type varchar(255) NOT NULL,
filter_name varchar(255) NOT NULL,
table_id int,
PRIMARY KEY (table_id, filter_type, filter_name),
INDEX (table_id),
FOREIGN KEY (table_id) REFERENCES MyTable(id)
对我而言,第二种方法的缺点是,每次我想加载用户保存的表时,我都必须向Filters
进行额外的查询。
这些选项中的一个是首选,还是第三种方法更适合表示这种模式?作为一个注释,我被锁定为使用该应用程序的关系数据库(其余环境使用MySQL)。在此先感谢您的帮助!