erd.sketch

SQL to Prisma: models from a DDL script

What follows is not a mock-up: it is the real output of the generator for the script on the left. You get the same code in the editor under “Codegen → Prisma”.

The inputschema.sql
CREATE TABLE users (
    id BIGINT NOT NULL PRIMARY KEY,
    email       VARCHAR(255) NOT NULL UNIQUE,
    full_name   VARCHAR(120),
    is_active   BOOLEAN NOT NULL,
    created_at  TIMESTAMP NOT NULL
);

CREATE TABLE orders (
    id BIGINT NOT NULL PRIMARY KEY,
    user_id     BIGINT NOT NULL REFERENCES users(id),
    total       DECIMAL(12,2) NOT NULL,
    note        TEXT,
    placed_at   TIMESTAMP NOT NULL
);
What comes outschema.prisma
model Users {
  id         BigInt      @id
  email      String      @db.VarChar(255) @unique
  fullName   String?     @db.VarChar(120) @map("full_name")
  isActive   Boolean     @map("is_active")
  createdAt  DateTime    @map("created_at")

  orders     Orders[]

  @@map("users")
}

model Orders {
  id        BigInt      @id
  userId    BigInt      @map("user_id")
  total     Decimal     @db.Decimal(12, 2)
  note      String?     @db.Text
  placedAt  DateTime    @map("placed_at")

  users     Users       @relation(fields: [userId], references: [id])

  @@map("orders")
}
Open the editor

The script stays in the browser: both parsing and generation run on your machine, nothing goes to a server.

How the types land

in SQLin the model
BIGINTBigInt
VARCHAR(255)String @db.VarChar(255)
BOOLEANBoolean
TIMESTAMPDateTime
DECIMAL(12,2)Decimal @db.Decimal(12, 2)
TEXTString? @db.Text
Optional field
String?
Column name
@map("full_name")
Relation
@relation(fields: [userId], references: [id])