Haxe API Documentation
Back | Index
extern class js.html.idb.Database
extends js.html.EventTarget
Available in js

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



Documentation for this class was provided by MDN.
var name(default,null) : String
Name of the connected database.
var objectStoreNames(default,null) : js.html.DOMStringList
A list of the names of the object stores currently in the connected database.
var onabort : js.html.EventListener
var onerror : js.html.EventListener
var onversionchange : js.html.EventListener
var version(default,null) : Any
The version of the connected database. When a database is first created, this attribute is the empty string.
function close() : Void
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, 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.
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, use webkitIDBTransaction.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 the READ_WRITE mode.
Scope Code
Single object store

var transaction = db.transaction('my-store-name', IDBTransaction.READ_ONLY);

Alternatively:

var transaction = db.transaction('my-store-name', IDBTransaction.READ_ONLY);

Multiple object stores var transaction = db.transaction('my-store-name', 'my-store-name2', IDBTransaction.READ_ONLY);
All object stores

var transaction = db.transaction(db.objectStoreNames, IDBTransaction.READ_ONLY);

You cannot pass an empty array into the storeNames parameter, such as in the following: var transaction = db.transaction(, IDBTransaction.READ_ONLY);.

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:
  • The close() method has been called on this IDBDatabase instance.
  • The object store has been deleted or removed.
NOT_FOUND_ERR One of the object stores doesn't exist in the connected database.
Throws DatabaseException.

Back | Index