class js.html.idb.Database extends EventTarget
Available on jsThe 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
Documentation for this class was provided by MDN.
Instance Fields
var objectStoreNames:DOMStringList
A list of the names of the object stores currently in the connected database.
var onabort:EventListener
var onerror:EventListener
var version:Any
The version of the connected database. When a database is first created, this attribute is the empty string.
function createObjectStore(name:String, options:Dynamic):ObjectStore
function deleteObjectStore(name:String):Void
function setVersion(version:String):VersionChangeRequest
function transaction(storeName:String, mode:String):Transaction
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.
Parameters
- storeNames
- The names of object stores and indexes that are in the scope of the new transaction. Specify only the object stores that you need to access.
- mode
- Optional. The types of access that can be performed in the transaction. Transactions are opened in one of three modes:
READ_ONLY,READ_WRITE, andVERSION_CHANGE. If you don't provide the parameter, the default access mode isREAD_ONLY. To avoid slowing things down, don't open aREAD_WRITEtransaction, unless you actually need to write into the database.
Sample code
To start a transaction with the following scope, you can use the code snippets in the table. As noted earlier:
- Add prefixes to the methods in WebKit browsers, (that is, instead of
IDBTransaction.READ_ONLY, usewebkitIDBTransaction.READ_ONLY). - The default mode is
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 theREAD_WRITEmode.
| Scope | Code |
|---|---|
| Single object store |
Alternatively:
|
| Multiple object stores | var transaction = db.transaction(['my-store-name', 'my-store-name2'], IDBTransaction.READ_ONLY); |
| 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. |
Returns
IDBTransaction- The transaction object.
Exceptions
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. |