Guest User

Untitled

a guest
Feb 3rd, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. from sqlalchemy.orm import Mapped, mapped_column, relationship
  2. from sqlalchemy import ForeignKey, create_engine
  3. from sqlalchemy.ext.declarative import declarative_base
  4.  
  5.  
  6. Base = declarative_base()
  7. engine = create_engine("postgresql://postgres:password@localhost:5432/trading")
  8.  
  9.  
  10. class Users(Base):
  11. __tablename__ = "users"
  12.  
  13. id: Mapped[int] = mapped_column(primary_key=True)
  14.  
  15. name: Mapped[str]
  16. age: Mapped[int]
  17. email: Mapped[str]
  18.  
  19. role_id: Mapped[int] = mapped_column(ForeignKey("roles.id"))
  20. roles: Mapped["Roles"] = relationship("role", backref="users")
  21.  
  22.  
  23. class Roles(Base):
  24. __tablename__ = "roles"
  25.  
  26. id: Mapped[int] = mapped_column(primary_key=True)
  27.  
  28. name: Mapped[str]
  29. permission: Mapped[str]
  30.  
  31. Base.metadata.create_all(engine)
  32.  
Advertisement
Add Comment
Please, Sign In to add comment