erd.sketch

SQL에서 TypeScript으로: DDL 스크립트로 모델 만들기

아래는 예시 그림이 아니라 왼쪽 스크립트에 대한 생성기의 실제 출력입니다. 편집기에서 「Codegen → TypeScript」을 누르면 같은 코드가 나옵니다.

입력schema.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
);
결과types.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;
}
편집기 열기

스크립트는 브라우저에 남습니다. 해석도 생성도 사용자의 기기에서 이뤄지고 서버로는 아무것도 가지 않습니다.

타입이 어떻게 대응되나

SQL에서모델에서
BIGINTstring
VARCHAR(255)string
BOOLEANboolean
TIMESTAMPDate
DECIMAL(12,2)string
TEXTstring | null
널 허용 필드
string | null
컬럼 이름
fullName
관계
// BIGINT → users.id