Back to articles
Drizzle ORM Is What Prisma Should Have Been

Drizzle ORM Is What Prisma Should Have Been

via Dev.to TutorialAlex Spinov

SQL-Like Syntax, Full Type Safety Drizzle ORM gives you a SQL-like API that generates perfect SQL. No query engine overhead, no N+1 surprises, no schema push headaches. Define Schema import { pgTable , serial , text , integer , timestamp } from " drizzle-orm/pg-core " ; export const users = pgTable ( " users " , { id : serial ( " id " ). primaryKey (), name : text ( " name " ). notNull (), email : text ( " email " ). unique (), age : integer ( " age " ), createdAt : timestamp ( " created_at " ). defaultNow () }); export const posts = pgTable ( " posts " , { id : serial ( " id " ). primaryKey (), title : text ( " title " ). notNull (), authorId : integer ( " author_id " ). references (() => users . id ) }); Query import { db } from " ./db " ; import { users , posts } from " ./schema " ; import { eq , gt , desc } from " drizzle-orm " ; // Select const allUsers = await db . select (). from ( users ); const adults = await db . select (). from ( users ). where ( gt ( users . age , 18 )); //

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
2 views

Related Articles