【问题标题】:indexedDB XML Schema?indexedDB XML 模式?
【发布时间】:2012-04-26 13:54:45
【问题描述】:

我正在编写一个小而简单的 API 来抽象出 Web SQL、indexedDB,甚至可能是 localStorage/JSON。 API 将允许程序员将数据库视为小型关系数据库,即使实际使用的数据库是 indexedDB 或 localStorage/JSON 数据结构。

我不知道是否有这样做的“标准”方式,但我将数据库的结构表示为在 XML 模式中定义的关系数据库。我认为最终产品将如下所示:xsd --> xml(遵循模式,定义 db)--> javascript api --> (indexeddb/wwebsql/localStorage-JSON)。好主意?请注意,该性能可以在 api 中进行调整。也就是说,我知道 indexedDB 不是关系数据库,对于某些人来说,它是一个邪恶的 UNION,但 API 本身将以 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>

【问题讨论】:

    标签: html xsd web-sql offline-mode indexeddb


    【解决方案1】:

    IndexedDB 更像是一种面向文档(实际上是面向对象)的存储,而不是关系存储。虽然可以在 IndexedDB 中实现 many-to-many relationships,但这并不完全自然。

    因此,虽然我认为将所有 Web 存储简化为一个简单的 XML 模式会很棒,但我认为它不会具有令人难以置信的表现力。

    【讨论】:

    • 您认为只使用 indexeddb 是否安全,或者离线解决方案是否应该还包括用于尚不支持 indexeddb 的设备的 web sql?
    猜你喜欢
    • 2011-10-28
    • 1970-01-01
    • 2014-12-01
    • 2018-04-18
    • 2023-03-06
    • 1970-01-01
    • 2011-03-04
    • 2012-08-05
    • 1970-01-01
    相关资源
    最近更新 更多