The IDBDatabase
interface of the IndexedDB API provides asynchronous access to a connection to a database. Use it to create, manipulate, and delete objects in that database. The interface also provides the only way to get a transaction and manage versions on that database.
Inherits from: EventTarget
Immediately returns an IDBTransaction object, and starts a transaction in a separate thread. The method returns a transaction object (IDBTransaction
) containing the objectStore() method, which you can use to access your object store.
READ_ONLY
, READ_WRITE
, and VERSION_CHANGE
. If you don't provide the parameter, the default access mode is READ_ONLY
. To avoid slowing things down, don't open a READ_WRITE
transaction, unless you actually need to write into the database.To start a transaction with the following scope, you can use the code snippets in the table. As noted earlier:
IDBTransaction.READ_ONLY
, use webkitIDBTransaction.READ_ONLY
).READ_ONLY
, so you don't really have to specify it. Of course, if you need to write into the object store, you can open the transaction in the READ_WRITE
mode.Scope | Code |
---|---|
Single object store |
Alternatively:
|
Multiple object stores | var transaction = db.transaction( |
All object stores |
You cannot pass an empty array into the storeNames parameter, such as in the following: Warning: Accessing all obejct stores under the READ_WRITE mode means that you can run only that transaction. You cannot have writing transactions with overlapping scopes. |
IDBTransaction
This method can raise an IDBDatabaseException with the following codes:
Exception | Description |
---|---|
NOT_ALLOWED_ERR | The error is thrown for one of two reasons:
|
NOT_FOUND_ERR | One of the object stores doesn't exist in the connected database. |