MemoryTableclass

new MemoryTable<I, T>(collection: Collection<string, I, T>)
ParamType
collectionCollection<string, I, T>
Collection this table holds the items of. required
Return
MemoryTable<I, T>
In-memory table holding the items of a single collection for a MemoryDBProvider.
PropertyType
.nextunknown
Deferred sequence that resolves on every change to this table. Defaults to new DeferredSequence() readonly
.collectionCollection<string, I, T>
Collection this table stores the items of. required readonly

In-memory table holding the items of a single collection for a MemoryDBProvider.

  • Keys items by id in a Map, preserving the exact object instance passed in.
  • Exposes a next DeferredSequence that resolves on every change, powering the live *Sequence subscriptions.

Examples

const table = provider.getTable(users);
 table.setItem(123, { name: "Dave" });

Methods

Go

MemoryTable.getItem()method

Get an item by its id, or undefined if it doesn't exist.

getItem(id: I): OptionalItem<I, T>
Go

MemoryTable.getItemSequence()method

Subscribe to all changes for this item key.

getItemSequence(id: I): AsyncIterable<OptionalItem<I, T>>
Go

MemoryTable.generateUniqueID()method

Generate a unique id for a new item in this table.

generateUniqueID(): I
Go

MemoryTable.addItem()method

Add a new item with a freshly generated unique id.

addItem(data: T): I
Go

MemoryTable.setItem()method

Set (insert or overwrite) an item by its id.

setItem(id: I, data: Item<I, T> | T): void
Go

MemoryTable.setItemSequence()method

Mirror an async sequence of item values into this table, passing each value through.

setItemSequence(id: I, sequence: AsyncIterable<OptionalItem<I, T>>): AsyncIterable<OptionalItem<I, T>>
Go

MemoryTable.updateItem()method

Apply partial updates to an existing item by its id.

updateItem(id: I, updates: Updates<Item<I, T>>): void
Go

MemoryTable.deleteItem()method

Delete an item by its id.

deleteItem(id: I): void
Go

MemoryTable.countQuery()method

Count the items in this table matching an optional query.

countQuery(query?: Query<Item<I, T>>): number
Go

MemoryTable.getQuery()method

Get the items in this table matching an optional query.

getQuery(query?: Query<Item<I, T>>): Items<I, T>
Go

MemoryTable.getQuerySequence()method

Subscribe to the live result of a query.

getQuerySequence(query?: Query<Item<I, T>>): AsyncIterable<Items<I, T>>
Go

MemoryTable.setQuery()method

Set (overwrite) the data for every item matching a query.

setQuery(query: Query<Item<I, T>>, data: T): void
Go

MemoryTable.updateQuery()method

Apply partial updates to every item matching a query.

updateQuery(query: Query<Item<I, T>>, updates: Updates<T>): void
Go

MemoryTable.deleteQuery()method

deleteQuery(query: Query<Item<I, T>>): void
Go

MemoryTable.setItems()method

setItems(items: Items<I, T>): void
Go

MemoryTable.setItemsSequence()method

setItemsSequence(sequence: AsyncIterable<Items<I, T>>): AsyncIterable<Items<I, T>>