public interface IDBDatabase extends EventTarget
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
Modifier and Type | Method and Description |
---|---|
EventRemover |
addEventListener(String type,
EventListener listener)
Register an event handler of a specific event type on the
EventTarget . |
EventRemover |
addEventListener(String type,
EventListener listener,
boolean useCapture)
Register an event handler of a specific event type on the
EventTarget . |
void |
close()
Returns immediately and closes the connection in a separate thread.
|
IDBObjectStore |
createObjectStore(String name)
Creates and returns a new object store or index.
|
IDBObjectStore |
createObjectStore(String name,
Mappable options)
Creates and returns a new object store or index.
|
void |
deleteObjectStore(String name)
Destroys the object store with the given name in the connected database, along with any indexes that reference it.
|
boolean |
dispatchEvent(Event evt)
Dispatch an event to this
EventTarget . |
String |
getName()
Name of the connected database.
|
Indexable |
getObjectStoreNames()
A list of the names of the object stores currently in the connected database.
|
EventListener |
getOnabort() |
EventListener |
getOnerror() |
EventListener |
getOnversionchange() |
String |
getVersion()
The version of the connected database.
|
void |
removeEventListener(String type,
EventListener listener)
Removes an event listener from the
EventTarget . |
void |
removeEventListener(String type,
EventListener listener,
boolean useCapture)
Removes an event listener from the
EventTarget . |
void |
setOnabort(EventListener arg) |
void |
setOnerror(EventListener arg) |
void |
setOnversionchange(EventListener arg) |
IDBTransaction |
transaction(Indexable storeNames)
Immediately returns an IDBTransaction object, and starts a transaction in a separate thread.
|
IDBTransaction |
transaction(Indexable storeNames,
int mode)
Immediately returns an IDBTransaction object, and starts a transaction in a separate thread.
|
IDBTransaction |
transaction(Indexable storeNames,
String mode)
Immediately returns an IDBTransaction object, and starts a transaction in a separate thread.
|
IDBTransaction |
transaction(String storeName)
Immediately returns an IDBTransaction object, and starts a transaction in a separate thread.
|
IDBTransaction |
transaction(String storeName,
int mode)
Immediately returns an IDBTransaction object, and starts a transaction in a separate thread.
|
IDBTransaction |
transaction(String storeName,
String mode)
Immediately returns an IDBTransaction object, and starts a transaction in a separate thread.
|
String getName()
Indexable getObjectStoreNames()
EventListener getOnabort()
void setOnabort(EventListener arg)
EventListener getOnerror()
void setOnerror(EventListener arg)
EventListener getOnversionchange()
void setOnversionchange(EventListener arg)
String getVersion()
EventRemover addEventListener(String type, EventListener listener)
EventTarget
EventTarget
.addEventListener
in interface EventTarget
EventRemover addEventListener(String type, EventListener listener, boolean useCapture)
EventTarget
EventTarget
.addEventListener
in interface EventTarget
void close()
Returns immediately and closes the connection in a separate thread. The connection is not actually closed until all transactions created using this connection are complete. No new transactions can be created for this connection once this method is called. Methods that create transactions throw an exception if a closing operation is pending.
void close();
IDBObjectStore createObjectStore(String name)
Creates and returns a new object store or index. The method takes the name of the store as well as a parameter object. The parameter object lets you define important optional properties. You can use the property to uniquely identify individual objects in the store. As the property is an identifier, it should be unique to every object, and every object should have that property.
But before you can create any object store or index, you must first call the setVersion()
method.
IDBDatabaseOptionalParameters
, which is not yet recognized by any browserOptional. Options object whose attributes are optional parameters to the method. It includes the following properties:
Attribute | Description |
---|---|
keyPath | The key path to be used by the new object store. If empty or not specified, the object store is created without a key path and uses out-of-line keys. |
autoIncrement | If true, the object store has a key generator. Defaults to false . |
Unknown parameters are ignored.
IDBObjectStore
This method can raise an IDBDatabaseException with the following codes:
Exception | Description |
---|---|
NOT_ALLOWED_ERR | The method was not called from a VERSION_CHANGE transaction callback. You must call setVersion() first. |
CONSTRAINT_ERR | An object store with the given name (based on case-sensitive comparison) already exists in the connected database. |
NON_TRANSIENT_ERR | optionalParameters has attributes other than keyPath and autoIncrement . |
IDBObjectStore createObjectStore(String name, Mappable options)
Creates and returns a new object store or index. The method takes the name of the store as well as a parameter object. The parameter object lets you define important optional properties. You can use the property to uniquely identify individual objects in the store. As the property is an identifier, it should be unique to every object, and every object should have that property.
But before you can create any object store or index, you must first call the setVersion()
method.
IDBDatabaseOptionalParameters
, which is not yet recognized by any browserOptional. Options object whose attributes are optional parameters to the method. It includes the following properties:
Attribute | Description |
---|---|
keyPath | The key path to be used by the new object store. If empty or not specified, the object store is created without a key path and uses out-of-line keys. |
autoIncrement | If true, the object store has a key generator. Defaults to false . |
Unknown parameters are ignored.
IDBObjectStore
This method can raise an IDBDatabaseException with the following codes:
Exception | Description |
---|---|
NOT_ALLOWED_ERR | The method was not called from a VERSION_CHANGE transaction callback. You must call setVersion() first. |
CONSTRAINT_ERR | An object store with the given name (based on case-sensitive comparison) already exists in the connected database. |
NON_TRANSIENT_ERR | optionalParameters has attributes other than keyPath and autoIncrement . |
void deleteObjectStore(String name)
Destroys the object store with the given name in the connected database, along with any indexes that reference it.
As with createObjectStore()
, this method can be called only within a VERSION_CHANGE
transaction. So you must call the setVersion()
method first before you can remove any object store or index.
void
This method can raise an IDBDatabaseException with the following codes:
Exception | Description |
---|---|
NOT_ALLOWED_ERR | The method was not called from a VERSION_CHANGE transaction callback. You must call setVersion() first. |
NOT_FOUND_ERR | You are trying to delete an object store that does not exist. Names are case sensitive. |
boolean dispatchEvent(Event evt)
EventTarget
EventTarget
.dispatchEvent
in interface EventTarget
void removeEventListener(String type, EventListener listener)
EventTarget
EventTarget
.removeEventListener
in interface EventTarget
void removeEventListener(String type, EventListener listener, boolean useCapture)
EventTarget
EventTarget
.removeEventListener
in interface EventTarget
IDBTransaction transaction(Indexable storeNames)
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(['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. |
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. |
IDBTransaction transaction(Indexable storeNames, String mode)
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(['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. |
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. |
IDBTransaction transaction(String storeName)
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(['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. |
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. |
IDBTransaction transaction(String storeName, String mode)
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(['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. |
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. |
IDBTransaction transaction(Indexable storeNames, int mode)
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(['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. |
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. |
IDBTransaction transaction(String storeName, int mode)
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(['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. |
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. |
Copyright © 2018. All rights reserved.