SQL DDL to Python SQLAlchemy 2.0 Model Generator
Convert SQL CREATE TABLE statements into strongly-typed Python SQLAlchemy 2.0 DeclarativeBase models with Mapped annotations.
"""
SQLAlchemy 2.0 DeclarativeBase Models
Generated by ToolsAA SQL to SQLAlchemy Generator
Dialect: POSTGRES | Generated Tables: 6
"""
from typing import Any, List, Optional
import uuid
import enum
from sqlalchemy import (
BigInteger,
Boolean,
Date,
DateTime,
Float,
ForeignKey,
Index,
Integer,
Numeric,
SmallInteger,
String,
Text,
Time,
UniqueConstraint,
func,
text,
)
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
class Base(DeclarativeBase):
pass
class UserRole(str, enum.Enum):
CUSTOMER = "CUSTOMER"
ADMIN = "ADMIN"
VENDOR = "VENDOR"
class OrderStatus(str, enum.Enum):
PENDING = "PENDING"
PAID = "PAID"
PROCESSING = "PROCESSING"
SHIPPED = "SHIPPED"
DELIVERED = "DELIVERED"
CANCELLED = "CANCELLED"
class User(Base):
__tablename__ = "users"
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default="gen_random_uuid(")
def __repr__(self) -> str:
return f"<User(id={self.id!r})>"
class UserProfile(Base):
__tablename__ = "user_profiles"
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default="gen_random_uuid(")
def __repr__(self) -> str:
return f"<UserProfile(id={self.id!r})>"
class Product(Base):
__tablename__ = "products"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
sku: Mapped[Optional[str]] = mapped_column(nullable=True)
def __repr__(self) -> str:
return f"<Product(id={self.id!r}, sku={self.sku!r})>"
class Order(Base):
__tablename__ = "orders"
__table_args__ = (
Index("idx_orders_customer", "customer_id"),
)
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default="gen_random_uuid(")
# Relationships
order_items: Mapped[List["OrderItem"]] = relationship(back_populates="order", cascade="all, delete-orphan")
def __repr__(self) -> str:
return f"<Order(id={self.id!r})>"
class OrderItem(Base):
__tablename__ = "order_items"
__table_args__ = (
Index("idx_order_items_order", "order_id"),
)
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
order_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("orders.id"), nullable=False)
# Relationships
order: Mapped["Order"] = relationship(back_populates="order_items")
def __repr__(self) -> str:
return f"<OrderItem(id={self.id!r}, order_id={self.order_id!r})>"
class AuditLog(Base):
__tablename__ = "audit_logs"
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
action: Mapped[Optional[str]] = mapped_column(nullable=True)
def __repr__(self) -> str:
return f"<AuditLog(id={self.id!r}, action={self.action!r})>"Zero-Knowledge Local Execution
All data processing, parsing, and compilation execute strictly inside your local browser memory. Zero external server uploads.
Sub-Millisecond AST Engine
All data payloads remain strictly local with zero external server communication.
Production Ready Export
Clean, optimized output formats ready for immediate deployment.