Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spoqa/sqlalchemy-enum34
SQLAlchemy type to store standard enum.Enum values
https://github.com/spoqa/sqlalchemy-enum34
databases enum orm python sqlalchemy
Last synced: 2 months ago
JSON representation
SQLAlchemy type to store standard enum.Enum values
- Host: GitHub
- URL: https://github.com/spoqa/sqlalchemy-enum34
- Owner: spoqa
- License: mit
- Created: 2015-07-30T13:51:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-14T04:29:35.000Z (over 3 years ago)
- Last Synced: 2024-04-24T14:30:01.777Z (8 months ago)
- Topics: databases, enum, orm, python, sqlalchemy
- Language: Python
- Homepage: https://pypi.python.org/pypi/SQLAlchemy-Enum34
- Size: 16.6 KB
- Stars: 49
- Watchers: 27
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
SQLAlchemy-Enum34
=================.. image:: https://badge.fury.io/py/SQLAlchemy-Enum34.svg?
:target: https://pypi.python.org/pypi/SQLAlchemy-Enum34
.. image:: https://travis-ci.org/spoqa/sqlalchemy-enum34.svg?branch=master
:target: https://travis-ci.org/spoqa/sqlalchemy-enum34
.. image:: https://codecov.io/github/spoqa/sqlalchemy-enum34/coverage.svg?branch=master
:target: https://codecov.io/github/spoqa/sqlalchemy-enum34?branch=masterThis package provides a SQLAlchemy type to store values of standard
``enum.Enum`` (which became a part of standard library since Python 3.4).
Its internal representation is equivalent to SQLAlchemy's built-in
``sqlalchemy.types.Enum``, but its Python representation is not
a ``str`` but ``enum.Enum``.Note that this works on Python 2.6 as well as 3.4, the latest version of
Python, through enum34_ package.The following example shows how enum_-typed columns can be declared::
import enum
from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_enum34 import EnumTypeBase = declarative_base()
class Color(enum.Enum):
black = 'black'
white = 'white'
navy = 'navy'
red = 'red'class Size(enum.Enum):
small = 'S'
medium = 'M'
large = 'L'
xlarge = 'XL'class Shirt(Base):
id = Column(Integer, primary_key=True)
color = Column(EnumType(Color), nullable=False)
size = Column(EnumType(Size, name='shirt_size'), nullable=False)And the following REPL session shows how these columns work:
>>> shirt = session.query(Shirt).filter(Shirt.color == Color.navy).first()
>>> shirt.color>>> shirt.size
Written by `Hong Minhee`_ at Spoqa_, and distributed under MIT license.
.. _enum34: https://pypi.python.org/pypi/enum34
.. _enum: https://docs.python.org/3/library/enum.html
.. _Hong Minhee: http://hongminhee.org/
.. _Spoqa: http://www.spoqa.com/