Skip to content

Instantly share code, notes, and snippets.

@mansha99
Created September 5, 2023 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mansha99/5f038932f39b6539be2d4fc6a44a8e1a to your computer and use it in GitHub Desktop.
Save mansha99/5f038932f39b6539be2d4fc6a44a8e1a to your computer and use it in GitHub Desktop.
using DeclarativeBase to define Models of ORM in SQLAlchemy
from sqlalchemy import String
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy import Integer,String,Float
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
class Base(DeclarativeBase):
pass
class Planet(Base):
__tablename__ = "planet"
id: Mapped[int] = mapped_column(Integer,primary_key=True)
name: Mapped[str] = mapped_column(String(32))
diameter: Mapped[float] = mapped_column(Float)
def __repr__(self) -> str:
return f"Planet [ Id: {self.id}, Name: {self.name}, Diameter: {self.diameter} ]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment