Since Python 3.4 is adding support for enums to the standard library,
I wrote a TypeDecorator for it:

import sqlalchemy.types as types


class PythonEnum(types.TypeDecorator):

    impl = types.Enum

    def __init__(self, enum_class, **kw):
        super().__init__(*(m.name for m in enum_class), **kw)
        self._enum_class = enum_class

    def process_bind_param(self, value, dialect):
        return value.name

    def process_result_value(self, value, dialect):
        return self._enum_class[value]

    @property
    def python_type(self):
        return self._enum_class


Comments welcome.  Is this something that should be added to sqlalchemy?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to