How do I convert SQL to TypeScript, Prisma, or Drizzle?
Paste SQL CREATE TABLE statements and get TypeScript interfaces, Prisma schema, or Drizzle ORM table definitions. The tool parses constraints (PRIMARY KEY, FOREIGN KEY, UNIQUE, DEFAULT), maps 30+ SQL types, and generates framework-specific annotations. Download or copy. Everything runs in your browser.
CREATE TABLE users ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, email TEXT UNIQUE NOT NULL, age INTEGER, created_at TIMESTAMP DEFAULT NOW() );
export interface User {
id: number;
name: string;
email: string;
age: number | null;
createdAt: Date;
}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.
Tips & Best Practices
Generate Prisma schemas for rapid prototyping, Drizzle for production control
Prisma's schema is more concise and includes migrations out of the box — great for prototyping. Drizzle's schema is TypeScript-native, giving you full control over queries with zero abstraction cost. Choose based on your project maturity and performance requirements.
SQL DECIMAL/NUMERIC types should not become TypeScript number
JavaScript's number type is IEEE 754 floating point — it cannot exactly represent 0.1 + 0.2. Financial and precision-sensitive SQL columns (DECIMAL, NUMERIC, MONEY) should map to string or a Decimal library (decimal.js, Prisma Decimal) in TypeScript, not number.
Migrate a legacy database to a modern TypeScript ORM
Export your existing database schema as CREATE TABLE statements (pg_dump --schema-only), paste into this converter, and get Prisma or Drizzle schemas. This shortcut saves hours of manually translating column types, constraints, and relationships for legacy database migrations.
Generated types should separate read and write interfaces
A SQL table with auto-generated id, created_at, and hashed_password columns shouldn't have a single TypeScript interface. Create separate InsertUser (without id/timestamps), SelectUser (without password), and InternalUser (full row) types to prevent accidentally exposing or overwriting sensitive columns.
Frequently Asked Questions
How do I convert SQL CREATE TABLE to TypeScript interfaces?
What is the difference between Prisma schema and Drizzle ORM output?
How are SQL foreign keys converted to TypeScript or ORM schemas?
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