Ready. Paste SQL queries or CREATE TABLE DDL statements.
Statements
0
DDL Tables
0
Parsed Columns
0
NOT NULL Fields
0

Parsed DDL Column Catalog

Table Column SQL Type Nullability Constraints
No DDL table columns parsed yet.

Technical Reference: Lexical SQL Formatting & DDL Schema Compilation

Backend engineers, analytics teams, and database reliability specialists routinely inspect schema migrations and multi-join queries containing proprietary table structures and customer-facing business metrics. Sending raw DDL scripts to remote formatting websites exposes internal database architectures unnecessarily. The ZERO.OPS SQL Formatter & DDL-to-Schema workbench executes lexical tokenization, indentation normalization, comment-stripping minification, and type compilation strictly in browser memory.

1. Literal-Safe Lexical Tokenization

Regex-based SQL formatters break whenever string literals contain words like select, from, or -- comment markers. ZERO.OPS scans the input character-by-character into typed lexical tokens: whitespace, single-line comments (-- ...), block comments (/* ... */), single-quoted string literals with escaped quotes ('' or \'), double-quoted or backtick identifiers, numeric literals, multi-character operators (<>, !=, ::, ->>), and SQL keywords. Keyword casing transformations (UPPER, lower, or preserve) apply strictly to keyword tokens, guaranteeing that string constants and case-sensitive quoted column names remain unaltered.

2. Clause Indentation & Comment-Safe Minification

During beautification, major query clauses (SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, WITH, and UNION) align cleanly while boolean predicates (AND, OR, ON) receive nested sub-indentation. Inside CREATE TABLE (...) declarations, top-level comma boundaries place each column and table constraint on its own indented line while keeping parameterized types like DECIMAL(12, 2) intact. Minification strips SQL comments and collapses redundant whitespace while inserting single-space separators solely between adjacent alphanumeric or word-like tokens.

3. CREATE TABLE DDL AST Extraction

To generate application contracts from database schemas, the parser locates every CREATE TABLE block (supporting IF NOT EXISTS, TEMPORARY, and optional schema.table qualifiers) and splits top-level comma-delimited entries while tracking nested parentheses for DECIMAL(p,s), ENUM(...), and CHECK (...) expressions. Table-level constraints such as composite PRIMARY KEY (col1, col2), FOREIGN KEY, and UNIQUE are separated from column definitions and propagated back onto the referenced columns so composite primary keys automatically become non-nullable.

4. Deterministic JSON Schema & TypeScript Mapping

Extracted columns compile simultaneously to JSON Schema Draft 2020-12 and TypeScript interfaces using an explicit type projection table:

INT/SERIAL -> integer / number | DECIMAL/FLOAT -> number | BOOL -> boolean | UUID/DATE/TIMESTAMPTZ -> string (with format) | JSONB -> object / Record<string, unknown>

PostgreSQL array suffixes ([]) wrap the target type in JSON Schema array items and TypeScript T[] syntax, while VARCHAR(n) propagates maxLength: n constraints. Columns marked NOT NULL or PRIMARY KEY populate the JSON Schema required array and emit non-nullable TypeScript properties, whereas nullable columns emit explicit [type, "null"] schemas and T | null unions so API validators and frontend models stay synchronized with database constraints.

5. Multi-Table Bundles, Dialect Coverage & Contract Drift Prevention

When an input script declares multiple CREATE TABLE definitions—such as normalized order headers, line items, and audit events—the JSON Schema generator automatically switches from a single top-level schema object to a Draft 2020-12 $defs bundle keyed by table name, while the TypeScript emitter outputs one exported PascalCase interface per table in source order. Each generated TypeScript property carries an inline SQL type and primary-key annotation comment so reviewers can trace precision loss risks—such as BIGINT or DECIMAL(18,4) monetary columns mapped to IEEE-754 JavaScript number—during code review.

6. Safe Handling of Identifiers, Comments & Default Expressions

Database migrations frequently mix double-quoted PostgreSQL identifiers, backtick-quoted MySQL column names, and inline documentation comments. By preserving quoted identifier casing during AST extraction and stripping comments only during SQL minification, ZERO.OPS ensures that production query rewrites remain syntactically faithful across dialects without leaking internal table schemas to external formatting APIs.