How you are dealing with sql in rescript?

Hi there. I’ve got a good opportunity to use rescript as a full-stack solution; the only missing thing is type-safe SQL or working ORM. There is no Prisma generator, so maybe some type-safe SQL solution? Any advice?

Shameless self plug, but I’ve built pgtyped-rescript (a ReScript fork of pgtyped) which I use in a lot of projects: pgtyped-rescript/RESCRIPT.md at rescript · zth/pgtyped-rescript · GitHub

Let’s you write SQL code inline in a type safe way (types are generated from the SQL and your DB):

let query = %sql.one(`
  SELECT * FROM books WHERE id = :id!
`)

let res = await client->query({id: 1})

// Typed according to the SQL 1query
Console.log(res)
4 Likes

There are some things:

and I think @joshderochervlk had some prisma bindings?

2 Likes

No, I have some other library bindings I’ve worked on but nothing in this space. @zth is the expert for these :slight_smile:

Because I needed to work with a range of databases and other folks in my team were sql devs, I used knex.js with custom bindings for an internal app. It let me use sql for querying and having ReScript helped with some runtime safety.

1 Like

I’ve also thought about it. It looks like something easy to use and quite universal.