-
Notifications
You must be signed in to change notification settings - Fork 24
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
Use static query analysis for type generation #366
Comments
Hi @danielrearden, this sounds very cool! Yeah, slonik-typegen is slowly moving in that direction already. It started by blindly accepting the
|
Also curious if it could help with #315 |
I wrote a small library for generating TypeScript types from Postgres queries using only static query analysis. There's a number of advantages of using static query analysis over the approach currently used by
@slonik/typegen
including:psql
coalesce
ornullif
There's also some pretty cool things we could do in the future, for example, providing very accurate types for JSON objects built using
json_build_object
or narrowing the types based onWHERE
conditions.There are, of course, tradeoffs as well. Namely, because static analysis requires us to effectively duplicate logic that's already handled by Postgres, there's a risk of human error and the possibility that we haven't covered every possible expression. However, I think the flexibility and simplicity of the approach outweigh the risks.
I actually wrote
pg-magic
with the hope that it could be used with@slonik-typegen
😅 Let me know whether you think it would be worthwhile to move in this direction!The text was updated successfully, but these errors were encountered: