Pan*_*nda 7 python sqlalchemy python-typing
我想为我的 SQLAlchemy 基类使用类型,但似乎找不到类型定义。
例如:
from sqlalchemy.types import BigInteger
from sqlalchemy.schema import Column, Index
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
__tablename__ = "users"
id_user = Column(
BigInteger, primary_key=True, autoincrement=True, nullable=False, index=True
)
username = Column(String, unique=True, index=True)
Run Code Online (Sandbox Code Playgroud)
现在,当引用这个 User 类时,我不知道该使用什么类型。此外,如果我想要一个包含 table_name 的字典:模型映射如下:
from typing import Any, Dict
table_model_map: Dict[str, Any] = {
"users": User,
"another_table": AnotherTableModel,
}
Run Code Online (Sandbox Code Playgroud)
我将如何定义这个字典的类型
非常感谢您帮助我理解这一点!