Finding Python types for Columns #97
-
Hi, thanks for this function just as I started putting together one of my own. Regarding this code: pydantic-sqlalchemy/pydantic_sqlalchemy/main.py Lines 24 to 30 in 8667e21 Have you looked at the typing.get_type_hints() function? Perhaps else:
python_types = typing.get_type_hints(db_model)
python_type = python_types[column.name] works for you as well? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
from sqlalchemy.sql import sqltypes ...def python_type_for_column(db_model, column): |
Beta Was this translation helpful? Give feedback.
-
Thanks for the patience with my reply! 😅 I deprecated this library a while ago in favor of SQLModel which would solve all the same use cases in a much better way, and I'm directing all the effort in that direction. SQLModel uses Pydantic models to define both data and table (SQL) models, so it's easier to do all these things. 🚀 That also means it uses all the nice type annotations utils from Pydantic. 🤓 |
Beta Was this translation helpful? Give feedback.
Thanks for the patience with my reply! 😅
I deprecated this library a while ago in favor of SQLModel which would solve all the same use cases in a much better way, and I'm directing all the effort in that direction.
SQLModel uses Pydantic models to define both data and table (SQL) models, so it's easier to do all these things. 🚀
That also means it uses all the nice type annotations utils from Pydantic. 🤓