Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for comparator of null values with equals and notEquals #310

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

huuyafwww
Copy link

Hi, thank you for developing a great library.
I would like to compare null with equals and notEquals in the Where clause, but it seems that it is not currently supported.
I see the same reported in issue #228.
I wanted this feature and implemented it, what do you think?

return compareDates(expected, actual) === 0
return compareDates(expected as unknown as Date, actual as unknown as Date) === 0
Copy link
Author

@huuyafwww huuyafwww Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added null to equals in DateQuery.
This would cause people to guess that a null value is coming here.
However, since null values cannot be retrieved by getComparatorsForValue, the function for comparison cannot be used.
The null value is now handled before the call.
So the null value will not appear here,
The unknown type is used to overwrite the Date to suppress type errors.

Comment on lines +41 to +53
if (comparatorName === "equals" && expectedValue === null) {
return actualValue === null
}

if (comparatorName === "notEquals" && expectedValue === null) {
return actualValue !== null
}

// If an entity doesn't have any value for the property
// is being queried for, treat it as non-matching.
if (actualValue == null) {
return false
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed control when actualValue is null.
Addes comparison if comparatorName is equals or notEquals and expectedValue is null.
This control prevents null values from entering getComparatorsForValue.

@huuyafwww huuyafwww force-pushed the feature/expect_equal_null branch from 75f3794 to da06da0 Compare December 24, 2024 14:45
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.

1 participant