IndexedDBBackend Class
The storage of the IndexedDB databases (https://w3c.github.io/IndexedDB/) of the browsing contexts, e.g. a SQLite database or InMemoryIndexedDBBackend (see BrowsingContextOptions.IndexedDB). The backend stores the schemas and the records of the databases of each origin, and runs the queries of the library: the library implements the API (the requests, the events, the transaction scheduling, the key generators, the key paths and the indexes) and only reads and writes bytes.
public abstract class IndexedDBBackendRemarks
The keys and the values are opaque byte arrays. The keys are encoded so that their byte order (MemoryExtensions.SequenceCompareTo, i.e. memcmp) is the order of the IndexedDB keys (https://w3c.github.io/IndexedDB/#compare-two-keys): a backend sorts and compares the keys as byte strings (e.g. the BLOB columns of SQLite), and never decodes them. The values are the serialized JavaScript values, including the bytes of their blobs and files.
The data of an origin is changed in transactions (IndexedDBBackend.BeginTransaction) that the library commits or aborts. The library guarantees that:
- the calls for a database (of an origin) are never concurrent (but the calls for different databases can be);
- at most one
IdbTransactionMode.ReadWriteorIdbTransactionMode.VersionChangetransaction of a database is open at a time; - the
IdbTransactionMode.ReadOnlytransactions that are open at the same time as a read-write transaction do not read its object stores; - no transaction of a database is open while it is deleted.
So a backend can run a read-write transaction as a transaction of its storage (e.g. BEGIN, COMMIT and ROLLBACK on a SQLite connection), and the read-only transactions without isolation. The methods are called on the threads of the event loops of the windows and the workers that use the databases: an implementation must be thread-safe, and its exceptions make the requests fail with an UnknownError (or the transaction abort).
The database names, the object store names and the index names are arbitrary strings (possibly empty, with lone surrogates). The object stores and the indexes are identified by ids assigned by the library, which are unique in a database and never reused while the database exists.
Constructors
| Name | Description |
|---|---|
| IndexedDBBackend() |
IndexedDBBackend()
protected IndexedDBBackend()No documentation is available.
Methods
| Name | Description |
|---|---|
| BeginTransaction(string, string, IdbTransactionMode, IReadOnlyList<long>) | Begins a transaction on a database. A IdbTransactionMode.VersionChange transaction creates the database (with the version 0 and no object store) when it does not exist; aborting this transaction deletes it. |
| DeleteDatabase(string, string) | Deletes a database and its data (https://w3c.github.io/IndexedDB/#delete-a-database). Does nothing when it does not exist. |
| GetDatabase(string, string) | Returns the schema of a database, or null when the database does not exist. |
| GetDatabases(string) | Returns the name and the version of the databases of an origin (https://w3c.github.io/IndexedDB/#dom-idbfactory-databases). |
| GetUsage(string) | Returns an estimation of the number of bytes used by the databases of an origin (navigator.storage.estimate()). The default is 0: the usage is not reported. |
BeginTransaction(string, string, IdbTransactionMode, IReadOnlyList<long>)
Begins a transaction on a database. A IdbTransactionMode.VersionChange transaction creates the database (with the version 0 and no object store) when it does not exist; aborting this transaction deletes it.
public abstract IndexedDBBackendTransaction BeginTransaction(string origin, string name, IdbTransactionMode mode, IReadOnlyList<long> objectStoreIds)Parameters
originstring- The serialization of the origin.
namestring- The name of the database.
modeIdbTransactionMode- The mode of the transaction.
objectStoreIdsIReadOnlyList<long>- The ids of the object stores of the scope of the transaction (all the object stores for a version change transaction).
Returns
DeleteDatabase(string, string)
GetDatabase(string, string)
Returns the schema of a database, or null when the database does not exist.
public abstract IndexedDBDatabaseSchema? GetDatabase(string origin, string name)Parameters
Returns
GetDatabases(string)
Returns the name and the version of the databases of an origin (https://w3c.github.io/IndexedDB/#dom-idbfactory-databases).
public abstract IReadOnlyList<IndexedDBDatabaseInfo> GetDatabases(string origin)