summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/pg8000.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/pg8000.py')
-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
}
)