summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2017-08-17 09:14:07 -0400
committerGerrit Code Review <gerrit@awstats.zzzcomputing.com>2017-08-17 09:14:07 -0400
commitd173662fe01fe4c952370ad52f34b03145ffa17a (patch)
treeecb706867575c40a56a88e1e64633c47e9773e0e /lib/sqlalchemy/dialects
parenteb8db2303b1677d49fc68a8ee299061e8cfc2b31 (diff)
parentc86b95038d84b40617fccd485e4596da4b139f5a (diff)
downloadsqlalchemy-d173662fe01fe4c952370ad52f34b03145ffa17a.tar.gz
Merge "Enable uuid for pg8000"
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pg8000.py28
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
}
)