我正在编写一个小而简单的API来抽象出Web、indexedDB,甚至可能是localStorage/JSON。即使实际使用的数据库是indexedDB或localStorage/JSON数据结构,应用程序接口也允许程序员将数据库视为小型关系数据库。
我不知道是否有这样做的“标准”方法,但是我将数据库的结构表示为在XML模式中定义的关系数据库。我认为最终的产品将如下所示: xsd --> xml (遵循schema,定义db) --> javascript api --> (indexeddb/wwebsql/localStorage-JSON)。好主意?请注意,性能可以在api中进行调优。也就是说,我知道indexedDB不是一个关系数据库,对某些人来说,它是一个不神圣的联盟,但它本身将以indexedDB的方式与indexedDB一起工作,以Web SQL的方式与Web SQL一起工作。
如上所述,我将向您介绍我的方案。我想让它非常简单。尽可能简单。你能在这方面做些改进吗?我想要添加的一件事是字段的定义类型。因此字段可以有属性类型,但只能是某些值(字符串、数字、blob、w/e)。
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- DATABASE -->
<xs:element name="database">
<xs:complexType>
<xs:choice>
<!-- TABLE-->
<xs:element name="table" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:choice>
<!-- FIELD -->
<xs:element name="field" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="pk" type="xs:boolean"/>
<xs:attribute name="fk" type="xs:string"/>
<xs:attribute name="unique" type="xs:boolean"/>
<xs:attribute name="index" type="xs:boolean"/>
<xs:attribute name="indentity" type="xs:boolean"/>
<xs:attribute name="maxSize" type="xs:long"/>
</xs:complexType>
</xs:element>
<!-- END FIELD -->
</xs:choice>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<!-- END TABLE -->
</xs:choice>
<xs:attribute name="version" type="xs:double" use="required"/>
</xs:complexType>
</xs:element>
<!-- END DATABASE -->
</xs:schema>发布于 2012-04-27 12:12:02
IndexedDB更像是面向文档(实际上是面向对象)的存储,而不是关系存储。虽然可以在IndexedDB中实现many-to-many relationships,但这并不是很自然。
因此,虽然我认为将所有web存储简化为一个简单的XML模式是很棒的,但我不认为它会有令人难以置信的表现力。
https://stackoverflow.com/questions/10334925
复制相似问题