SQL CREATE TABLE to TypeScript

Turns CREATE TABLE statements from MySQL, PostgreSQL or SQLite into TypeScript interfaces, one per table, with nullable columns typed as "| null".

Use the tool

Why this tool exists

When you build a TypeScript backend or a typed API client on top of an existing database, someone has to write the row types by hand. That is slow, and the types drift the moment a column changes. If you already have the schema dump or a migration file, the column list is right there: names, types, NOT NULL flags. This tool reads that DDL and writes the matching interfaces, so you start from something accurate and only adjust the odd column. Because the conversion runs in your browser, a schema from a private project never leaves your machine. It is a quick way to bootstrap types for a script, a prototype or a data-access layer without installing a code generator.

How to use it

  1. Paste one or more CREATE TABLE statements into the SQL box.
  2. Choose how BIGINT and dates are typed (string, number, bigint, Date) and whether property names stay as they are or become camelCase.
  3. Tick "export" or the optional-for-DEFAULT setting if you want them, then copy the interfaces.

Frequently asked questions

How are SQL types mapped to TypeScript?

Integers, decimals and floats become number, booleans become boolean, timestamps and dates follow your Date setting, JSON becomes unknown, blobs become Uint8Array and everything else becomes string. BIGINT is your choice, because a JavaScript number cannot hold every 64-bit value.

Does it handle quoted names and constraints?

Yes. Backtick, double-quote and bracket identifiers are read, as are IF NOT EXISTS, PRIMARY KEY and other table constraints. Primary key columns are treated as NOT NULL. Constraint-only lines produce no property.

What happens to columns with a DEFAULT?

By default they stay required. Tick the option for DEFAULT columns to be optional (?) and they become optional unless they are primary keys. That suits insert payloads more than row types.

Is it a full SQL parser?

No. It reads CREATE TABLE statements only and splits column definitions with simple rules. Unusual syntax can be misread, so check the output against your schema before committing it.