A Software Engineer's Tips and Tricks #1: Drizzle
4 minHey there! At Koyeb, we really like diving into technical stuff. But here’s the thing: not every cool thing we stumble upon or think about needs a massive blog post. And honestly, not everything we’re into is directly related to what Koyeb does or about infrastructure in general.
So, we’ve got an idea: what if we start sharing these bits and pieces with you in a series of really short blog posts? They’ll be about all sorts of things—some related to our work, some just because we think they’re neat.
Here’s the plan: we’ll post something new three times a week, at least for the next few weeks. These posts will be super short reads, just a couple of minutes tops. If you don’t like one of the posts, no problem! Just skip it and check out the next one.
But if you do find something you like, please share it, tweet it, or tell your friends about it. And more importantly, don’t forget to check out the "further reading" links we’ll include at the bottom of each post for more info to dive deeper into the topic.
Sound good? Keep an eye on our blog, and let’s see where this goes!
Drizzle: a lightweight ORM in TypeScript
In the world of software development, there are two kinds of developers: those who have never had to complain about ORMs and those who have actually used them. Whether it’s Django ORM for Python, Active Record for Ruby, GORM for Golang, Doctrine for PHP, or Prisma for TypeScript, a common issue persists: writing simple queries is straightforward, but constructing complex or optimized queries can take hours, if not days.
Enter Drizzle, a lightweight typesafe ORM for TypeScript that comes with one promise: If you know SQL — you know Drizzle.
Here is a quick example to demonstrate how to use Drizzle. First, create a PostgreSQL database (on Koyeb!), and create a table with some data:
Now, let’s install Drizzle:
Finally, let’s open myapp.ts
and:
- Add the imports
- Declare the database and the table we previously created:
- Fetch the entry from
users
starting withj
:
For your important application running in production, you should consider using a framework (Vite, NextJS) and not replicate this example setup. You probably also want to set up database migrations and use Drizzle Studio to explore your data. The goal of this example is to demonstrate it is possible to have a typesafe ORM, and write queries in the best language that exists to query relational data: SQL!
Further reading:
- Drizzle website: https://orm.drizzle.team/
- Tutorial for building a web app with Drizzle: https://www.koyeb.com/tutorials/build-and-run-a-web-app-using-turso-drizzle-orm-and-express-on-koyeb
SIGKILL
That’s it for today! We hope you enjoyed these tips and tricks. If you have any feedback or suggestions for future posts, feel free to reach out to us on Twitter (or X) at @gokoyeb, Koyeb's LinkedIn, or on the Koyeb Community.