From 1ccd5dbbd02e02547a87177b647990929cdc9b34 Mon Sep 17 00:00:00 2001 From: Tadeuchi Date: Thu, 25 May 2023 17:17:50 +0200 Subject: [PATCH] kvStorage range options --- .../docs/sdk/advanced/kv-storage.md | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/warp-academy-docs/docs/sdk/advanced/kv-storage.md b/warp-academy-docs/docs/sdk/advanced/kv-storage.md index 5ff6780..0d6efea 100644 --- a/warp-academy-docs/docs/sdk/advanced/kv-storage.md +++ b/warp-academy-docs/docs/sdk/advanced/kv-storage.md @@ -99,13 +99,31 @@ The full contract example is available here: https://github.com/warp-contracts/w #### Example of retrieving kv entries for a specified range +This is a simple example of fetching values, filtered by key prefix, in order to calculate the sum of all of them. ```js let partialSum = 0; -for await (let part of (await SmartWeave.kv.kvMap({ gte: 'pref.', lte: 'pref.\xff'})).values()) { +for await (let part of (await SmartWeave.kv.kvMap({ gte: 'pref.', lt: 'pref.\xff'})).values()) { partialSum = partialSum + parseInt(part); } ``` +Here is a full list of range options used by `SmartWeave.kv.kvMap` +```ts +/** + * Range option for fetching items from kv storage {@link SortKeyCache} + * @param gte - greater than equals + * @param lt - less than + * @param reverse - reverses the order + * @param limit - limits output elements + */ +export interface SortKeyCacheRangeOptions { + gte?: string; + lt?: string; + reverse?: boolean | undefined; + limit?: number | undefined; +} +``` + #### Example of retrieving the values via SDK ```ts const result = (await contract.getStorageValues(['voo', 'doo'])).cachedValue;