🐱 **Node.js + TypeScript + SQL = disappointment... but there's hope
**I've been trying to find an optimal solution for working with SQL databases on Node.js + TypeScript for a long time
As I've written before, I don't like ORMs, but what about SQL Builder and Typed SQL?
The first thing that comes to mind is Knex, but:
Firstly, although it has TypeScript support, it doesn't do much with it (it can't handle aliases, select only through a cumbersome construction db.ref(...).withSchema(...) and often without typing; where + join = pain)
Secondly, and this is, in my opinion, incredibly wild, you won't find almost any content on the topic of working with Knex + TypeScript, even on StackOverflow (reminder: 17k stars on Github)
The projects that interest me and that I will be implementing in the near future are:
- kysely – Knex, but written in TS from the start and able to do what Knex can't
- pgtyped – write SQL, run the pgtyped client, it checks that it's correct SQL for your database and exports types
- drizzle – although it's an ORM, it works like a SQL Builder
- slqc – an amazing library for Go, which is currently being ported to TypeScript (so it's not ready yet, but worth keeping an eye on)
The problem with these technologies is that they're a bit raw and only just starting to be discussed in the media (1, 2), but this is definitely the direction to look
**Okay, what if you already have Knex, an ORM, or even pure SQL and can't switch?
**At the moment, my solution is integration tests.
I've set up a system that allows me to write an integration test in a couple of minutes and check that all queries work correctly. And that's not counting all the other benefits of integration testing.
I'll definitely share all my settings, because I've already transferred them to 4 large projects and they work perfectly everywhere.
What do you use?