From 2e51ef7621402345a7adf3152f1935bd075ccf95 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 12 Nov 2020 01:02:15 +0000 Subject: [PATCH] More Connection documentation. --- docs/connection.rst | 9 ++++++++- psycopg3/psycopg3/connection.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/connection.rst b/docs/connection.rst index 16067494f..5ccb9f7a0 100644 --- a/docs/connection.rst +++ b/docs/connection.rst @@ -69,7 +69,7 @@ Take a look to :ref:`transactions` for the details. TODO - .. rubric:: Methods you will need if you do something cool + .. rubric:: Methods you can use to do something cool .. automethod:: notifies @@ -82,6 +82,12 @@ Take a look to :ref:`transactions` for the details. See :ref:`async-notify` for details. + .. automethod:: cancel + .. automethod:: add_notice_handler + .. automethod:: remove_notice_handler + + TODO: document `Diagnostic` + .. autoclass:: AsyncConnection @@ -103,3 +109,4 @@ Take a look to :ref:`transactions` for the details. .. autoclass:: Notify + :members: channel, payload, pid diff --git a/psycopg3/psycopg3/connection.py b/psycopg3/psycopg3/connection.py index 9ef0c9935..dd1b04f45 100644 --- a/psycopg3/psycopg3/connection.py +++ b/psycopg3/psycopg3/connection.py @@ -46,8 +46,13 @@ class Notify(NamedTuple): """An asynchronous notification received from the database.""" channel: str + """The name of the channel on which the notification was received.""" + payload: str + """The message attached to the notification.""" + pid: int + """The PID of the backend process which sent the notification.""" NoticeHandler = Callable[[e.Diagnostic], None] @@ -138,13 +143,20 @@ class BaseConnection: raise NotImplementedError def cancel(self) -> None: + """Cancel the current operation on the connection.""" c = self.pgconn.get_cancel() c.cancel() def add_notice_handler(self, callback: NoticeHandler) -> None: + """ + Register a callable to be invoked when a notice message is received. + """ self._notice_handlers.append(callback) def remove_notice_handler(self, callback: NoticeHandler) -> None: + """ + Unregister a notice message callable previously registered. + """ self._notice_handlers.remove(callback) @staticmethod -- 2.47.3