feat(db): support $unset operator in update operations#8
Open
gowthamrdyy wants to merge 13 commits into
Open
Conversation
feat: add PR welcome bot
test: trigger welcome bot
Delete .github/ISSUE_TEMPLATE/bug_report.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for the
$unsetoperator in theupdate()method ofdb-client.ts, allowing callers to remove specific fields from a document without replacing the entire object.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'srefreshTokenor removing an optional metadata field.Solution
UpdateFilter<T>type to accept an optional$unsetkey whose value is aPartial<Record<keyof T, 1>>(mirroring the MongoDB$unsetconvention).update(), after applying$setmutations, any keys present in$unsetare deleted from the document object before the finaldexie.table.put()call..changeset/.Files Changed
packages/db/src/db-client.ts$unsethandling inupdate()tests/unit/db.test.ts$unset.changeset/support-unset-operator.mdTest
All existing tests pass; the new
$unsettest case verifies the field is correctly removed.Checklist