HTML5之IndexedDB使用详解
HTML5NoSQL数据结构浏览器
随着firefox4正式版的推出,IndexedDB正式进入我们的视线。IndexedDB是HTML5-WebStorage的重要一环,是一种轻量级NOSQL数据库。相较之下,WebDataBase标准已经很长时间没有更新,大有被IndexedDB取代的意思。
Section 1:起步,得到Database引用
w3c为IndexedDB定义了很多接口,其中Database对象被定义为IDBDataBase。而得到IDBDataBase用的是工厂方法,即从IDBFactory中取得。浏览器对象中,实现了IDBFactory的只有indexedDB这个实例。
大家可以先看下IDBFactory和IDBDataBase接口的定义
Js代码
interface IDBFactory {
IDBRequestopen (in DOMString name);
IDBRequestdeleteDatabase (in DOMString name);
};
interface IDBDatabase : EventTarget {
readonlyattributeDOMString name;
readonlyattributeDOMString version;
readonlyattribute DOMStringList objectStoreNames;
IDBObjectStore createObjectStore (in DOMString name, in optional ObjectoptionalParameters) raises(IDBDatabaseException);
IDBRequest deleteObjectStore (in DOMString name) raises(IDBDatabaseException);
IDBVersionChangeRequest setVersion ([TreatNullAs=EmptyString] inDOMString version);
IDBTransaction transaction (in any storeNames, in optional unsigned short mode)raises (IDBDatabaseException);
void close ();
attributeFunction onabort;
attributeFunction onerror;
attributeFunction onversionchange;
};
interface IDBRequest : EventTarget {
readonlyattributeany result get raises (IDBDatabaseException);
readonlyattribute unsigned short errorCode get raises(IDBDatabaseException);
readonlyattributeObject source;
readonlyattribute IDBTransaction transaction;
constunsigned short LOADING = 1;
constunsigned short DONE = 2;
readonlyattribute unsigned short readyState;
attributeFunction onsuccess;
attributeFunction onerror;
};