Skip to main content

MemoryIndexedKeyValueUnifiedStorage

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:88

Unified storage wrapper that can be used on top of a simple key-value storage, this should only ever be used for a single-user swap databases (e.g. to be used on the client-side), because:

  • in-memory indexes are used (which can get out of hand for large datasets & don't support multi-process access)
  • uses a single write queue, meaning even concurrent writes are always processed sequentially

Extended by

Implements

Constructors

Constructor

new MemoryIndexedKeyValueUnifiedStorage(storageBackend, options?): MemoryIndexedKeyValueUnifiedStorage;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:108

Creates a new MemoryIndexedKeyValueUnifiedStorage instance

Parameters

ParameterTypeDescription
storageBackendIKeyValueStorage<boolean>The underlying key-value storage backend
options?MemoryIndexedKeyValueUnifiedStorageOptionsConfiguration options

Returns

MemoryIndexedKeyValueUnifiedStorage

Properties

compositeIndexes?

optional compositeIndexes: UnifiedStorageCompositeIndexes;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:92


compositeIndexesMaps?

optional compositeIndexesMaps: object;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:99

Index Signature

[compositeIndexIdentifier: string]: Map<string, Set<string>>

indexes?

optional indexes: UnifiedStorageIndexes;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:91


indexesMaps?

optional indexesMaps: object;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:98

Index Signature

[indexField: string]: Map<any, Set<string>>

options

options: object;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:94

allowQueryWithoutIndexes

allowQueryWithoutIndexes: boolean;

maxBatchItems

maxBatchItems: number;

storageBackend

storageBackend: IKeyValueStorage<boolean>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:90


writeQueue

writeQueue: PromiseQueue;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:101

Methods

init()

init(indexes, compositeIndexes): Promise<void>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:319

Initializes the storage with given indexes and composite indexes

Parameters

ParameterTypeDescription
indexesUnifiedStorageIndexes
compositeIndexesUnifiedStorageCompositeIndexes

Returns

Promise<void>

Implementation of

IUnifiedStorage.init


query()

query(params): Promise<any[]>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:362

Params are specified in the following way:

  • [[condition1, condition2]] - returns all rows where condition1 AND condition2 is met
  • [[condition1], [condition2]] - returns all rows where condition1 OR condition2 is met
  • [[condition1, condition2], [condition3]] - returns all rows where (condition1 AND condition2) OR condition3 is met

You can also add an optional _meta field in the returned unified storage object which gets attached to that returned object and will be present for subsequent saves and removal of this object, if you specify the _meta field here, you need to explicitly handle it in the all the saving and remove functions and not simply serialize it into the storage

Parameters

ParameterTypeDescription
paramsQueryParams[][]

Returns

Promise<any[]>

Implementation of

IUnifiedStorage.query


querySingle()

querySingle(params): Promise<any[]>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:380

Queries storage with a single set of AND conditions

Parameters

ParameterTypeDescription
paramsQueryParams[]Array of conditions that must all be met

Returns

Promise<any[]>

Array of matching objects


remove()

remove(value): Promise<void>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:557

Removes an object from storage

If the object contains a _meta field, this will be also present in the to-be-removed value, to mutate the _meta field of the object that is saved, you can mutate the _meta field directly on the passed value, which then gets reflected automatically in the existing object. The mutated _meta field is copied even if the function throws, hence the implementations must be careful with setting the _meta field on the still in-flight requests that might fail.

Parameters

ParameterTypeDescription
valueanyObject to remove (must have an id property)

Returns

Promise<void>

Implementation of

IUnifiedStorage.remove


removeAll()

removeAll(_values): Promise<void>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:578

Removes multiple objects from storage in a batch operation

If the objects contain a _meta field, this will be also present in the to-be-removed values, to mutate the _meta field of the objects that are saved, you can mutate the _meta field directly on the passed values, which then gets reflected automatically in the existing objects. The mutated _meta field is copied even if the function throws, hence the implementations must be careful with setting the _meta field on the still in-flight requests that might fail.

Parameters

ParameterTypeDescription
_valuesany[]Array of objects to remove

Returns

Promise<void>

Implementation of

IUnifiedStorage.removeAll


save()

save(value): Promise<void>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:472

Saves an object to storage, updating indexes as needed

If the object contains a _meta field, this will be also present in the to-be-saved value, to mutate the _meta field of the object that is saved, you can mutate the _meta field directly on the passed value, which then gets reflected automatically in the existing object. The mutated _meta field is copied even if the function throws, hence the implementations must be careful with setting the _meta field on the still in-flight requests that might fail.

Parameters

ParameterTypeDescription
valueanyObject to save (must have an id property)

Returns

Promise<void>

Implementation of

IUnifiedStorage.save


saveAll()

saveAll(_values): Promise<void>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:496

Saves multiple objects to storage in a batch operation

If the objects contain a _meta field, this will be also present in the to-be-saved values, to mutate the _meta field of the objects that are saved, you can mutate the _meta field directly on the passed values, which then gets reflected automatically in the existing objects. The mutated _meta field is copied even if the function throws, hence the implementations must be careful with setting the _meta field on the still in-flight requests that might fail.

Parameters

ParameterTypeDescription
_valuesany[]Array of objects to save

Returns

Promise<void>

Implementation of

IUnifiedStorage.saveAll


_get()

protected _get(key): any;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:117

Parameters

ParameterType
keystring

Returns

any


_getAll()

protected _getAll(keys): any[] | Promise<any[]>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:126

Parameters

ParameterType
keysstring[]

Returns

any[] | Promise<any[]>


_getAllSequential()

protected _getAllSequential(keys): Promise<any[]>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:218

Parameters

ParameterType
keysstring[]

Returns

Promise<any[]>


_removeAll()

protected _removeAll(values): void | Promise<void>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:183

Parameters

ParameterType
valuesobject[]

Returns

void | Promise<void>


_removeIndex()

protected _removeIndex(
indexMap,
indexValue,
obj): void;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:241

Parameters

ParameterType
indexMapMap<any, Set<string>>
indexValueany
objany

Returns

void


_removeObjectIndexes()

protected _removeObjectIndexes(obj): void;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:273

Parameters

ParameterType
objany

Returns

void


_saveIndex()

protected _saveIndex(
indexMap,
indexValue,
obj): void;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:235

Parameters

ParameterType
indexMapMap<any, Set<string>>
indexValueany
objany

Returns

void


_saveObjectIndexes()

protected _saveObjectIndexes(obj): void;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:254

Parameters

ParameterType
objany

Returns

void


_set()

protected _set(key, value): void | Promise<void>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:141

Parameters

ParameterType
keystring
valueany

Returns

void | Promise<void>


_setAll()

protected _setAll(values): void | Promise<void>;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:145

Parameters

ParameterType
valuesobject[]

Returns

void | Promise<void>


_updateIndex()

protected _updateIndex(
indexMap,
indexOldValue,
indexNewValue,
obj): void;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:249

Parameters

ParameterType
indexMapMap<any, Set<string>>
indexOldValueany
indexNewValueany
objany

Returns

void


_updateObjectIndexes()

protected _updateObjectIndexes(obj, existingValue): void;

Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:292

Parameters

ParameterType
objany
existingValueany

Returns

void