Class IDBTransaction
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
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.
[Value("IDBTransaction")]
public class IDBTransaction : EventTarget
- Inheritance
-
IDBTransaction
- Inherited Members
Remarks
Transactions are started when the transaction is created, not when the first request is placed; for example consider this:
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.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Constructors
IDBTransaction()
public IDBTransaction()
Properties
Db
The db read-only property of the IDBTransaction interface returns the database connection
with which this transaction is associated.
[Value("db")]
public IDBDatabase Db { get; }
Property Value
- IDBDatabase
An IDBDatabase object.
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Durability
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.
[Value("durability")]
public IDBTransactionDurability Durability { get; }
Property Value
- IDBTransactionDurability
Any of the following literal 'String':
Remarks
The value of this property is defined in the options.durability parameter when creating a transaction using Transaction(Union104, IDBTransactionMode, IDBTransactionOptions).
Error
The IDBTransaction.error property of the IDBTransaction interface
returns the type of error when there is an unsuccessful transaction.
[Value("error")]
public DOMException? Error { get; }
Property Value
- DOMException
A DOMException containing the relevant error, or
nullif there are none.It can be a reference to the same error as the request object that raised it, or a transaction
failure (for exampleQuotaExceededError).This property isnullif the transaction is not finished, or is finished and
was successfully committed.
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Mode
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.
[Value("mode")]
public IDBTransactionMode Mode { get; }
Property Value
- IDBTransactionMode
An object defining the mode for isolating access to
data in the current object stores:
A string defining the mode for isolating access to data in the current object stores.
The following values are available:
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
ObjectStoreNames
The objectStoreNames read-only property of the
IDBTransaction interface returns a DOMStringList of names
of IDBObjectStore objects.
[Value("objectStoreNames")]
public DOMStringList ObjectStoreNames { get; }
Property Value
- DOMStringList
A DOMStringList of names of IDBObjectStore objects.
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Onabort
[Value("onabort")]
public EventHandlerNonNull Onabort { get; set; }
Property Value
Oncomplete
[Value("oncomplete")]
public EventHandlerNonNull Oncomplete { get; set; }
Property Value
Onerror
[Value("onerror")]
public EventHandlerNonNull Onerror { get; set; }
Property Value
Methods
Abort()
The abort() method of the IDBTransaction
interface rolls back all the changes to objects in the database associated with this
transaction.
[Value("abort")]
public GlobalObject.Undefined Abort()
Returns
Remarks
All pending IDBRequest objects created during this transaction have
their Error attribute set to an AbortError DOMException.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Commit()
The commit() method of the IDBTransaction interface commits the transaction if it is called on an active transaction.
[Value("commit")]
public GlobalObject.Undefined Commit()
Returns
Remarks
Note that commit() doesn't normally have to be called — a transaction will automatically commit when all outstanding requests have been satisfied and no new requests have been made. commit() can be used to start the commit process without waiting for events from outstanding requests to be dispatched.
If it is called on a transaction that is not active, it throws an InvalidStateError DOMException.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
ObjectStore(string)
The objectStore() method of the
IDBTransaction interface returns an object store that has already been
added to the scope of this transaction.
[Value("objectStore")]
public IDBObjectStore ObjectStore(string name)
Parameters
namestring
Returns
- IDBObjectStore
An IDBObjectStore object for accessing an object store.
Remarks
Every call to this method on the same transaction object, with the same name, returns
the same IDBObjectStore instance. If this method is called on a different
transaction object, a different IDBObjectStore instance is returned.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).