Anyone working on ways to have type-safety across the database layer, ideally Postgres?
If not, for the most part, I can query the metadata in Postgres for tables, columns, and whatnot. But I’ve never written a codegen library.
Does someone have advice on how I can best generate Rescript?
It’d be great if we can write SQL, but writing a parser seems tough. But perhaps I can leverage an existing tool that parses it into a transferable data medium.
I hardly know ppx development. But how do you propose someone going about this?
Because I like sql and how prevalent it is, I do like pgocaml’s choice. Ideal would be something like https://sqlc.dev/ where I can write sql, the compiler turns it into a nice little rescript function for me.
Safeql is a vscode plugin that checks your sql against the database. Most if not all of these implementations rely on Postgres, and at compile time (or whenever the vscode plugin runs), it runs a Describe query for each sql against the db for validation.
I’m working at a typesafe query builder written for and in rescript.
It will be a combination of a codegen (for the basic schema) and a “real” api.
As it is still very experimental, there is no real readme and a lot of code is commented out but you can already get a short overview how it might work by reading the example code.
Sitting on this idea inspired by safeql, maybe it’s possible to fork and adapt the rescript vscode into similar fashion.
You inform safeql what functions are called with the sql query and the database it’ll use. The plugin can execute the queries (with describe/explain analyze) and cache the results in the background. I can see some edge cases that makes it hard to differentiate which database to check against.
Can we adapt the rescript vscode extension to do this? If I understand correctly, most extensions are only displaying and working with whatever is outputted by the language server.
The ergonomics of using tagged template literals is immensely positive. Rescript would need to support this. See my rfc
Hmm, might be easier to forego the linter style and use a decorator on plain sql functions like gentype.
Extensions can do pretty much anything, so setting up your own extension to try things shouldn’t be that hard. But in general, make it work as a CLI or similar first. Then integrating into an extension is a bit easier.