3 ms·
Hah a few months back I released https://github.com/ivank/potygen https://github.com/ivank/potygen Similar idea - statically typing queries. Mine was mostly me
by seer 4y ago
Hah a few months back I released https://github.com/ivank/potygen https://github.com/ivank/potygen
Similar idea - statically typing queries. Mine was mostly me playing around with recursive decent parsers seeing if I can actually parse SQL with it, and it seems to work OK, at least for Postgres.
It does require a "build" pass to generate the types, but I've added some additional bells and whistles like auto formatters and on hover info about columns / views / tables etc. Once you have the sql AST its pretty easy to build a lot of cool stuff around it.
It's all pure TS and doesn't use parser generators like ANTLR. We've been using it in prod for a while now and seem to be working alright - its mostly types anyway, but does have a runtime component, since sql parameters in node Postgres are too basic for our use case.
It all started from the amazing https://github.com/dmaevsky/rd-parse https://github.com/dmaevsky/rd-parse which showed me that you could build crazy complex parsers with like 100-200 lines of code.
- norman784 4y agoI don't agree with this being a cons > Requires knowledge about SQL & your database For me that's a pros, because it is transferable knowledge. And > No type safety Is a bummer, if you could check at compile time or some other way that your queries are valid it will be cool, in rust is a crate that does exactly that sqlx[0], and besides sql being verbose I found so easy and enjoyable to work with, it's so easy to know exactly what the query does, with ORM's is easy to have a query that's hard to know what does and the only way to be sure is running and printing the query. [0] https://crates.io/crates/sqlx https://crates.io/crates/sqlx