A datastore that can combine multiple stores inside various key prefixes

Hierarchy (view full)

Constructors

Properties

mounts: {
    datastore: Datastore<{}, {}, {}, {}, {}, {}, {}, {}, {}, {}>;
    prefix: Key;
}[]

Type declaration

  • datastore: Datastore<{}, {}, {}, {}, {}, {}, {}, {}, {}, {}>
  • prefix: Key

Methods

  • Lookup the matching datastore for the given key

    Parameters

    Returns undefined | {
        datastore: Datastore<{}, {}, {}, {}, {}, {}, {}, {}, {}, {}>;
        mountpoint: Key;
    }

  • This will return an object with which you can chain multiple operations together, with them only being executed on calling commit.

    Returns Batch<{}>

    Example

    const b = store.batch()

    for (let i = 0; i < 100; i++) {
    b.put(new Key(`hello${i}`), new TextEncoder('utf8').encode(`hello world ${i}`))
    }

    await b.commit()
    console.log('put 100 values')
  • Check for the existence of a value for the passed key

    Parameters

    Returns Promise<boolean>

    Example

    const exists = await store.has(new Key('awesome'))

    if (exists) {
    console.log('it is there')
    } else {
    console.log('it is not there')
    }
  • Query the datastore.

    Parameters

    Returns AsyncIterable<Pair>

    Example

    // retrieve __all__ key/value pairs from the store
    let list = []
    for await (const { key, value } of store.query({})) {
    list.push(value)
    }
    console.log('ALL THE VALUES', list)
  • Query the datastore.

    Parameters

    Returns AsyncIterable<Key>

    Example

    // retrieve __all__ keys from the store
    let list = []
    for await (const key of store.queryKeys({})) {
    list.push(key)
    }
    console.log('ALL THE KEYS', key)