What is Drizzle ORM?
Drizzle ORM is a lightweight, TypeScript-native ORM for PostgreSQL, MySQL, and SQLite. Unlike Prisma, schemas are defined in TypeScript code using builder functions (pgTable, mysqlTable, sqliteTable), giving full type inference without a separate schema file.
Why Generate from JSON?
When building API-backed applications, you often have sample JSON from an existing API or database. Generating a Drizzle schema from that sample saves 10–20 minutes of manual mapping per table.
Column Type Mapping per Dialect
- PostgreSQL:
text(),integer(),doublePrecision(),boolean(),timestamp() - MySQL:
varchar(),int(),double(),tinyint(),datetime() - SQLite:
text(),integer(),real(),integer()(bool),text()(date)
// JSON Input
{ "id": 1, "email": "a@example.com", "score": 9.5, "active": true }
// Generated Drizzle Schema (PostgreSQL)
import { pgTable, integer, text, doublePrecision, boolean } from 'drizzle-orm/pg-core';
export const users = pgTable('users', {
id: integer('id').primaryKey().notNull(),
email: text('email').notNull(),
score: doublePrecision('score').notNull(),
active: boolean('active').notNull(),
});