Skip to main content
CodeAlchemy

SQL → ORM

Convert SQL DDL to Prisma or Drizzle schema definitions instantly.

client-sidefree
Sample:
Input
Loading editor…
Loading editor…

Runs entirely in your browser. No server calls.

How to use SQL → ORM

01

Paste your SQL DDL

Drop a CREATE TABLE statement into the editor, or load one of the samples.

02

Configure and convert

Pick ORM, dialect, and options. Click Convert or press ⌘↵.

03

Copy the schema

Copy the Prisma or Drizzle schema to your project.

Frequently asked questions

Is this free?

Yes, completely free. No sign-up, no rate limits.

Does my code get sent to a server?

No. All conversion runs entirely in your browser. Nothing is sent to any server.

Are all SQL column types mapped?

Common types (INT, VARCHAR, TEXT, BOOLEAN, TIMESTAMP, etc.) are mapped. Exotic vendor-specific types fall back to String / text.

Are foreign keys handled?

Yes — foreign keys detected from REFERENCES become @relation / references() directives in the output schema.

Long-form guide

Convert SQL DDL into Prisma or Drizzle schema, with relations intact

SQL → ORM turns your SQL CREATE TABLE statements into a Prisma schema or Drizzle table definitions, with relations, indexes, and dialect-specific types all preserved. Paste DDL on the left, pick your ORM, set a couple of toggles, and the generated schema appears on the right — copy it, drop it into your project, and you're shipping.

How to use it

  1. Paste your DDL. Drop one CREATE TABLE statement or your whole schema. The parser handles standard PostgreSQL, MySQL, and SQLite syntax. Use the Sample selector to load a typical blog schema if you want a reference shape before pasting your own.
  2. Pick your ORM. Prisma generates a schema.prisma with models, types, and relations. Drizzle generates a TypeScript file with table definitions, ready to import. Both produce idiomatic output you'd have written by hand.
  3. Pick the DB dialect. Postgres, MySQL, or SQLite. For Drizzle this affects which column helpers get imported (pg, mysql2, better-sqlite3). For Prisma it sets the datasource provider in the schema header.
  4. Toggle options. Indexes preserves CREATE INDEX statements as @@index in Prisma or index() calls in Drizzle. Foreign keys and Include relations turn REFERENCES into typed relations. Timestamps adds createdAt/updatedAt to every model. Soft delete adds a nullable deletedAt.
  5. Click Convert (or press ⌘↵). Output appears on the right. Copy with the corner button or download as schema.prisma or schema.ts directly.

What the converter handles

Tables become models (Prisma) or pgTable / mysqlTable / sqliteTable calls (Drizzle). Column types map cleanly: INT, BIGINT, SMALLINT, VARCHAR, TEXT, BOOLEAN, TIMESTAMP, DATE, TIME, DECIMAL, JSON, JSONB, UUID. Lengths on VARCHAR and DECIMAL are preserved. NOT NULL becomes required; absence becomes optional (? in Prisma, no .notNull() in Drizzle).

Constraints translate too. PRIMARY KEY becomes @id in Prisma or .primaryKey() in Drizzle. UNIQUE becomes @unique or .unique(). CHECK constraints are preserved as comments — neither ORM exposes them as first-class — and DEFAULT values become @default(...) or .default(...) calls. Composite primary keys use @@id or composite primaryKey() definitions.

Foreign keys become typed relations. REFERENCES users(id) becomes @relation in Prisma or references(() => users.id) in Drizzle. The reverse side of the relation is added on the parent table for Prisma; in Drizzle it's left as a one-directional reference (Drizzle's idiomatic style). Cascade behaviors (ON DELETE CASCADE, ON UPDATE) are preserved.

Indexes from CREATE INDEX statements are picked up and emitted as @@index([columns]) (Prisma) or index().on(table.column) (Drizzle). Composite indexes work; partial indexes (with WHERE clauses) are emitted with a comment since neither ORM has first-class syntax for them yet.

When to reach for it

Migrating a legacy Postgres or MySQL database to a Node.js stack is the obvious case. Dump your DDL with pg_dump --schema-only, paste it in, get a working Prisma or Drizzle schema in seconds. Adopting an ORM in an existing project is similar: introspect your database to SQL, convert here, drop into the codebase.

It's also a learning tool. Paste a SQL schema you don't fully understand and see how it expresses in Prisma's relational metaphors or Drizzle's table builder. Switching ORMs mid-project also gets easier — convert SQL to the new ORM directly without retyping every column.

Examples

Simple table to Prisma
Input · sql
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  name VARCHAR(100),
  created_at TIMESTAMP DEFAULT NOW()
);
Output · prisma
model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  createdAt DateTime @default(now())
}
Foreign key to Drizzle
Input · sql
CREATE TABLE posts (
  id SERIAL PRIMARY KEY,
  user_id INT NOT NULL REFERENCES users(id),
  title VARCHAR(255) NOT NULL,
  body TEXT
);
Output · typescript
import { pgTable, serial, integer, varchar, text } from 'drizzle-orm/pg-core';
import { users } from './users';

export const posts = pgTable('posts', {
  id: serial('id').primaryKey(),
  userId: integer('user_id').references(() => users.id).notNull(),
  title: varchar('title', { length: 255 }).notNull(),
  body: text('body'),
});
Indexes and composite keys
Input · sql
CREATE TABLE follows (
  follower_id INT NOT NULL,
  following_id INT NOT NULL,
  PRIMARY KEY (follower_id, following_id)
);
CREATE INDEX follows_following_idx ON follows(following_id);
Output · prisma
model Follow {
  followerId  Int
  followingId Int

  @@id([followerId, followingId])
  @@index([followingId])
}

Frequently asked questions

Yes. No sign-up, no rate limit, no usage cap. The conversion is fully client-side using sql-parser-cst, so neither your DDL nor the generated schema leaves your browser.