diff options
author | Kaolin Imago Fire <kaolin@amazon.com> | 2015-05-15 16:56:49 -0700 |
---|---|---|
committer | Kaolin Imago Fire <kaolin@amazon.com> | 2015-05-15 16:56:49 -0700 |
commit | 193d9fba32f71deb5492035109d54447a92964c4 (patch) | |
tree | ea648c485a37097b54f1b387cce17cbcc611417a | |
parent | d178707ecaeb547470e2b7b37b9a939abc69cbd0 (diff) | |
download | sqlalchemy-pr/172.tar.gz |
initial stab at pygresql dialect based on psycopg2pr/172
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/__init__.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pygresql.py | 79 |
2 files changed, 80 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/__init__.py b/lib/sqlalchemy/dialects/postgresql/__init__.py index 98fe6f085..b729d5020 100644 --- a/lib/sqlalchemy/dialects/postgresql/__init__.py +++ b/lib/sqlalchemy/dialects/postgresql/__init__.py @@ -5,7 +5,7 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -from . import base, psycopg2, pg8000, pypostgresql, zxjdbc, psycopg2cffi +from . import base, psycopg2, pg8000, pypostgresql, zxjdbc, psycopg2cffi, pygresql base.dialect = psycopg2.dialect diff --git a/lib/sqlalchemy/dialects/postgresql/pygresql.py b/lib/sqlalchemy/dialects/postgresql/pygresql.py new file mode 100644 index 000000000..8d6c655ec --- /dev/null +++ b/lib/sqlalchemy/dialects/postgresql/pygresql.py @@ -0,0 +1,79 @@ +# postgresql/pygresql.py +# Copyright (C) 2005-2015 the SQLAlchemy authors and contributors +# <see AUTHORS file> +# +# This module is part of SQLAlchemy and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + +""" +.. dialect:: postgresql+pygresql + :name: py-pygresql + :dbapi: pygresql + :connectstring: postgresql+pygresql://user:password@host:port/dbname\ +[?key=value&key=value...] + :url: http://python.projects.pgfoundry.org/ + + +""" +from ... import util +from ... import types as sqltypes +from .base import PGDialect, PGExecutionContext +from ... import processors + + +class PGNumeric(sqltypes.Numeric): + def bind_processor(self, dialect): + return processors.to_str + + def result_processor(self, dialect, coltype): + if self.asdecimal: + return None + else: + return processors.to_float + + +class PGExecutionContext_pygresql(PGExecutionContext): + pass + + +class PGDialect_pygresql(PGDialect): + driver = 'pygresql' + + supports_unicode_statements = True + supports_unicode_binds = True + description_encoding = None + default_paramstyle = 'pyformat' + + # requires trunk version to support sane rowcounts + # TODO: use dbapi version information to set this flag appropriately + supports_sane_rowcount = True + supports_sane_multi_rowcount = False + + execution_ctx_cls = PGExecutionContext_pygresql + colspecs = util.update_copy( + PGDialect.colspecs, + { + sqltypes.Numeric: PGNumeric, + + # prevents PGNumeric from being used + sqltypes.Float: sqltypes.Float, + } + ) + + @classmethod + def dbapi(cls): + import pgdb + return pgdb + + def create_connect_args(self, url): + opts = url.translate_connect_args(username='user') + if 'port' in opts: + opts['host'] = ":".join((opts['host'],str(opts.pop('port')))) + opts.pop('port',None) + opts.update(url.query) + return ([], opts) + + def is_disconnect(self, e, connection, cursor): + return "connection is closed" in str(e) + +dialect = PGDialect_pygresql |