Skip to content

feat(db): support $unset operator in update operations#8

Open
gowthamrdyy wants to merge 13 commits into
arpitkhandelwal12:mainfrom
gowthamrdyy:fix/unset-operator
Open

feat(db): support $unset operator in update operations#8
gowthamrdyy wants to merge 13 commits into
arpitkhandelwal12:mainfrom
gowthamrdyy:fix/unset-operator

Conversation

@gowthamrdyy
Copy link
Copy Markdown

Summary

Adds support for the $unset operator in the update() method of db-client.ts, allowing callers to remove specific fields from a document without replacing the entire object.

Contributing on behalf of GSSoC'26 🚀


Problem

Currently, ZerithDB's update() only supports field-value replacement via $set. There is no way to remove a field from a stored document. This is a common requirement — e.g., clearing a user's refreshToken or removing an optional metadata field.

Solution

  • Extended the UpdateFilter<T> type to accept an optional $unset key whose value is a Partial<Record<keyof T, 1>> (mirroring the MongoDB $unset convention).
  • In update(), after applying $set mutations, any keys present in $unset are deleted from the document object before the final dexie.table.put() call.
  • Added a changeset entry under .changeset/.

Files Changed

File Change
packages/db/src/db-client.ts Implemented $unset handling in update()
tests/unit/db.test.ts Added unit test: verify field is removed after $unset
.changeset/support-unset-operator.md Changeset for minor release

Test

pnpm vitest run tests/unit/db.test.ts

All existing tests pass; the new $unset test case verifies the field is correctly removed.

Checklist

  • Follows existing code style
  • Unit tests added and passing
  • Changeset file included
  • No breaking changes (purely additive)

Copilot AI review requested due to automatic review settings May 29, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants