【发布时间】:2021-07-26 20:02:19
【问题描述】:
我想要什么
我想制作一个表格,将“CRUD 操作信息本身”保存在我的数据库中。
例如)
①create new row {"name": "Tom", "price": 200}
②find a row WHERE {"age": 30}
③delete row WHERE {"name": "John"}
④update the row WHERE {"name": "Ted"} SET {"price": 300}
我的想法
为了实现上述目的,我创建了两个模型。
①CrudOperation
t.string :crud_type # this should be one of CRUD ("create", "read", "update", "delete")
t.string :target_database
②CrudOperationParameter
t.integer :crud_operation_id # reference
t.string :key
t.value :value
CrudOperation 有很多 CrudOperationParameter-s。
问题
我的模型似乎运行良好,除了 crud_type 是“更新”。
这样
①新建行{"name": "Tom", "price": 200}
**CrudOperation**
id: 1
crud_type: "create"
target_database: "XXXX"
**CrudOperationParameter**
crud_operation_id: 1
key: "name"
value "Tom"
**Another CrudOperationParameter**
crud_operation_id: 1
key: "price"
value "200"
但是在注册 CrudOperation 的更新类型时,问题就出现了。
④更新行 WHERE {"name": "Ted"} SET {"price": 300}
**CrudOperation**
id: 1
crud_type: "update"
target_database: "XXXX"
**CrudOperationParameter**
crud_operation_id: 1
key: "name"
value "Ted"
**Another CrudOperationParameter**
crud_operation_id: 1
key: "price"
value "300"
由于 CrudOperationParameter 只有键值列, 我无法确定这个 CrudOperationParameter 是用于 UPDATE 语句中的 WHERE 子句还是 SET 子句。
你能教我更好的数据库架构来保存这些类型的数据吗?
【问题讨论】:
标签: ruby-on-rails database schema