summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/pypostgresql.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pypostgresql.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
new file mode 100644
index 000000000..975006d92
--- /dev/null
+++ b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
@@ -0,0 +1,80 @@
+"""Support for the PostgreSQL database via py-postgresql.
+
+Connecting
+----------
+
+URLs are of the form `postgresql+pypostgresql://user@password@host:port/dbname[?key=value&key=value...]`.
+
+
+"""
+from sqlalchemy.engine import default
+import decimal
+from sqlalchemy import util
+from sqlalchemy import types as sqltypes
+from sqlalchemy.dialects.postgresql.base import PGDialect, PGDefaultRunner
+
+class PGNumeric(sqltypes.Numeric):
+ def bind_processor(self, dialect):
+ return None
+
+ def result_processor(self, dialect):
+ if self.asdecimal:
+ return None
+ else:
+ def process(value):
+ if isinstance(value, decimal.Decimal):
+ return float(value)
+ else:
+ return value
+ return process
+
+class PostgreSQL_pypostgresqlExecutionContext(default.DefaultExecutionContext):
+ pass
+
+class PostgreSQL_pypostgresqlDefaultRunner(PGDefaultRunner):
+ def execute_string(self, stmt, params=None):
+ return PGDefaultRunner.execute_string(self, stmt, params or ())
+
+class PostgreSQL_pypostgresql(PGDialect):
+ driver = 'pypostgresql'
+
+ supports_unicode_statements = True
+
+ supports_unicode_binds = True
+ description_encoding = None
+
+ defaultrunner = PostgreSQL_pypostgresqlDefaultRunner
+
+ default_paramstyle = 'format'
+
+ supports_sane_rowcount = False # alas....posting a bug now
+
+ supports_sane_multi_rowcount = False
+
+ execution_ctx_cls = PostgreSQL_pypostgresqlExecutionContext
+ colspecs = util.update_copy(
+ PGDialect.colspecs,
+ {
+ sqltypes.Numeric : PGNumeric,
+ sqltypes.Float: sqltypes.Float, # prevents PGNumeric from being used
+ }
+ )
+
+ @classmethod
+ def dbapi(cls):
+ from postgresql.driver import dbapi20
+ return dbapi20
+
+ def create_connect_args(self, url):
+ opts = url.translate_connect_args(username='user')
+ if 'port' in opts:
+ opts['port'] = int(opts['port'])
+ else:
+ opts['port'] = 5432
+ opts.update(url.query)
+ return ([], opts)
+
+ def is_disconnect(self, e):
+ return "connection is closed" in str(e)
+
+dialect = PostgreSQL_pypostgresql