sql to typescript interface converter

typetools

instant, client-side type converter • 0ms network latency

root:
inputsql ddl
paste or drop file
297 chars
outputtypescript
*.ts
export interface RootPayloadItem {
  "CREATE TABLE users (": string;
}

export type RootPayload = RootPayloadItem[];
0.15ms•in-browser
documentation, edge cases & specifications below

step-by-step integration guide

technical specification differences & end-to-end conversion workflow

Mapping Relational Database DDL Constraints to TypeScript's Structural Type System

Relational database engines (PostgreSQL, MySQL, SQLite, and SQL Server) define data schemas through Data Definition Language (CREATE TABLE) statements that govern physical disk storage, column nullability, default expressions, and foreign-key constraints. TypeScript, on the other hand, models in-memory JavaScript values returned by database drivers such as pg (node-postgres), mysql2, or better-sqlite3. A critical engineering pitfall is assuming SQL numeric and temporal types map 1:1 to JavaScript primitives. For example, PostgreSQL BIGINT (64-bit signed integer) and NUMERIC(18,4) exceed IEEE 754 double-precision float safety and are returned by node-postgres as JavaScript string values by default to prevent silent precision corruption.

DDL AST Parsing, Nullability Analysis, and Insert vs. Select Types

Our SQL-to-TypeScript compiler tokenizes raw SQL scripts—ignoring dialect-specific index declarations, tablespaces, and trigger clauses—to extract column definitions and constraint modifiers. Each column's SQL data type is mapped to its exact runtime TypeScript counterpart: VARCHAR, TEXT, and UUID map to string; INT, SMALLINT, and REAL map to number; BOOLEAN maps to boolean; TIMESTAMPTZ maps to Date | string; and JSONB maps to Record<string, unknown>. Crucially, the analyzer inspects NOT NULL and PRIMARY KEY constraints: any column lacking an explicit NOT NULL constraint is emitted as a union with | null (e.g., deleted_at: string | null;) because database drivers return explicit null (not undefined) for empty relational cells.

frequently asked questions

common developer questions answered

q:Why are nullable SQL columns typed as 'T | null' instead of optional 'field?: T'?

When you run a SELECT query, SQL drivers like node-postgres or Prisma always return every selected column key on the result object, setting missing database values to null rather than omitting the key (undefined).

q:How are PostgreSQL array columns (e.g., TEXT[] or INT4[]) converted to TypeScript?

The DDL parser detects PostgreSQL array brackets [] and ARRAY keywords, mapping them directly to typed TypeScript arrays such as string[] or number[].

q:How should PostgreSQL BIGINT and DECIMAL columns be typed in TypeScript?

Because 64-bit BIGINT and arbitrary-precision NUMERIC values can exceed JavaScript's Number.MAX_SAFE_INTEGER, standard Node.js database drivers serialize them as strings over the wire, which our type definitions reflect.

topic cluster

related type & ast converters

3 interconnected tools