Skip to content
New issue

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

Simple Enum support (#502) #585

Open
wants to merge 43 commits into
base: orm
Choose a base branch
from

Conversation

luckydonald
Copy link

@luckydonald luckydonald commented Jan 30, 2021

This is a pull request for tracking the work for #502.


The way it works is actually quite simple:

In python, enums are a subtype of both Enum, and a base type (int, str, bool, etc.)
In other words code:

value = SomeEnum.SOME_VALUE

isinstance(value, int) == True

This means we can simply use those values which is backing the enums as database values.

All this PR does is checking the enum type for what the underlying type would be processed as (self._get_real_converter(py_type, attr)), and store that converter internally (self.converter).

Now all the fancy converter methods (py2sql, sql2py, val2dbval, …) will be forwarded to that chosen converter.

That's it.

Bonus feature: It chooses the size of the integer or string colums correctly if you don't provide those.

@luckydonald luckydonald marked this pull request as draft January 30, 2021 00:24
@luckydonald luckydonald marked this pull request as ready for review January 31, 2021 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant