Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I played around with parsing and inferring SQL on a type level. Simple stuff works, but as soon as you have a DB-specific dialect, it becomes hard. Parsing is already hard enough, but type inference on a type level is just not maintainable on the long run.

You can find it here: https://github.com/nikeee/sequelts



I was thinking on how a library could work with the type inference, one idea that came to mind is to have some script running in the background (if you are using a bundler, you might be able to hook into it) that search for all sql tag templates, execute them against a live database to validate and get the result structure. This is how sqlx[0] works and might is worth exploring more in deep.

One downside of course is that AFAIK typescript is not powerful enough to match all queries to types, so my idea was to build a .d.ts file that maps the queries with the result.

ts-safeql seems to work with a lsp plugin? I didn't dig into how lsp and plugin works, so I cannot speak of if my approach will work with it, but I suppose no, because it needs to generate files.

[0] https://github.com/launchbadge/sqlx


You should check out sdf (semantic data fabric). https://sdf.com




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: