Skip to content

Commit 646ed1b

Browse files
committed
rewrite model to latest best practice
Signed-off-by: Grant Ramsay <[email protected]>
1 parent 008cd2c commit 646ed1b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

models.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
"""Define Models used in this example."""
22
from db import Base
3-
from sqlalchemy import Column, Integer, String
3+
from sqlalchemy import String
4+
from sqlalchemy.orm import Mapped, mapped_column
45

56

67
class User(Base):
78
"""Create a test table."""
89

910
__tablename__ = "users"
1011

11-
id = Column(Integer, primary_key=True, index=True)
12-
name = Column(String)
13-
email = Column(String, unique=True, index=True)
12+
id: Mapped[int] = mapped_column(primary_key=True)
13+
name: Mapped[str] = mapped_column(String(255))
14+
email: Mapped[str] = mapped_column(String(120), unique=True, index=True)
15+
16+
def __repr__(self) -> str:
17+
"""Define the model representation."""
18+
return f'User({self.id}, "{self.name}")'

0 commit comments

Comments
 (0)