nanokv
    Preparing search index...

    Interface KvApi<E, Q>

    interface KvApi<
        E extends KvEntry = KvEntry,
        Q extends KvQueueEntry = KvQueueEntry,
    > {
        atomic(): AtomicOperation<E, Q>;
        delete(
            key: E["key"],
            signal?: AbortSignal,
        ): Promise<KvCommitResult | KvCommitError>;
        get<K extends KvKey>(
            key: K,
            signal?: AbortSignal,
        ): Promise<KvPairMaybe<SelectKvPair<E, K>>>;
        getMany<Ks extends [] | E["key"][]>(
            keys: Ks,
            signal?: AbortSignal,
        ): Promise<
            {
                [N in string
                | number
                | symbol]: KvPairMaybe<SelectKvPair<E, Ks[N<N>]>>
            },
        >;
        list<K extends KvKey, P extends KvKey | []>(
            selector: KvListSelector<K, P>,
            options?: KvListOptions,
        ): NanoStream<SelectKvPairByPrefix<E, P>>;
        listenQueue<Ks extends [] | Q["key"][]>(
            ...keys: Ks,
        ): NanoStream<
            { [N in string
            | number
            | symbol]: SelectKvPair<Q, Ks[N<N>]> }[keyof Ks & number],
        >;
        set<K extends KvKey>(
            key: K,
            value: ValueFotKvPair<E, K>,
            options?: { expireIn?: number; signal?: AbortSignal },
        ): Promise<KvCommitResult | KvCommitError>;
        subspace<P extends KvKey | []>(
            prefix: P,
        ): KvApi<RemoveKvPairPrefix<E, P>, RemoveKvPairPrefix<Q, P>>;
        watch<Ks extends [] | E["key"][]>(
            keys: Ks,
        ): NanoStream<
            {
                [N in string
                | number
                | symbol]: KvPairMaybe<SelectKvPair<E, Ks[N<N>]>>
            },
        >;
    }

    Type Parameters

    Implemented by

    Index

    Methods

    • Delete the value for the given key from the database. If no value exists for the key, this operation is a no-op.

      Parameters

      • key: E["key"]

        The key to delete.

      • Optionalsignal: AbortSignal

      Returns Promise<KvCommitResult | KvCommitError>

      A promise resolving to an object containing a boolean indicating whether the operation was successful, and the versionstamp of the deleted key-value entry.

    • Retrieve the value and versionstamp for the given key from the database in the form of a KvEntryMaybe. If no value exists for the key, the returned entry will have a null value and versionstamp.

      Type Parameters

      Parameters

      • key: K
      • Optionalsignal: AbortSignal

      Returns Promise<KvPairMaybe<SelectKvPair<E, K>>>

    • Retrieve multiple values and versionstamp from the database in the form of an array of KvEntryMaybe objects. The returned array will have the same length as the keys array, and the entries will be in the same order as the keys. If no value exists for a given key, the returned entry will have a null value and versionstamp.

      Type Parameters

      • Ks extends [] | E["key"][]

      Parameters

      • keys: Ks
      • Optionalsignal: AbortSignal

      Returns Promise<
          {
              [N in string
              | number
              | symbol]: KvPairMaybe<SelectKvPair<E, Ks[N<N>]>>
          },
      >

    • Retrieve a list of keys in the database. The returned list is a NanoStream which can be used to iterate over the entries in the database. Each list operation must specify a selector which is used to specify the range of keys to return. The selector can either be a prefix selector, or a range selector:

      • A prefix selector selects all keys that start with the given prefix of key parts. For example, the selector ["users"] will select all keys that start with the prefix ["users"], such as ["users", "alice"] and ["users", "bob"]. Note that you can not partially match a key part, so the selector ["users", "a"] will not match the key ["users", "alice"]. A prefix selector may specify a start key that is used to skip over keys that are lexicographically less than the start key.
      • A range selector selects all keys that are lexicographically between the given start and end keys (including the start, and excluding the end). For example, the selector ["users", "a"], ["users", "n"] will select all keys that start with the prefix ["users"] and have a second key part that is lexicographically between a and n, such as ["users", "alice"], ["users", "bob"], and ["users", "mike"], but not ["users", "noa"] or ["users", "zoe"].

      Type Parameters

      Parameters

      Returns NanoStream<SelectKvPairByPrefix<E, P>>

      The options argument can be used to specify additional options for the list operation. See the documentation for KvListOptions for more information.

    • Listen for queue values to be delivered from the database queue, which were enqueued with AtomicOperation.enqueue, you can spcify which keys to listen to.

      You need to use AtomicOperation.dequeue to dequeue values from the queue after you have received and processed them, or you will get duplicates in next time you call this method.

      Type Parameters

      • Ks extends [] | Q["key"][]

      Parameters

      • ...keys: Ks

        The keys to listen to.

      Returns NanoStream<
          { [N in string
          | number
          | symbol]: SelectKvPair<Q, Ks[N<N>]> }[keyof Ks & number],
      >

      A readable stream of key-value pairs.

    • Set the value for the given key in the database. If a value already exists for the key, it will be overwritten.

      Optionally an expireIn option can be specified to set a time-to-live (TTL) for the key. The TTL is specified in milliseconds, and the key will be deleted from the database at earliest after the specified number of milliseconds have elapsed. Once the specified duration has passed, the key may still be visible for some additional time. If the expireIn option is not specified, the key will not expire.

      Type Parameters

      Parameters

      • key: K

        The key to set.

      • value: ValueFotKvPair<E, K>

        The value to set.

      • Optionaloptions: { expireIn?: number; signal?: AbortSignal }

        Options for the set operation.

        • OptionalexpireIn?: number

          The number of milliseconds after which the key-value entry will expire.

        • Optionalsignal?: AbortSignal

      Returns Promise<KvCommitResult | KvCommitError>

    • Watch for changes to the given keys in the database. The returned stream is a NanoStream that emits a new value whenever any of the watched keys change their versionstamp. The emitted value is an array of KvEntryMaybe objects, with the same length and order as the keys array. If no value exists for a given key, the returned entry will have a null value and versionstamp.

      The returned stream does not return every single intermediate state of the watched keys, but rather only keeps you up to date with the latest state of the keys. This means that if a key is modified multiple times quickly, you may not receive a notification for every single change, but rather only the latest state of the key.

      Type Parameters

      • Ks extends [] | E["key"][]

      Parameters

      • keys: Ks

        An array of keys to watch for changes.

      Returns NanoStream<
          {
              [N in string
              | number
              | symbol]: KvPairMaybe<SelectKvPair<E, Ks[N<N>]>>
          },
      >