diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-08 12:56:43 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-08 18:00:18 -0400 |
commit | c86b95038d84b40617fccd485e4596da4b139f5a (patch) | |
tree | 520108197c050038766a6a6a8bd83e1673733887 /lib/sqlalchemy/dialects/postgresql/pg8000.py | |
parent | 03560c4b83308719067ec635662c35f9a437fb7f (diff) | |
download | sqlalchemy-c86b95038d84b40617fccd485e4596da4b139f5a.tar.gz |
Enable uuid for pg8000
Enabled UUID support for the pg8000 driver, which supports native Python
uuid round trips for this datatype. Arrays of UUID are still not supported,
however.
Change-Id: I44ca323c5d9f2cd87327210233bc36a3556eb050
Fixes: #4016
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/pg8000.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pg8000.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 5f6cd0a3f..3ec7798c3 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -70,11 +70,16 @@ from ... import processors from ... import types as sqltypes from .base import ( PGDialect, PGCompiler, PGIdentifierPreparer, PGExecutionContext, - _DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES) + _DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES, UUID) import re from sqlalchemy.dialects.postgresql.json import JSON from ...sql.elements import quoted_name +try: + from uuid import UUID as _python_UUID +except ImportError: + _python_UUID = None + class _PGNumeric(sqltypes.Numeric): def result_processor(self, dialect, coltype): @@ -113,6 +118,24 @@ class _PGJSON(JSON): return super(_PGJSON, self).result_processor(dialect, coltype) +class _PGUUID(UUID): + def bind_processor(self, dialect): + if not self.as_uuid: + def process(value): + if value is not None: + value = _python_UUID(value) + return value + return process + + def result_processor(self, dialect, coltype): + if not self.as_uuid: + def process(value): + if value is not None: + value = str(value) + return value + return process + + class PGExecutionContext_pg8000(PGExecutionContext): pass @@ -156,7 +179,8 @@ class PGDialect_pg8000(PGDialect): sqltypes.Numeric: _PGNumericNoBind, sqltypes.Float: _PGNumeric, JSON: _PGJSON, - sqltypes.JSON: _PGJSON + sqltypes.JSON: _PGJSON, + UUID: _PGUUID } ) |