IDBFactory
IndexedDB API の IDBFactory
インターフェイスは、indexedDB への非同期アクセスを提供します。 このインターフェイスを実装するオブジェクトは、window.indexedDB
です。このオブジェクトを使用すれば、IDBFactory
インターフェイスに直接アクセスせずに、IndexedDB を開いたり (生成したり接続したり)、削除したりできます。
注:
この機能は Web Worker 内で利用可能です。メソッド
IDBFactory.open
- データベースへの接続を開く要求をする現在のメソッドです。
IDBFactory.deleteDatabase
- データベースの削除を要求するメソッドです。
IDBFactory.cmp
- 2 つのキーを比較して、大きいほうの値を戻り値として返すメソッドです。
IDBFactory.databases
(en-US)
例
次のコードスニペットでは、 データベースを開く要求をし、 成功の場合と失敗の場合のイベントハンドラーを登録しています。完全に動作する例は、To-do Notifications app (view example live.) を見てください。
var note = document.querySelector("ul");
// In the following line, you should include the prefixes of implementations you want to test.
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
// DON'T use "var indexedDB = ..." if you're not in a function.
// Moreover, you may need references to some window.IDB* objects:
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
// (Mozilla has never prefixed these objects, so we don't need window.mozIDB*)
// Let us open version 4 of our database
var DBOpenRequest = window.indexedDB.open("toDoList", 4);
// these two event handlers act on the database being opened successfully, or not
DBOpenRequest.onerror = function(event) {
note.innerHTML += '<li>Error loading database.</li>';
};
DBOpenRequest.onsuccess = function(event) {
note.innerHTML += '<li>Database initialised.</li>';
// store the result of opening the database in the db variable. This is used a lot later on, for opening transactions and suchlike.
db = DBOpenRequest.result;
};
仕様
仕様書 | 策定状況 | 備考 |
---|---|---|
Indexed Database API 2.0 IDBFactory の定義 |
勧告 | |
Indexed Database API 2.0 IDBFactory の定義 |
勧告 | |
Indexed Database API 3.0 IDBFactory の定義 |
編集者草案 |
ブラウザーの実装状況
BCD tables only load in the browser
関連情報
- Using IndexedDB
- Starting transactions:
IDBDatabase
- Using transactions:
IDBTransaction
- Setting a range of keys:
IDBKeyRange
(en-US) - Retrieving and making changes to your data:
IDBObjectStore
(en-US) - Using cursors:
IDBCursor
- Reference example: To-do Notifications (view example live.)