Home Reference Source Test
public class | source

InMemoryBackend

Transactions are created by calling the transaction method on an ObjectStore object. Transactions ensure read-isolation. On a given state, only one transaction can be committed successfully. Other transactions based on the same state will end up in a conflicted state if committed. Transactions opened after the successful commit of another transaction will be based on the new state and hence can be committed again.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public get

connected: boolean

public get

indices: Map<string, IIndex>

public get

tableName: string

Method Summary

Public Methods
public

async applyCombined(tx: Transaction): function(): Promise>

Returns the necessary information in order to flush a combined transaction.

public

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

public

createIndex(indexName: string, keyPath: string | Array<string>, options: IndexConfig)

public

decode(value: *, key: string): *

Method called to decode a single value.

public

deleteIndex(indexName: *, options: function(oldVersion: number, newVersion: number): boolean})

Deletes a secondary index from the object store.

public

encode(value: *): *

Method called to encode a single value.

public

get(key: string, options: RetrievalConfig): Promise<*>

public abstract

getSync(key: string, options: SyncRetrievalConfig): *

Returns the object stored under the given primary key.

public

index(indexName: string): IIndex

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

keyStream(callback: function(key: string): boolean, ascending: boolean, query: KeyRange): Promise

Iterates over the keys in a given range and direction.

public

keys(query: Query | KeyRange, limit: number): Promise<Set<string>>

public

async map(func: function(key: string, value: *)): Promise

public

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

public

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

public

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

public

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

public

async truncate(): Promise

public
public

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, limit: number): Promise<Array<*>>

Protected Methods
protected

async _apply(tx: Transaction): Promise<boolean>

Public Constructors

public constructor() source

Public Members

public get connected: boolean source

public get indices: Map<string, IIndex> source

public get tableName: string source

Public Methods

public async applyCombined(tx: Transaction): function(): Promise> source

Returns the necessary information in order to flush a combined transaction.

Params:

NameTypeAttributeDescription
tx Transaction

The transaction that should be applied to this backend.

Return:

function(): Promise>

Either the tableName if this is a native, persistent backend or a function that effectively applies the transaction to non-persistent backends.

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

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Return:

Promise<number>

public createIndex(indexName: string, keyPath: string | Array<string>, options: IndexConfig) source

Params:

NameTypeAttributeDescription
indexName string

The name of the index.

keyPath string | Array<string>
  • optional

The path to the key within the object. May be an array for multiple levels.

options IndexConfig
  • optional

An options object.

public decode(value: *, key: string): * source

Method called to decode a single value.

Params:

NameTypeAttributeDescription
value *

Value to be decoded.

key string

Key corresponding to the value.

Return:

*

The decoded value.

public deleteIndex(indexName: *, options: function(oldVersion: number, newVersion: number): boolean}) source

Deletes a secondary index from the object store.

Params:

NameTypeAttributeDescription
indexName *
options function(oldVersion: number, newVersion: number): boolean}
  • optional

public encode(value: *): * source

Method called to encode a single value.

Params:

NameTypeAttributeDescription
value *

Value to be encoded.

Return:

*

The encoded value.

public get(key: string, options: RetrievalConfig): Promise<*> source

Params:

NameTypeAttributeDescription
key string
options RetrievalConfig
  • optional

Advanced retrieval options.

Return:

Promise<*>

public abstract 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:

NameTypeAttributeDescription
key string

The primary key to look for.

options SyncRetrievalConfig
  • optional

Advanced retrieval options.

Return:

*

The object stored under the given key, or undefined if not present.

public index(indexName: string): IIndex source

Params:

NameTypeAttributeDescription
indexName string

Return:

IIndex

public isCached(key: string): boolean source

A check whether a certain key is cached.

Params:

NameTypeAttributeDescription
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.

Return:

boolean

The transaction object.

public keyStream(callback: function(key: string): boolean, ascending: boolean, query: KeyRange): Promise source

Iterates over the keys in a given range and direction. The callback is called for each primary key fulfilling the query until it returns false and stops the iteration.

Params:

NameTypeAttributeDescription
callback function(key: string): boolean

A predicate called for each key until returning false.

ascending boolean

Determines the direction of traversal.

query KeyRange

An optional KeyRange to narrow down the iteration space.

Return:

Promise

The promise resolves after all elements have been streamed.

public keys(query: Query | KeyRange, limit: number): Promise<Set<string>> source

Params:

NameTypeAttributeDescription
query Query | KeyRange
  • optional
limit number
  • optional

Return:

Promise<Set<string>>

public async map(func: function(key: string, value: *)): Promise source

Params:

NameTypeAttributeDescription
func function(key: string, value: *)

Return:

Promise

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

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Return:

Promise<string>

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

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Return:

Promise<*>

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

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Return:

Promise<string>

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

Params:

NameTypeAttributeDescription
query KeyRange
  • optional

Return:

Promise<*>

public async truncate(): Promise source

Return:

Promise

public truncateSync() source

public valueStream(callback: function(value: *, key: string): boolean, ascending: boolean, query: KeyRange): Promise source

Iterates over the keys and values in a given range and direction. The callback is called for each value and primary key fulfilling the query until it returns false and stops the iteration.

Params:

NameTypeAttributeDescription
callback function(value: *, key: string): boolean

A predicate called for each value and key until returning false.

ascending boolean

Determines the direction of traversal.

query KeyRange

An optional KeyRange to narrow down the iteration space.

Return:

Promise

The promise resolves after all elements have been streamed.

public async values(query: Query | KeyRange, limit: number): Promise<Array<*>> source

Params:

NameTypeAttributeDescription
query Query | KeyRange
  • optional
limit number
  • optional

Return:

Promise<Array<*>>

Protected Methods

protected async _apply(tx: Transaction): Promise<boolean> source

Params:

NameTypeAttributeDescription
tx Transaction

Return:

Promise<boolean>