SynchronousTransaction
Extends:
Implements:
Indirect Implements:
Synchronous transactions avoid unnecessary async/await calls by preloading and caching all necessary key-value-pairs.
WARNING: If not all required key-value-pairs are preloaded, the results of any call on a synchronous transaction might be wrong. Only use synchronous transactions, if unavoidable.
Constructor Summary
Protected Constructor | ||
protected |
constructor(objectStore: ObjectStore, parent: IObjectStore, managingBackend: ICommittable, enableWatchdog: boolean) This constructor should only be called by an ObjectStore object. |
Method Summary
Public Methods | ||
public |
async get(key: string, options: RetrievalConfig): * |
|
public |
getSync(key: string, options: SyncRetrievalConfig): * Returns the object stored under the given primary key. |
|
public |
isCached(key: string): boolean A check whether a certain key is cached. |
|
public |
isSynchronous(): boolean Checks whether an object store implements the ISynchronousObjectStore interface. |
|
public |
preload(keys: Array<string>): Promise This method preloads a set of keys and caches them. |
Inherited Summary
From class Transaction | ||
public get |
connected: boolean |
|
public get |
|
|
public get |
id: number |
|
public get |
A map of index names to indices. |
|
public get |
nested: boolean |
|
public get |
|
|
public get |
state: Transaction.STATE: * The transaction's current state. |
|
public |
async abort(tx: Transaction): Promise<boolean> Aborts a transaction and (if this was the last open transaction) potentially persists the most recent, committed state. |
|
public |
close(): Promise Alias for abort. |
|
public |
async commit(tx: Transaction): Promise<boolean> Commits a transaction to the underlying backend. |
|
public |
Returns the count of entries in the given range. |
|
public |
decode(value: *, key: string): * Method called to decode a single value. |
|
public |
encode(value: *): * Method called to encode a single value. |
|
public |
async get(key: string, options: RetrievalConfig): Promise<*> Returns a promise of the object stored under the given primary key. |
|
public |
Returns the index of the given name. |
|
public |
isSynchronous(): boolean Checks whether an object store implements the ISynchronousObjectStore interface. |
|
public |
async keyStream(callback: function(key: string): boolean, ascending: boolean, query: KeyRange): Promise Iterates over the keys in a given range and direction. |
|
public |
Returns a promise of a set of keys fulfilling the given query. |
|
public |
Returns a promise of the key being maximal for the given range. |
|
public |
Returns a promise of the object whose primary key is maximal for the given range. |
|
public |
Returns a promise of the key being minimal for the given range. |
|
public |
Returns a promise of the object whose primary key is minimal for the given range. |
|
public |
async put(key: string, value: *): Promise Inserts or replaces a key-value pair. |
|
public |
putSync(key: string, value: *) Inserts or replaces a key-value pair. |
|
public |
async remove(key: string): Promise Removes the key-value pair of the given key from the object store. |
|
public |
removeSync(key: string) Removes the key-value pair of the given key from the object store. |
|
public |
Creates an in-memory snapshot of this state. |
|
public |
synchronousTransaction(enableWatchdog: boolean): SynchronousTransaction Creates a nested synchronous transaction, ensuring read isolation. |
|
public |
toString(): string |
|
public |
toStringShort(): string |
|
public |
transaction(enableWatchdog: boolean): Transaction Creates a nested transaction, ensuring read isolation. |
|
public |
async truncate(): Promise Empties the object store. |
|
public |
async valueStream(callback: function(value: *, key: string): boolean, ascending: boolean, query: KeyRange): Promise Iterates over the keys and values in a given range and direction. |
|
public |
Returns a promise of an array of objects whose primary keys fulfill the given query. |
|
protected |
async _apply(tx: Transaction): Promise Internally applies a transaction to the transaction's state. This needs to be done in batch (as a db level transaction), i.e., either the full state is updated or no changes are applied. |
|
protected |
_applySync(tx: Transaction) Non-async version of _apply that does not update snapshots. |
|
protected |
async _checkConstraints(): Promise<boolean> Is used to check constraints before committing. |
|
protected |
async _commitBackend(): Promise<boolean> Commits the transaction to the backend. |
|
protected |
async _commitInternal(tx: Transaction): Promise Is used to commit the transaction to the in memory state. |
|
protected |
_isCommittable(tx: Transaction): boolean Is used to probe whether a transaction can be committed. |
|
protected |
_put(key: string, value: *) Internal method for inserting/replacing a key-value pair. |
|
protected |
_remove(key: string) Internal method for removing a key-value pair. |
|
protected |
_setParent(parent: *) Allows to change the backend of a Transaction when the state has been flushed. |
|
protected |
Non-async variant to empty the object store. |
Protected Constructors
protected constructor(objectStore: ObjectStore, parent: IObjectStore, managingBackend: ICommittable, enableWatchdog: boolean) source
This constructor should only be called by an ObjectStore object. Our transactions have a watchdog enabled by default, logging a warning after a certain time specified by WATCHDOG_TIMER. This helps to detect unclosed transactions preventing to store the state in the persistent backend.
Override:
Transaction#constructorParams:
Name | Type | Attribute | Description |
objectStore | ObjectStore | The object store this transaction belongs to. |
|
parent | IObjectStore | The backend on which the transaction is based, i.e., another transaction or the real database. |
|
managingBackend | ICommittable |
|
The object store managing the transactions, i.e., the ObjectStore object. |
enableWatchdog | boolean |
|
If this is is set to true (default), a warning will be logged if left open for longer than WATCHDOG_TIMER. |
Public Methods
public async get(key: string, options: RetrievalConfig): * source
Returns a promise of the object stored under the given primary key. Resolves to undefined if the key is not present in the object store.
Override:
Transaction#getParams:
Name | Type | Attribute | Description |
key | string | ||
options | RetrievalConfig |
|
Advanced retrieval options. |
Return:
* |
public getSync(key: string, options: SyncRetrievalConfig): * source
Returns the object stored under the given primary key. Resolves to undefined if the key is not present in the object store.
Params:
Name | Type | Attribute | Description |
key | string | The primary key to look for. |
|
options | SyncRetrievalConfig |
|
Advanced retrieval options. |
Return:
* | The object stored under the given key, or undefined if not present. |
public isCached(key: string): boolean source
A check whether a certain key is cached.
Params:
Name | Type | Attribute | Description |
key | string | The key to check. |
Return:
boolean | A boolean indicating whether the key is already in the cache. |
public isSynchronous(): boolean source
Checks whether an object store implements the ISynchronousObjectStore interface.
Override:
Transaction#isSynchronousReturn:
boolean | The transaction object. |
public preload(keys: Array<string>): Promise source
This method preloads a set of keys and caches them. It can be called as often as needed.
Params:
Name | Type | Attribute | Description |
keys | Array<string> | The keys to preload. |
Return:
Promise |