DTLocal Dev ToolsPrivate browser utilities

Code generation tool

SQL DDL to SQLAlchemy ORM Converter

Paste PostgreSQL CREATE TABLE statements and generate SQLAlchemy 2.0 DeclarativeBase model code with Mapped typing, mapped_column, primary keys, unique constraints, ForeignKey references, nullable flags, and visible warnings for unsupported SQL.

This tool runs locally in your browser. Your input is not uploaded.

No uploadsNo server logsNo runtime APIsBrowser-only transforms

Primary key, varchar length, unique email, boolean default, and timestamp.

Generated SQLAlchemy output

Convert PostgreSQL CREATE TABLE DDL to generate SQLAlchemy 2.0 model code.
Options
Output options
MVP scope: PostgreSQL CREATE TABLE statements only. Unsupported constraints are ignored with warnings.

Examples

PostgreSQL CREATE TABLE example

A compact PostgreSQL table converted into SQLAlchemy 2.0 mapped columns.

CREATE TABLE users (
  id integer PRIMARY KEY,
  email varchar(255) NOT NULL UNIQUE,
  created_at timestamp NOT NULL
);

SQLAlchemy 2.0 output example

Shows UUID, ForeignKey, and Numeric precision mapping.

CREATE TABLE orders (
  id uuid PRIMARY KEY,
  user_id integer REFERENCES users(id),
  total numeric(10, 2) NOT NULL
);

How it works

  1. What this converter does: parses PostgreSQL CREATE TABLE statements and generates SQLAlchemy 2.0 DeclarativeBase model code.
  2. Supported PostgreSQL types: integer, bigint, smallint, varchar, text, boolean, numeric, real, double precision, timestamp, timestamptz, date, uuid, json, and jsonb are mapped to Python and SQLAlchemy types.
  3. SQLAlchemy 2.0 output example: generated code uses Mapped[], mapped_column(), __tablename__, primary_key, unique, nullable, and ForeignKey where parsed.
  4. Unsupported SQL is not evaluated and not executed; unsupported constraints are skipped with visible warnings.

Limitations

  • MVP supports PostgreSQL CREATE TABLE statements only and does not claim full SQL dialect support.
  • CHECK, EXCLUDE, GENERATED, COLLATE, indexes, triggers, and advanced constraints may require manual edits.
  • Complex DEFAULT expressions are emitted as server_default=text(...) with warnings for review.

FAQ

Does this converter execute my SQL?

No. It only parses CREATE TABLE text locally in your browser and never uses eval or a database connection.

Does it support every PostgreSQL feature?

No. The MVP focuses on common CREATE TABLE columns, primary keys, unique constraints, foreign keys, defaults, and common PostgreSQL types.

Can it convert multiple tables?

Yes, it attempts to parse multiple CREATE TABLE statements and shows a warning that multiple tables were converted.

Related tools