Skip to content

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?

export const dateComparators: QueryToComparator<DateQuery> = {
equals(expected, actual) {
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.

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