在Sqlalchemy中实现枚举的最佳方法是什么?

11 浏览
0 Comments

在Sqlalchemy中实现枚举的最佳方法是什么?

我正在阅读有关SQLAlchemy的内容,我看到了以下代码:

employees_table = Table('employees', metadata,
    Column('employee_id', Integer, primary_key=True),
    Column('name', String(50)),
    Column('manager_data', String(50)),
    Column('engineer_info', String(50)),
    Column('type', String(20), nullable=False)
)
employee_mapper = mapper(Employee, employees_table, \
    polymorphic_on=employees_table.c.type, polymorphic_identity='employee')
manager_mapper = mapper(Manager, inherits=employee_mapper, polymorphic_identity='manager')
engineer_mapper = mapper(Engineer, inherits=employee_mapper, polymorphic_identity='engineer')

我应该将'type'变成一个带有常量的整数库吗?还是只需将'type'变成枚举类型即可?

0