4 ms·
Ive been dreaming up a TS SQL library that would use the new template literal features to implement a full postgres SQL parser in the type system. I imagine thi
by tengbretson 5y ago
Ive been dreaming up a TS SQL library that would use the new template literal features to implement a full postgres SQL parser in the type system. I imagine this would allow you to define a series of db migration statements (alter table, add column, etc) and the net result of that series of migrations would be rolled up into a schema definition as a type.
Then you could take this schema type and feed it into some function as a generic to generate a raw query executor that could again fully parse the SQL and perfectly infer the result type.
I believe all this is possible but I don't really know where to start.
- lukeramsden 5y agoMaybe this may help as some inspiration https://github.com/codemix/ts-sql https://github.com/codemix/ts-sql
- phpnode 5y agoAuthor of ts-sql here. Shin Ando has forked my proof of concept / toy implementation and made it much more practical, if you're thinking about spending time on this idea that's probably a better starting point: https://github.com/andoshin11/sqlpture https://github.com/andoshin11/sqlpture
- nawgz 5y agoHasura / GraphQL / GraphQL-codegen does pretty much exactly what you describe wrt fully typed query results, except you type graphql queries rather than sql ones
- seer 5y agoWe’ve been using pg-typed to give us almost the exact thing you are talking about. While it does have its limitations, its vastly better than raw sql queries. https://pgtyped.vercel.app/ https://pgtyped.vercel.app/
- furstenheim 5y agoIt looks interesting, but how does it behave with dynamically created queries?
- cldellow 5y agoDynamic queries aren't supported, eg if you want to conditionally join a table or generate where clauses programmatically.
- DylanSp 5y agohttps://github.com/codemix/ts-sql https://github.com/codemix/ts-sql might be worth looking at, at least the parsing section.
- presentation 5y agoHere’s another one I found: https://github.com/Ff00ff/mammoth https://github.com/Ff00ff/mammoth