denoland / denoland/deploy_feedback

[KV Feedback]: Wildcards in `list` selector

Open
#415 0 comments 5 reactions 0 assignees View on GitHub
kv
Dominant language
No language data
Stars
79
Forks
5
PR merge metrics
No merged PRs in 30d

Description

### 🔍

- [X] Did you search for existing issues?

### Type of feedback

Feature request

### Description

It would be great if we could select down into a specific nested keyspace within a whole parent keyspace in `list` with something like wildcards.

Currently, we must fully qualify the selector down to the last keyspace using the `prefix` and/or `start` & `end` options.

A key in Deno KV is similar to a file path on disk. Wildcards and globs have proven themselves quite useful and should be similarly useful in Deno KV. In the file path analogy, we can currently select files from a single folder, but can't select the same files from multiple folders. We can only select the whole parent folder and filter out what we don't want.

One use case is to limit the list to specific children in a large nested keyspace.

A workaround is to list the whole parent keyspace and filter out the desired entries manually. The workaround isn't ideal, because it's more error prone, less efficient, and makes pagination harder.

### Steps to reproduce (if applicable)

Example

```js
const db = await Deno.openKv(":memory:");

await db
.atomic()
.set(["users", "1", "name"], "foo") // <-- we only want that in the list
.set(["users", "1", "age"], 42)
// ... more
.set(["users", "2", "name"], "bar") // <-- we only want that in the list
.set(["users", "2", "age"], 12)
// ... more
.set(["users", "3", "name"], "buz") // <-- we only want that in the list
.set(["users", "3", "age"], 21)
// ... more
.set(["users", "4", "name"], "baz") // <-- we only want that in the list
.set(["users", "4", "age"], 69)
// ... more
.commit();

// how to select here?
const entries = db.list({ ... });
```

### Expected behavior (if applicable)

An option to specify wildcard intermediate ranges, for example using a `*`

```js
const entries = db.list({ prefix: ["users", "*", "name"] });

for await (const { key, value } of entries) {
// ... do stuff
}
```

### Possible solution (if applicable)

_No response_

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.