Add an API for deleting key ranges to Skv
Categories
(Core :: SQLite and Embedded Database Bindings, enhancement, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox132 | --- | fixed |
People
(Reporter: lina, Assigned: lina)
References
(Blocks 2 open bugs)
Details
Attachments
(1 file)
Extensions would like to have an API to delete all keys that fall within a range. Currently, they need to enumerate() all key-value pairs in a range, then call delete for each one. This is super awkward to write, and super inefficient for us, too—each of those delete() calls is a separate SQLite transaction.
Let's offer a better way to do this:
await db.deleteRange(
fromKey, /* Inclusive. */
toKey /* Exclusive. */
);
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 1•1 year ago
|
||
I was thinking a bit more about this, and it occurred to me: if we wanted to match enumerate()'s semantics (both bounds are optional, and omitting either bound extends the range to the first or last key), deleteRange() would be equivalent to clear(). I considered overloading clear() with optional fromKey and toKey arguments, but keeping them as separate methods actually feels cleaner to me [1].
I also thought about overloading delete() to take an optional second argument, but then it would behave inconsistently with enumerate(), where omitting the upper bound extends the range to the end of the database. We definitely wouldn't want to do that for delete(), though, because it would change the meaning of db.delete("foo") to "delete foo and everything that comes after it."
[1]: It feels a bit like isEmpty(): while you could write it as (await db.count()) == 0, await db.isEmpty() reads a bit better.
| Assignee | ||
Comment 2•1 year ago
|
||
Comment 4•1 year ago
|
||
| bugherder | ||
Description
•