Closed Bug 1919674 Opened 11 months ago Closed 11 months ago

Add an API for deleting key ranges to Skv

Categories

(Core :: SQLite and Embedded Database Bindings, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
132 Branch
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. */
);
Blocks: skv
See Also: → 1919676

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: nobody → lina
Status: NEW → ASSIGNED
Blocks: 1919530
Pushed by lbutler@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1dc5ccccdeae Introduce `nsIKeyValueDatabase.deleteRange()`. r=robwu,nanj
Status: ASSIGNED → RESOLVED
Closed: 11 months ago
Resolution: --- → FIXED
Target Milestone: --- → 132 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: