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
| Parameter | Type | Description |
|---|---|---|
storageBackend | IKeyValueStorage<boolean> | The underlying key-value storage backend |
options? | MemoryIndexedKeyValueUnifiedStorageOptions | Configuration 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
| Parameter | Type | Description |
|---|---|---|
indexes | UnifiedStorageIndexes | |
compositeIndexes | UnifiedStorageCompositeIndexes |
Returns
Promise<void>
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
params | QueryParams[][] |
Returns
Promise<any[]>
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
params | QueryParams[] | 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
| Parameter | Type | Description |
|---|---|---|
value | any | Object to remove (must have an id property) |
Returns
Promise<void>
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
_values | any[] | Array of objects to remove |
Returns
Promise<void>
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
value | any | Object to save (must have an id property) |
Returns
Promise<void>
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
_values | any[] | Array of objects to save |
Returns
Promise<void>
Implementation of
_get()
protected _get(key): any;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:117
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
any
_getAll()
protected _getAll(keys): any[] | Promise<any[]>;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:126
Parameters
| Parameter | Type |
|---|---|
keys | string[] |
Returns
any[] | Promise<any[]>
_getAllSequential()
protected _getAllSequential(keys): Promise<any[]>;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:218
Parameters
| Parameter | Type |
|---|---|
keys | string[] |
Returns
Promise<any[]>
_removeAll()
protected _removeAll(values): void | Promise<void>;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:183
Parameters
| Parameter | Type |
|---|---|
values | object[] |
Returns
void | Promise<void>
_removeIndex()
protected _removeIndex(
indexMap,
indexValue,
obj): void;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:241
Parameters
| Parameter | Type |
|---|---|
indexMap | Map<any, Set<string>> |
indexValue | any |
obj | any |
Returns
void
_removeObjectIndexes()
protected _removeObjectIndexes(obj): void;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:273
Parameters
| Parameter | Type |
|---|---|
obj | any |
Returns
void
_saveIndex()
protected _saveIndex(
indexMap,
indexValue,
obj): void;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:235
Parameters
| Parameter | Type |
|---|---|
indexMap | Map<any, Set<string>> |
indexValue | any |
obj | any |
Returns
void
_saveObjectIndexes()
protected _saveObjectIndexes(obj): void;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:254
Parameters
| Parameter | Type |
|---|---|
obj | any |
Returns
void
_set()
protected _set(key, value): void | Promise<void>;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:141
Parameters
| Parameter | Type |
|---|---|
key | string |
value | any |
Returns
void | Promise<void>
_setAll()
protected _setAll(values): void | Promise<void>;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:145
Parameters
| Parameter | Type |
|---|---|
values | object[] |
Returns
void | Promise<void>
_updateIndex()
protected _updateIndex(
indexMap,
indexOldValue,
indexNewValue,
obj): void;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:249
Parameters
| Parameter | Type |
|---|---|
indexMap | Map<any, Set<string>> |
indexOldValue | any |
indexNewValue | any |
obj | any |
Returns
void
_updateObjectIndexes()
protected _updateObjectIndexes(obj, existingValue): void;
Defined in: atomiq-storage-memory-indexed-kv/src/MemoryIndexedKeyValueUnifiedStorage.ts:292
Parameters
| Parameter | Type |
|---|---|
obj | any |
existingValue | any |
Returns
void