diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/asyncpg.py | 17 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pg8000.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg.py | 4 |
3 files changed, 25 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py index a84bece4f..4cc04d20a 100644 --- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py +++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py @@ -741,6 +741,12 @@ class AsyncAdapt_asyncpg_connection(AdaptedConnection): else: self.isolation_level = self._isolation_setting + def ping(self): + try: + _ = self.await_(self._connection.fetchrow(";")) + except Exception as error: + self._handle_exception(error) + def set_isolation_level(self, level): if self._started: self.rollback() @@ -996,6 +1002,17 @@ class PGDialect_asyncpg(PGDialect): util.coerce_kw_type(opts, "port", int) return ([], opts) + def do_ping(self, dbapi_connection): + try: + dbapi_connection.ping() + except self.dbapi.Error as err: + if self.is_disconnect(err, dbapi_connection, None): + return False + else: + raise + else: + return True + @classmethod def get_pool_class(cls, url): diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index ce9a3bb6c..d4b159b73 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -559,5 +559,9 @@ class PGDialect_pg8000(PGDialect): else: return None + @util.memoized_property + def _dialect_specific_select_one(self): + return ";" + dialect = PGDialect_pg8000 diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg.py b/lib/sqlalchemy/dialects/postgresql/psycopg.py index 633357a74..371bf2bc2 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg.py @@ -505,6 +505,10 @@ class PGDialect_psycopg(_PGDialect_common_psycopg): else: self.do_commit(connection.connection) + @util.memoized_property + def _dialect_specific_select_one(self): + return ";" + class AsyncAdapt_psycopg_cursor: __slots__ = ("_cursor", "await_", "_rows") |