diff options
author | Federico Caselli <cfederico87@gmail.com> | 2021-03-10 23:54:52 +0100 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-15 20:11:20 -0400 |
commit | dfa1d3b28f1a0abf1e11c76a94f7a65bf98d29af (patch) | |
tree | 975a06018edcc9a9fa75b709f40698842a82e494 /lib/sqlalchemy/testing/schema.py | |
parent | 28b0b6515af26ee3ba09600a8212849b2dae0699 (diff) | |
download | sqlalchemy-dfa1d3b28f1a0abf1e11c76a94f7a65bf98d29af.tar.gz |
CAST the elements in ARRAYs when using psycopg2
Adjusted the psycopg2 dialect to emit an explicit PostgreSQL-style cast for
bound parameters that contain ARRAY elements. This allows the full range of
datatypes to function correctly within arrays. The asyncpg dialect already
generated these internal casts in the final statement. This also includes
support for array slice updates as well as the PostgreSQL-specific
:meth:`_postgresql.ARRAY.contains` method.
Fixes: #6023
Change-Id: Ia7519ac4371a635f05ac69a3a4d0f4e6d2f04cad
Diffstat (limited to 'lib/sqlalchemy/testing/schema.py')
-rw-r--r-- | lib/sqlalchemy/testing/schema.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/schema.py b/lib/sqlalchemy/testing/schema.py index 22b1f7b77..fee021cff 100644 --- a/lib/sqlalchemy/testing/schema.py +++ b/lib/sqlalchemy/testing/schema.py @@ -5,11 +5,14 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php +import sys + from . import config from . import exclusions from .. import event from .. import schema from .. import types as sqltypes +from ..util import OrderedDict __all__ = ["Table", "Column"] @@ -162,3 +165,41 @@ def _truncate_name(dialect, name): ) else: return name + + +def pep435_enum(name): + # Implements PEP 435 in the minimal fashion needed by SQLAlchemy + __members__ = OrderedDict() + + def __init__(self, name, value, alias=None): + self.name = name + self.value = value + self.__members__[name] = self + value_to_member[value] = self + setattr(self.__class__, name, self) + if alias: + self.__members__[alias] = self + setattr(self.__class__, alias, self) + + value_to_member = {} + + @classmethod + def get(cls, value): + return value_to_member[value] + + someenum = type( + name, + (object,), + {"__members__": __members__, "__init__": __init__, "get": get}, + ) + + # getframe() trick for pickling I don't understand courtesy + # Python namedtuple() + try: + module = sys._getframe(1).f_globals.get("__name__", "__main__") + except (AttributeError, ValueError): + pass + if module is not None: + someenum.__module__ = module + + return someenum |