-
Notifications
You must be signed in to change notification settings - Fork 663
Add a typescript query builder for views #3812
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
Merged
Merged
Conversation
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
joshua-spacetime
approved these changes
Dec 4, 2025
Collaborator
joshua-spacetime
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mainly reviewed the api. Improving compile-time safety will be addressed in follow up patches.
Merged
github-merge-queue bot
pushed a commit
that referenced
this pull request
Dec 16, 2025
# Description of Changes This improves the type safety a bit from #3812. The core change is that the previous version typed queries based on the typescript type, not the spacetime type. This meant that we allowed queries for incorrect tables, like a table that had the same column names and types, but had a u32 instead of a u64 somewhere. This still has an issue with allowing results from tables where the rows are reordered, which would actually be a problem, but hopefully that is not too common. # API and ABI breaking changes This is technically a breaking change, because it changes some type parameters. I don't think people should be relying on these though, so I don't think we should be worried about breaking them. This would only cause new type errors for apps that are likely to error at runtime anyway. # Expected complexity level and risk 1.5. This should be low risk, since it is just a typing change. # Testing This has some type checks in `view.test-d.ts`, and I've done some manual e2e testing.
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.
Description of Changes
This adds a way to build queries with typescript views, and it allows views to return queries (if the return type of the query is an array).
For examples and syntax, you can look at the tests in crates/bindings-typescript/tests/query.test.ts.
To play around with the syntax, you might find it easier to look in crates/bindings-typescript/src/server/view.test-d.ts.
This could still use some cleanup, and there are some places where the type safety is imperfect. I'll try to list the known limitations here:
eqfor columns that are product types, even though the query engine doesn't support it. This can be fixed later, and it would only be a breaking change for modules that have invalid queries.u16andu32).API and ABI breaking changes
This adds some new API surface, but does not break existing code.
Expected complexity level and risk
Testing
For automated tests, there are unit tests to see what sql gets emitted in
tests/query.test.ts, and some tests of the types inview.test-d.ts.I've also run some manual tests with a typescript module with views.