Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvStorage range options #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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