DevBolt
Processed in your browser. Your data never leaves your device.

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.

Convert to TypeScript interface
Input
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email TEXT UNIQUE NOT NULL,
  age INTEGER,
  created_at TIMESTAMP DEFAULT NOW()
);
Output
export interface User {
  id: number;
  name: string;
  email: string;
  age: number | null;
  createdAt: Date;
}
← Back to tools

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 TypeTypeScriptPrisma
INT / INTEGER / SERIALnumberInt
BIGINT / BIGSERIALnumberBigInt
VARCHAR / TEXT / CHARstringString
BOOLEAN / BOOLbooleanBoolean
TIMESTAMP / DATETIMEDateDateTime
DECIMAL / NUMERICnumberDecimal
JSON / JSONBRecord<string, unknown>Json
UUIDstringString
BYTEA / BLOBBufferBytes

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 | null or 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

Pro Tip

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.

Common Pitfall

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.

Real-World Example

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.

Security Note

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?
Paste SQL CREATE TABLE statements into the converter. It parses column names, data types, nullability, and defaults to generate TypeScript interfaces. SQL types map to TypeScript: VARCHAR/TEXT become string, INTEGER/BIGINT become number, BOOLEAN becomes boolean, TIMESTAMP/DATE become Date or string, and NUMERIC/DECIMAL become number or string for precision. NOT NULL columns are required, nullable columns get optional or null union types. DevBolt generates one interface per table with proper PascalCase naming.
What is the difference between Prisma schema and Drizzle ORM output?
Prisma uses its own declarative schema language with models, field types, and attributes like @id, @default, @unique. It generates a type-safe client with findMany, create, and update methods. Drizzle uses plain TypeScript with functions like pgTable, varchar, integer, exporting table objects. Drizzle supports raw SQL more naturally. The converter outputs either Prisma's .prisma format or Drizzle's TypeScript definitions with your chosen database dialect. Foreign keys are preserved in both formats.
How are SQL foreign keys converted to TypeScript or ORM schemas?
For TypeScript interfaces, foreign key columns become number or string properties with JSDoc comments noting the relationship. For Prisma, relationships become @relation attributes connecting the foreign key to the referenced model. For Drizzle, relationships use the relations() helper with one() and many() definitions. Primary keys, unique constraints, and indexes are preserved as corresponding decorators or method calls.

Related Convert Tools