Skip to content
ZeroServer.tools

Drizzle ORM Schema Generator

Generate a Drizzle ORM table definition from any JSON sample.

Preset Templates
Columns Inferred
6
Input Size
128 B
Output Size
444 B
DB Target
postgresql
Generated Schema
import { pgTable, serial, text, timestamp, boolean, real } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
  id: serial("id").primaryKey(),
  email: text("email").notNull().unique(),
  name: text("name"),
  createdAt: timestamp("created_at").defaultNow(),
  active: boolean("active").default(false),
  score: real("score"),
});

export type User = typeof users.$inferSelect;
export type NewUser = typeof users.$inferInsert;

About Drizzle ORM Schema Generator

Paste any JSON object and instantly get a Drizzle ORM table definition ready to drop into your TypeScript project. Supports PostgreSQL (pg-core), MySQL (mysql-core), and SQLite (sqlite-core) with appropriate type mappings. Field names are automatically converted from camelCase to snake_case, and common patterns like id, email, and createdAt receive smart defaults such as .primaryKey(), .notNull().unique(), and .defaultNow(). Copy or download the result as a .ts file.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Generating a table definition from a sample row.
  • Producing a starting schema for a table that has no definition yet.
  • Getting the column helper syntax right for your dialect.
  • Choosing the right dialect helpers before the first migration is written.
  • Producing a schema for a fixture that matches production shapes.

Frequently Asked Questions

Why does the output differ per database?
Because Drizzle's column builders are dialect-specific: `pgTable` with `serial` and `timestamp` for Postgres, `mysqlTable` with `int().autoincrement()` for MySQL, `sqliteTable` with `integer` for SQLite — which has no native boolean or date type at all and stores both as integers.
How is a primary key inferred?
From an integer field named `id`, which becomes a serial or auto-incrementing column marked `.primaryKey()`. Any other convention — a UUID, a compound key, a natural key — cannot be read from a sample payload and needs setting by hand.
What makes Drizzle different from an ORM like Prisma?
The schema is TypeScript rather than a separate schema language, and the query builder mirrors SQL instead of abstracting it. There is no generation step and no runtime engine — types come from inference over the same objects you declare, which is why the schema file is the whole definition.
Does it generate migrations?
No — this produces the schema file. `drizzle-kit generate` then diffs that schema against the previous state and emits SQL migrations, which is the step that must not be skipped: applying a changed schema without a migration means the database and the types silently disagree.
Why is a date field a string in my JSON?
Because JSON has no date type, so `"2026-01-01"` arrives as characters. The generator recognises ISO-shaped values and emits a timestamp column; anything ambiguous stays text. Check that column specifically, since a date stored as text sorts lexically and breaks range queries.

Common errors and gotchas

  • Accepting a dialect's default when the target database is a different one, since the helpers differ.
  • Generating for one dialect and deploying to another, where the column helpers differ.
  • Letting a date string become text, which then cannot be filtered by range.
  • Omitting indexes and unique constraints, which are cheap now and painful later.
  • Generating a schema without a migration, so the definition and the database drift apart.

Related Developer Utilities tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate