Home Reference Source Test
public class | source

Snapshot

Extends:

Transaction → Snapshot

Snapshots present a read-only version of a specific state. As long as a snapshot is not aborted, the object store will reflect changes to the state in form of the differences to the originating state in the snapshot. This makes efficient queries against a fixed state possible without blocking other transactions to commit.

Constructor Summary

Protected Constructor
protected

constructor(objectStore: ObjectStore, backend: IObjectStore)

This constructor should only be called by an ObjectStore object.

Method Summary

Public Methods
public

abort(tx: *): Promise<boolean>

Aborts a snapshot and stops updating its diff.

public

close(): Promise

Alias for abort.

public

async commit(tx: *)

Unsupported operation for snapshots.

public

async put(key: *, value: *): Promise

Unsupported operation for snapshots.

public

putSync(key: *, value: *)

Unsupported operation for snapshots.

public

async remove(key: *): Promise

Unsupported operation for snapshots.

public

removeSync(key: *)

Unsupported operation for snapshots.

public

Unsupported operation for snapshots.

public

Unsupported operation for snapshots.

public

Unsupported operation for snapshots.

public

async truncate(): Promise

Unsupported operation for snapshots.

public

Unsupported operation for snapshots.

Protected Methods
protected

async _apply(tx: Transaction): Promise

Internally applies a transaction to the snapshot state.

protected

async _commitBackend(): Promise<boolean>

Commits the transaction to the backend.

protected

async _commitInternal(tx: Transaction): Promise

Unsupported operation for snapshots.

protected

_isCommittable(tx: Transaction): boolean

Unsupported operation for snapshots.

protected

A specific set of changes can be assumed to be already applied by providing a Transaction or Snapshot.

Inherited Summary

From class Transaction
public get

connected: boolean

public get
public get

id: number

public get

indices: Map<string, IIndex>

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

async count(query: KeyRange): Promise<number>

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

index(indexName: string): IIndex

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

async keys(query: Query | KeyRange): Promise<Set<string>>

Returns a promise of a set of keys fulfilling the given query.

public

async maxKey(query: KeyRange): Promise<string>

Returns a promise of the key being maximal for the given range.

public

async maxValue(query: KeyRange): Promise<*>

Returns a promise of the object whose primary key is maximal for the given range.

public

async minKey(query: KeyRange): Promise<string>

Returns a promise of the key being minimal for the given range.

public

async minValue(query: KeyRange): Promise<*>

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

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

async values(query: Query | KeyRange): Promise<Array<*>>

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

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, backend: IObjectStore) source

This constructor should only be called by an ObjectStore object.

Override:

Transaction#constructor

Params:

NameTypeAttributeDescription
objectStore ObjectStore

The object store this transaction belongs to.

backend IObjectStore

The backend this transaction is based on.

Public Methods

public abort(tx: *): Promise<boolean> source

Aborts a snapshot and stops updating its diff.

Override:

Transaction#abort

Params:

NameTypeAttributeDescription
tx *
  • optional

Return:

Promise<boolean>

A promise of the success outcome.

public close(): Promise source

Alias for abort.

Override:

Transaction#close

Return:

Promise

The promise resolves after successful abortion of the transaction.

public async commit(tx: *) source

Unsupported operation for snapshots.

Override:

Transaction#commit

Params:

NameTypeAttributeDescription
tx *

Throw:

*

public async put(key: *, value: *): Promise source

Unsupported operation for snapshots.

Override:

Transaction#put

Params:

NameTypeAttributeDescription
key *
value *

Return:

Promise

public putSync(key: *, value: *) source

Unsupported operation for snapshots.

Override:

Transaction#putSync

Params:

NameTypeAttributeDescription
key *
value *

public async remove(key: *): Promise source

Unsupported operation for snapshots.

Override:

Transaction#remove

Params:

NameTypeAttributeDescription
key *

Return:

Promise

public removeSync(key: *) source

Unsupported operation for snapshots.

Override:

Transaction#removeSync

Params:

NameTypeAttributeDescription
key *

public snapshot() source

Unsupported operation for snapshots.

Override:

Transaction#snapshot

public synchronousTransaction() source

Unsupported operation for snapshots.

Override:

Transaction#synchronousTransaction

public transaction() source

Unsupported operation for snapshots.

Override:

Transaction#transaction

public async truncate(): Promise source

Unsupported operation for snapshots.

Override:

Transaction#truncate

Return:

Promise

public truncateSync() source

Unsupported operation for snapshots.

Override:

Transaction#truncateSync

Protected Methods

protected async _apply(tx: Transaction): Promise source

Internally applies a transaction to the snapshot state. In contrast to transactions, this tries to reflect the old state in the snapshot.

Override:

Transaction#_apply

Params:

NameTypeAttributeDescription
tx Transaction

The transaction to apply.

Return:

Promise

The promise resolves after applying the transaction.

protected async _commitBackend(): Promise<boolean> source

Commits the transaction to the backend.

Override:

Transaction#_commitBackend

Return:

Promise<boolean>

A promise of the success outcome.

protected async _commitInternal(tx: Transaction): Promise source

Unsupported operation for snapshots.

Override:

Transaction#_commitInternal

Params:

NameTypeAttributeDescription
tx Transaction

The transaction to be applied.

Return:

Promise

A promise that resolves upon successful application of the transaction.

protected _isCommittable(tx: Transaction): boolean source

Unsupported operation for snapshots.

Override:

Transaction#_isCommittable

Params:

NameTypeAttributeDescription
tx Transaction
  • optional

The transaction to be applied, if not given checks for the this transaction.

Return:

boolean

Whether a commit will be successful.

protected inherit(tx: Transaction): * source

A specific set of changes can be assumed to be already applied by providing a Transaction or Snapshot. These differences will be inherited while the backend of the snapshot remains the current state. This is useful, if we have a transaction/snapshot to a previous state, which we do not want to commit. Then, we can still base our snapshot on this earlier state although the current backend is already ahead.

Params:

NameTypeAttributeDescription
tx Transaction

A transaction or snapshot containing changes that have already been applied.

Return:

*