Type-safe database access with Rescript?

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?

MVP Features

  1. 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.
  2. Rescript records for tables
  3. ??
3 Likes

I know it’s not the answer you’re looking for (I’d be interested in having a tool like that too), but you can use Postgraphile to have a type safe access to a postgres DB through graphQL.

3 Likes

Thank you! True, the graphql route is very much type safe. I thought Postgraphile became Prisma. Interesting to see it adopted stil.

What tools are you using to connect to your graphql server?

You could check out the sqlgg tool, which does this for OCaml: https://github.com/ygrek/sqlgg

Porting it to ReScript should be possible. Note the license is GPLv2, but that shouldn’t really be an issue, because it’s just used to generate code, it’s not linked as a library in your app.

2 Likes

Since postgraphile is relay compatible, I use rescript-relay, it works quite well!

4 Likes