diff options
author | nathan <nathan.alexander.rice@gmail.com> | 2013-12-10 10:01:51 -0500 |
---|---|---|
committer | nathan <nathan.alexander.rice@gmail.com> | 2013-12-10 10:01:51 -0500 |
commit | f285b3536fe01f21409e201fbeeac559ab423a9d (patch) | |
tree | 88688e41ea285c7aaf91b8e71bd9f10c159d5807 /lib/sqlalchemy/dialects/postgresql/psycopg2.py | |
parent | ba73d619ca2199d96e92646021af3eb95186725e (diff) | |
download | sqlalchemy-f285b3536fe01f21409e201fbeeac559ab423a9d.tar.gz |
sqlalchemy/dialects/postgresql/pgjson:
- Fixed reference to HSTORE
- Corrected spelling of SQLAlchemy
sqlalchemy/dialects/postgresql/psycopg2:
- Added psycopg2 specific wrapper type for JSON which uses inherent json deserialization facilities
- Added code to detect and utilize the JSON wrapper if psycopg2 >= 2.5
test/dialect/postgresql/test_types:
- removed reference to use_native_hstore
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg2.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index d7ce6eb90..1f4078500 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -168,6 +168,8 @@ from __future__ import absolute_import import re import logging +import psycopg2.extensions as ext + from ... import util, exc import decimal from ... import processors @@ -179,6 +181,7 @@ from .base import PGDialect, PGCompiler, \ ENUM, ARRAY, _DECIMAL_TYPES, _FLOAT_TYPES,\ _INT_TYPES from .hstore import HSTORE +from .pgjson import JSON logger = logging.getLogger('sqlalchemy.dialects.postgresql') @@ -243,6 +246,17 @@ class _PGHStore(HSTORE): else: return super(_PGHStore, self).result_processor(dialect, coltype) + +class _PGJSON(JSON): + # I've omitted the bind processor here because the method of serializing + # involves registering specific types to auto-serialize, and the adapter + # just a thin wrapper over json.dumps. + def result_processor(self, dialect, coltype): + if dialect._has_native_json: + return None + else: + return super(_PGJSON, self).result_processor(dialect, coltype) + # When we're handed literal SQL, ensure it's a SELECT-query. Since # 8.3, combining cursors and "FOR UPDATE" has been fine. SERVER_SIDE_CURSOR_RE = re.compile( @@ -327,6 +341,7 @@ class PGDialect_psycopg2(PGDialect): psycopg2_version = (0, 0) _has_native_hstore = False + _has_native_json = False colspecs = util.update_copy( PGDialect.colspecs, @@ -336,6 +351,7 @@ class PGDialect_psycopg2(PGDialect): sqltypes.Enum: _PGEnum, # needs force_unicode ARRAY: _PGArray, # needs force_unicode HSTORE: _PGHStore, + JSON: _PGJSON } ) @@ -363,6 +379,7 @@ class PGDialect_psycopg2(PGDialect): self._has_native_hstore = self.use_native_hstore and \ self._hstore_oids(connection.connection) \ is not None + self._has_native_json = self.psycopg2_version >= (2, 5) @classmethod def dbapi(cls): |