IDBTransaction extension type
The IDBTransaction
interface of the
IndexedDB API
provides a static, asynchronous transaction on a database using event
handler attributes. All reading and writing of data is done within
transactions. You use IDBDatabase to start transactions, IDBTransaction
to set the mode of the transaction (e.g. is it readonly
or readwrite
),
and you access an IDBObjectStore to make a request. You can also use an
IDBTransaction
object to abort transactions.
Transactions are started when the transaction is created, not when the first request is placed; for example consider this:
const trans1 = db.transaction("foo", "readwrite");
const trans2 = db.transaction("foo", "readwrite");
const objectStore2 = trans2.objectStore("foo");
const objectStore1 = trans1.objectStore("foo");
objectStore2.put("2", "key");
objectStore1.put("1", "key");
After the code is executed the object store should contain the value "2",
since trans2
should run after trans1
.
A transaction alternates between active and inactive states between
event loop tasks. It's active in the task when it was created, and in each
task of the requests'
success
or
error
event handlers. It's inactive in all other tasks, in which case placing
requests will fail. If no new requests are placed when the transaction is
active, and there are no other outstanding requests, the transaction will
automatically commit.
API documentation sourced from MDN Web Docs.
- on
- Implemented types
- Available extensions
Properties
- db → IDBDatabase
-
The
db
read-only property of the IDBTransaction interface returns the database connection with which this transaction is associated.no setter - durability → IDBTransactionDurability
-
The
durability
read-only property of the IDBTransaction interface returns the durability hint the transaction was created with. This is a hint to the user agent of whether to prioritize performance or durability when committing the transaction.no setter - error → DOMException?
-
The
IDBTransaction.error
property of the IDBTransaction interface returns the type of error when there is an unsuccessful transaction.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- mode → IDBTransactionMode
-
The
mode
read-only property of the IDBTransaction interface returns the current mode for accessing the data in the object stores in the scope of the transaction (i.e. is the mode to be read-only, or do you want to write to the object stores?) The default value isreadonly
.no setter - objectStoreNames → DOMStringList
-
The
objectStoreNames
read-only property of the IDBTransaction interface returns a DOMStringList of names of IDBObjectStore objects.no setter - onabort ↔ EventHandler?
-
getter/setter pair
- oncomplete ↔ EventHandler?
-
getter/setter pair
- onerror ↔ EventHandler?
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
abort(
) → void -
The
abort()
method of the IDBTransaction interface rolls back all the changes to objects in the database associated with this transaction. -
addEventListener(
String type, EventListener? callback, [JSAny options]) → void -
The
addEventListener()
method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.inherited -
commit(
) → void -
The
commit()
method of the IDBTransaction interface commits the transaction if it is called on an active transaction. -
dispatchEvent(
Event event) → bool -
The
dispatchEvent()
method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually withdispatchEvent()
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
objectStore(
String name) → IDBObjectStore -
The
objectStore()
method of the IDBTransaction interface returns an object store that has already been added to the scope of this transaction. -
removeEventListener(
String type, EventListener? callback, [JSAny options]) → void -
The
removeEventListener()
method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited