We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We have a lot of stringly-typed enums, and this can be error-prone. We should use enums instead.
Using enums could have other benefits, such as a method that makes a human-readable string of the enum (e.g. Role.lab_assistant -> "lab assistant").
Role.lab_assistant -> "lab assistant"
Here's how to hook it up to SQLAlchemy (stolen from the OH app):
class EnumType(db.TypeDecorator): impl = db.String(255) def __init__(self, enum_class): super(EnumType, self).__init__(self) self.enum_class = enum_class def process_bind_param(self, enum_value, dialect): return enum_value.name def process_result_value(self, name, dialect): return self.enum_class[name] @property def python_type(self): return self.enum_class ... Role = enum.Enum('Role', ['student', 'lab assistant', ...]) class MyModel(db.Model): my_enum_column = db.Column(EnumType(Role), nullable=False, index=True)
The text was updated successfully, but these errors were encountered:
This also looks easier if we need to update the table/run a migration.
Sorry, something went wrong.
No branches or pull requests
We have a lot of stringly-typed enums, and this can be error-prone. We should use enums instead.
Using enums could have other benefits, such as a method that makes a human-readable string of the enum (e.g.
Role.lab_assistant -> "lab assistant"
).Here's how to hook it up to SQLAlchemy (stolen from the OH app):
The text was updated successfully, but these errors were encountered: