SQL to Drizzle ORM Schema Generator
Generate Drizzle ORM table definitions from SQL DDL. Select your database dialect and get correctly typed pgTable, mysqlTable, or sqliteTable definitions with column types, constraints, and references.
SQL to TypeScript / Prisma / Drizzle Converter
Convert SQL CREATE TABLE statements into TypeScript interfaces, Prisma schema, or Drizzle ORM table definitions. Supports PostgreSQL, MySQL, and SQLite syntax.
SQL Type Mapping Reference
| SQL Type | TypeScript | Prisma |
|---|---|---|
| INT / INTEGER / SERIAL | number | Int |
| BIGINT / BIGSERIAL | number | BigInt |
| VARCHAR / TEXT / CHAR | string | String |
| BOOLEAN / BOOL | boolean | Boolean |
| TIMESTAMP / DATETIME | Date | DateTime |
| DECIMAL / NUMERIC | number | Decimal |
| JSON / JSONB | Record<string, unknown> | Json |
| UUID | string | String |
| BYTEA / BLOB | Buffer | Bytes |
How It Works
- SQL Parser -- parses CREATE TABLE statements supporting PostgreSQL, MySQL, and SQLite syntax including quoted identifiers, multi-word types, and constraints.
- TypeScript -- generates typed interfaces with SQL type mapping, nullable fields as
| nullor optional?. - Prisma -- generates Prisma models with @id, @default, @unique, @map, and @db.* annotations.
- Drizzle ORM -- generates table definitions using pgTable/mysqlTable/sqliteTable with correct column types and modifiers.
- Foreign keys -- detected from both inline REFERENCES and table-level FOREIGN KEY constraints.
- Everything runs in your browser -- no data is sent over the network.
What is Drizzle ORM?
Drizzle ORM is a lightweight, type-safe TypeScript ORM that provides a SQL-like query builder. Unlike Prisma, Drizzle schema definitions are written in TypeScript using helper functions like pgTable, mysqlTable, and sqliteTable. Each table is defined as a JavaScript object with column definitions that map directly to database columns.
-- SQL input
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
body TEXT,
author_id INTEGER REFERENCES users(id),
published BOOLEAN DEFAULT false
);
// Generated Drizzle ORM schema
import { pgTable, serial, varchar, text, integer, boolean } from "drizzle-orm/pg-core";
import { users } from "./users";
export const posts = pgTable("posts", {
id: serial("id").primaryKey(),
title: varchar("title", { length: 255 }).notNull(),
body: text("body"),
authorId: integer("author_id").references(() => users.id),
published: boolean("published").default(false),
});How the converter generates Drizzle schemas
The converter maps SQL types to Drizzle column functions: integer(), varchar(), text(), boolean(), timestamp(), serial(), uuid(), json(), jsonb(), numeric(), real(), doublePrecision(), and more. Constraints are added as method chains: .primaryKey(), .notNull(), .unique(), .default(), and .references(). The output uses the correct import path based on your selected dialect (drizzle-orm/pg-core, drizzle-orm/mysql-core, or drizzle-orm/sqlite-core).
Drizzle vs Prisma schema
Drizzle schema is pure TypeScript code, making it easy to compose, generate, and version control alongside your application. Prisma uses its own DSL (.prisma files) that requires a separate code generation step. Drizzle provides a thinner abstraction over SQL, while Prisma offers a more opinionated data access layer. Choose based on your project's needs.
Frequently Asked Questions
Does the converter handle dialect-specific types?
Yes. The converter generates different column functions based on your selected dialect. PostgreSQL gets functions like uuid(), jsonb(), and timestamp with timezone support. MySQL gets int(), datetime(), and varchar with required length. SQLite maps everything to integer(), text(), real(), or blob().
Are foreign key references included?
Yes. Both inline REFERENCES and table-level FOREIGN KEY constraints are detected and converted to Drizzle .references(() => tableName.columnName) calls, maintaining referential integrity in your schema definition.
Related Convert Tools
cURL to Code
Convert cURL commands to JavaScript, Python, Go, PHP, Ruby, and Java code instantly
JSON to CSV Converter
Convert JSON arrays to CSV with nested object flattening, column selection, and .csv download
TOML ↔ JSON/YAML
Convert between TOML, JSON, and YAML — perfect for Cargo.toml and pyproject.toml
Encode / Decode Multi-Tool
Base64, Base32, Hex, Binary, URL, and HTML encoding & decoding all in one tool