Build type-safe database queries with Drizzle ORM patterns.
$inferSelect for query return types, $inferInsert for insert input — they differ (select has defaults filled, insert has optionals)relations() in a separate call, not inline with table — Drizzle separates schema from relationswhere: eq(users.id, 5) not where: { id: 5 } — Prisma syntax doesn't workand() / or(): where: and(eq(users.active, true), gt(users.age, 18))db.query.users.findMany() for relational queries with with:, db.select().from(users) for SQL-like — mixing them causes type errorsdrizzle-kit pushdrizzle-kit generatedrizzle-kit migratestrict: true in drizzle.config.ts to catch schema drift before it hits productionpgTable, imports from drizzle-orm/pg-coremysqlTable, imports from drizzle-orm/mysql-coresqliteTable, imports from drizzle-orm/sqlite-coredb.transaction(async (tx) => {}) — Drizzle doesn't auto-batch.prepare() for queries executed repeatedly — skips query building overhead.limit() to every findMany() / select() — no default limit means full table scansawait on queries returns a Promise, not results — TypeScript doesn't catch this if you ignore the returnreturning() is required to get inserted/updated rows back — without it you get { rowCount } onlyjsonb(), MySQL uses json() — wrong function = wrong serialization