Kosame: A new Rust ORM inspired by Prisma and Drizzle
Hey everyone.
I have spent a decent amount of time in the TypeScript world and fallen in love with the power of TypeScript types (e.g. mapped types). One of the places where TypeScript shines the most in my opinion is in ORMs like Prisma and Drizzle. Both of these ask you to write exactly two things: Your database schema, and your queries. Notably however you don't have to specify the return value of a given query, because these can be inferred in TypeScript type land automatically. You get full type-safety and auto-completions whenever you adjust your query. This is something that is just impossible in a "normal language" (say Java) without an annoying code generation build step. But Rust ain't no normal language, am I right?
Exploring the Rust world of database access I was of course excited by crates like sqlx. However, I couldn't help but notice that none of the big ORMs give me the developer ergonomics that I've come to expect from Prisma and Drizzle. Most of them make me write the query, and then also the Rust struct to fill the result into. They also usually don't make much use of Rust's procedural macros. "Relational queries", meaning the 1:N queries Prisma and Drizzle do wonderfully, are also rarely executed in the way I was looking for.
I wanted to explore how far Rust macros can be pushed to recreate Prisma's and Drizzle's type magic, and this is how Kosame was born. It's just a rough prototype at the moment and I don't recommend using it. It only supports Postgres for now and there are a ton of features I still want to implement. But, I couldn't resist showing what I've built so far and am looking forward to hearing your feedback.