Skip to content

Commit

Permalink
kvStorage range options
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeuchi committed May 25, 2023
1 parent b817e82 commit 1ccd5db
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion warp-academy-docs/docs/sdk/advanced/kv-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1ccd5db

Please sign in to comment.