PostgreSQL CREATE TABLE to SQLModel
Paste a PostgreSQL CREATE TABLE and get a SQLModel class (table=True) that doubles as your Pydantic schema and your ORM table. Primary key becomes a Field, nullable columns become Optional, NUMERIC maps to Decimal.
Built from your real DDL, on the server, discarded after the response.
Example
CREATE TABLE product (
id BIGSERIAL PRIMARY KEY,
sku VARCHAR(40) UNIQUE NOT NULL,
name VARCHAR(200) NOT NULL,
price NUMERIC(12, 2) NOT NULL,
in_stock BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP NOT NULL DEFAULT now()
);
from datetime import datetime
from decimal import Decimal
from sqlmodel import Field, SQLModel
class Product(SQLModel, table=True):
__tablename__ = "product"
id: int | None = Field(default=None, primary_key=True)
sku: str = Field(unique=True, max_length=40)
name: str = Field(max_length=200)
price: Decimal = Field(max_digits=12, decimal_places=2)
in_stock: bool
created_at: datetime