Hey,
I’m not a big fan of orms, but unfortunately I have to use it in so many projects.
So I started to write some typesafe query builders in typescript for different databases a long time ago.
Well, now I’m using rescript in many private projects but I was missing something like kysely or drizzle which I can use in rescript directly.
So again… I started to work on my own library.
I’ve tried several different approaches, and I’ve mentioned one or the other in a different context here in the forum already.
One approach was to generate a lot of code by a codegenerator, another was the opposite - so no codegen but a lot of type magic.
The first one was too restrictive and the second one required a lot of boilerplate (bad dx).
Now I’ve chosen a hybrid approach:
- Create the schema of the tables with a simple dsl (rescript)
- Use the cli to generate the types for rescript
- Use the cli to generate an sql file with the complete schema
- Use the generated files to write typesafe select, insert, update and delete queries (rescript).
At some points, unfortunately, i had to write some really nasty code, because the typesystem of rescript limited me, but it was still enjoyable.
It’s far from feature completeness, I’m just using it in a mini project with sqlite and I’m still thinking about solutions against sql injection (with or without placeholders / prepared statements).
Nevertheless, someone might find it useful or can even improve it.
Cheers
Daniel