-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from romank0/psycopg-v3
Adds support for psycopg version 3
- Loading branch information
Showing
6 changed files
with
218 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
|
||
try: | ||
if os.getenv('PGPUBSUB_USE_PSYCOPG_V3', 'False') == 'True': | ||
raise ImportError() | ||
|
||
from psycopg2._psycopg import Notify | ||
|
||
class ConnectionWrapper: | ||
def __init__(self, conn): | ||
self.connection = conn | ||
|
||
def poll(self): | ||
self.connection.poll() | ||
|
||
@property | ||
def notifies(self): | ||
return self.connection.notifies | ||
|
||
@notifies.setter | ||
def notifies(self, value: Notify) -> None: | ||
self.connection.notifies = value | ||
|
||
def stop(self): | ||
pass | ||
|
||
except ImportError: | ||
from psycopg import Notify | ||
|
||
class ConnectionWrapper: | ||
def __init__(self, conn): | ||
self.connection = conn | ||
self.notifies = [] | ||
self.connection.add_notify_handler(self._notify_handler) | ||
|
||
def _notify_handler(self, notification): | ||
self.notifies.append(notification) | ||
|
||
def poll(self): | ||
self.connection.execute("SELECT 1") | ||
|
||
def stop(self): | ||
self.connection.remove_notify_handler(self._notify_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.