erd.sketch

SQL to TypeScript: 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 → TypeScript”.

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 outtypes.ts
export interface Users {
  id: string;  // BIGINT
  email: string;
  fullName: string | null;
  isActive: boolean;
  createdAt: Date;
}

export interface Orders {
  id: string;  // BIGINT
  userId: string;  // BIGINT → users.id
  total: string;  // DECIMAL(12,2)
  note: string | null;
  placedAt: Date;
}
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
BIGINTstring
VARCHAR(255)string
BOOLEANboolean
TIMESTAMPDate
DECIMAL(12,2)string
TEXTstring | null
Optional field
string | null
Column name
fullName
Relation
// BIGINT → users.id