Reputation: 1299
I am writing a small and simple API to abstract away Web SQL, indexedDB, and maybe even localStorage/JSON. The API will allow the programmer to think of the database as a small relational database even if the database actually being used is indexedDB or a localStorage/JSON data structure.
I don't know if there is a "standard" way of doing this but I am having the structure of the database be represented as a relational database which is defined in an XML schema. I think the final product will look like this: xsd --> xml (follows schema, defines db) --> javascript api --> (indexeddb/wwebsql/localStorage-JSON). Good idea? Mind you, that performance can be tuned inside the api. That is, I know indexedDB is not a relational database and that to some representing it as such is an unholy UNION but the API itself will work with indexedDB in a indexedDB way and Web SQL in a Web SQL way.
With that said I present to you my schema. I want to keep it very simple. As simple as possible. Can you make any improvements on this? One thing I would like to add is a defined type for a field. So that a field can have attribute type but it can only be certain values (string, number, 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>
Upvotes: 0
Views: 438
Reputation: 29238
IndexedDB is much more of a document-oriented (in reality, object oriented) store rather than a relational one. While it's possible to implement many-to-many relationships in IndexedDB, it's not exactly natural.
So while I think it'd be great to simplify all web storage into a simple XML schema, I don't think it's going to be incredibly expressive.
Upvotes: 1