如何在数据库中存储对象以供检索
我正在尝试创建一个可用于存储大量对象的数据库。我试图用关系数据库来做到这一点,但它似乎有点像野兽。我的意思是看下面这个简单的物体,
Object = {
"Type":"Car",
"Color":"Green",
"Doors":3,
Wheels:{
"Material":"Alloy",
"Size":17,
"Color":"Black",
"Tyres":{
"Profile":"Low",
"Material":"Rubber"
"Tread":"Slick"
}
},
Seats:{
"Number":2,
"Seatbelts":true
}
}
从这些物体中,您可以想象出一辆 3 门绿色汽车,配有黑色 17 英寸合金轮毂、低调的光滑橡胶轮胎、2 个带安全带的座椅。显然,这整个对象并不是一成不变的,您可以继续扩展
(例如。
Seatbelt:{
"Type":"Harness",
"Buckles":1,
"Color":"Blue"
}
)
最终,假设有很多对象,我想返回具有这些特征的对象列表
{
"Type":"Car"
"Doors":3
}
由此我可能获取 5 辆汽车的列表,这些汽车有 3 个门,但具有各种其他属性,没关系,我没有指定这些标准。我可以进一步缩小范围,寻找所有带有光头轮胎的 3 门汽车...我可能会得到 2
{
"Type":"Car"
"Doors":3
"Wheels":{
"Tyres":{
"Tread":"Slick"
}
}
}
所以我正在考虑一个具有 3 个主表的数据库:对象、属性和值。然后链接表,将对象链接到属性,将属性链接到值。但是,如果像示例中一样,我有包含对象的对象,并且如果我计划拥有一个汽车对象,该示例可以是该对象的扩展,该怎么办?
我们该如何处理此类数据库问题呢?可以使用关系数据库来完成还是我需要面向对象的数据库?如果是这样,是否有任何 OODB 可以像 MySQL 一样轻松地通过网站实现。
如果你可以使用 RDB 来做到这一点,那么查询肯定会非常消耗资源吗? OODB 怎么样?作为资源密集型?
如何为网站制作面向对象的数据库?使用 RDB 或 OODB,我不介意,只是如何
I am trying to create a database that can be used to store lots of objects. I was trying to do this with a relational database however it seems to be a bit of a beast. I mean take the simple object below
Object = {
"Type":"Car",
"Color":"Green",
"Doors":3,
Wheels:{
"Material":"Alloy",
"Size":17,
"Color":"Black",
"Tyres":{
"Profile":"Low",
"Material":"Rubber"
"Tread":"Slick"
}
},
Seats:{
"Number":2,
"Seatbelts":true
}
}
From these you could picture a 3 door green car, with black 17inch alloy wheels, low profile, slick rubber tyres, 2 seats with seatbelts. Obviously, this whole object is not set in stone, you could go and then expand upon things
(eg.
Seatbelt:{
"Type":"Harness",
"Buckles":1,
"Color":"Blue"
}
)
Eventually, assuming there are a lot of objects, I would want to return a list of objects that have these characteristics
{
"Type":"Car"
"Doors":3
}
From this I may get a list of 5 cars back that have 3 doors but have various other attributes, it doesn't matter, I haven't specified these criteria. I could narrow it down further, looking for all 3 door cars with slick tyres... I might get back 2
{
"Type":"Car"
"Doors":3
"Wheels":{
"Tyres":{
"Tread":"Slick"
}
}
}
So I was thinking a database having 3 main tables: objects, attributes and values. Then having linking tables, linking objects to attributes, attributes to values. However, what if, like in the example I have objects containing objects, and also if I plan on having an object of car which the example could be an extension of?
How do we deal with this type of database problem? Can it be done with a relational database or do I need an object oriented one? If so, are there any OODBs that I can implement with a website as easily as I can MySQL.
If you can use a RDB to do this, then queries, surely they would be very resource intensive? How about OODBs? As resource intensive?
How can I make a Object Oriented DB for a website? using RDB or OODB, I don't mind, it's just how
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会看一下 hibernate(对于 Java)或 nhibernate(对于 .net)。 http://www.hibernate.org
关系映射)
Hibernate 为关系数据库(如 MySql)提供 ORM(对象 解决方案(我个人不喜欢)对于少量数据是xml文件,然后您可以使用xpath表达式解析数据。 http://www.w3schools.com/xpath
I would take a look at hibernate (for Java) or nhibernate (for .net). http://www.hibernate.org
Hibernate provides ORM (Object Relational Mapping) for relational databases (like MySql)
Another solution (which I personally don't like) for small amounts of data are xml files, you can then parse the data with xpath expressions. http://www.w3schools.com/xpath