Databases With Prisma - The Ultimate Typescript ORM


For the past year I've found myself needing a database for my projects more than ever and, as someone who can't write SQL Prisma has saved me.

Allowing tight integration between my back-end and front-end code through Typescript types is awesome. Though, as I've recently realised that using an ORM (Object Relational Mapping) like this means that you can't use some of the more niche features of a database. For example, the Interval type in PostgreSQL isn't supported by Prisma but would be very useful for setting up reoccurring events that might appear in a piece of scheduling software.

Apart from these limitations it makes it easy for anyone to build a database to use in smaller applications like a blog or a simple piece of scheduling software. Because it generates migrations automatically it's easy to change types or even relationships.

But, Prisma's greatest claim to fame is the sheer depth of auto-generated types. When you generate your database schema along with creating migrations automatically, it'll also generate a client library that's fully typed. The types aren't just surface level either. If you choose to include a limited set of data for example, fetching only the user's name rather than their entire account the types will only include the name. This is awesome for full stack frameworks like Remix or NextJS where you can infer the type of the data you're fetching automatically.

Prisma also makes it easy to learn how to setup databases and model them the way they might be if you were to setup one from scratch.