Skip to content

Conversation

MAST1999
Copy link
Contributor

I tried not to change too many things.
If something doesn't look right, or we need some tests that are missing, I'm happy to try and make those changes.

BTW, I tried adding date support to eq as well but, I couldn't figure out a way to make it work. I made a change in packages/db/src/query/compiler/evaluators.ts and, after checking it, I can see that it's converting date to number and comparing it correctly.

After I added a test to confirm it, the test kept failing :(
So if it's something that needs more work I can take it out and follow up later.

Feel free to make any necessary changes :)

Copy link

changeset-bot bot commented Aug 20, 2025

⚠️ No Changeset found

Latest commit: 6bab62a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@MAST1999
Copy link
Contributor Author

I also checked with lt, gt and the whole family and I think it's working. Though I recommend someone double check.

Copy link

pkg-pr-new bot commented Aug 20, 2025

More templates

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@428

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@428

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@428

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@428

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@428

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@428

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@428

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@428

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@428

commit: 6bab62a

@MAST1999
Copy link
Contributor Author

OK, managed to make it work.

The PR is ready for review.

@samwillis
Copy link
Collaborator

Hey @MAST1999 just letting you know this hasn't dropped off my radar. I've asked @kevin-dp to review it as he worked on the groupBy operator recently.

@samwillis samwillis requested a review from kevin-dp August 26, 2025 11:09
Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

I left some comments with regard to the code changes. I believe the changes here are indeed enough for Dates to work with aggregation functions.

On the longer term, i'm not sure if this is the approach we want to take. Turning the value into a number with Number seems brittle and works for Dates but may not work for other data types.

We may want a bigger refactor such that min and max work on any data type that has a total ordering. This means we need a custom comparator function as well as a bottom value and a top value for that specific data type. For example, for numbers the comparator is <, the bottom value is -Inf and the top value is +Inf.

minValue = value
}
}
return minValue === Number.POSITIVE_INFINITY ? 0 : minValue
return minValue === Number.POSITIVE_INFINITY ? (0 as V) : minValue
Copy link
Contributor

Choose a reason for hiding this comment

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

let's type let minValue: Number | V such that we don't need the typecast here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue I have here is that I need the returned type to be the type passed in. So if they pass in a Date, I want the return type to be Date as well. That's why I ended up casting as V.

I couldn't figure out what's the best way to handle this minValue and maxValue situation since if the user returns a number we can return 0 as a valid response, but what should we do if they pass a date? Do we still return a 0, because then the response type would always be number | Date which is annoying?

@samwillis
Copy link
Collaborator

I think in future a larger refactor may be good to support a wider range of types in min/max, but in the sort term this looks like a good route to getting them working for Date. Numbers and dates are by far the most common use for these functions, so lets concentrate on getting that in soon.

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