TinyBase logoTinyBase β

getStorage

The getStorage method returns a reference to the storage that the Store is being persisted to.

getStorage(): DurableObjectStorage
returnsDurableObjectStorage

The reference to the storage.

Example

This example creates a Persister object against a newly-created Store (within the createPersister method of a WsServerDurableObject instance) and then gets the storage reference back out again.

import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
import {createDurableObjectStoragePersister} from 'tinybase/persisters/persister-durable-object-storage';
import {createMergeableStore} from 'tinybase';

export class MyDurableObject extends WsServerDurableObject {
  createPersister() {
    const store = createMergeableStore();
    const persister = createDurableObjectStoragePersister(
      store,
      this.ctx.storage,
    );
    console.log(persister.getStorage() == this.ctx.storage);
    // -> true

    return persister;
  }
}

Since

v5.4.0