Skip to content

Commit

Permalink
Initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Feb 2, 2024
1 parent 4e168e4 commit 7163fa5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions python/sdssdb/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from sqlalchemy.orm import scoped_session, sessionmaker

import peewee
from peewee import OperationalError, PostgresqlDatabase
from peewee import OperationalError
from playhouse.pool import PooledPostgresqlExtDatabase
from playhouse.postgres_ext import ArrayField
from playhouse.reflection import Introspector, UnknownField

Expand Down Expand Up @@ -357,7 +358,7 @@ def post_connect(self):
pass


class PeeweeDatabaseConnection(DatabaseConnection, PostgresqlDatabase):
class PeeweeDatabaseConnection(DatabaseConnection, PooledPostgresqlExtDatabase):
"""Peewee database connection implementation.
Attributes
Expand All @@ -376,8 +377,12 @@ def __init__(self, *args, **kwargs):
self._metadata = {}

autorollback = kwargs.pop('autorollback', True)
max_connections = kwargs.pop('max_connections', 10)
stale_timeout = kwargs.pop('stale_timeout', None)

PostgresqlDatabase.__init__(self, None, autorollback=autorollback)
PooledPostgresqlExtDatabase.__init__(self, None, autorollback=autorollback,
stale_timeout=stale_timeout,
max_connections=max_connections)
DatabaseConnection.__init__(self, *args, **kwargs)

@property
Expand Down Expand Up @@ -408,16 +413,16 @@ def _conn(self, dbname, silent_on_fail=False, **params):
except pgpasslib.FileNotFound:
params['password'] = None

PostgresqlDatabase.init(self, dbname, **params)
PooledPostgresqlExtDatabase.init(self, dbname, **params)
self._metadata = {}

try:
PostgresqlDatabase.connect(self)
PooledPostgresqlExtDatabase.connect(self)
self.dbname = dbname
except OperationalError as ee:
if not silent_on_fail:
log.warning(f'failed to connect to database {self.database!r}: {ee}')
PostgresqlDatabase.init(self, None)
PooledPostgresqlExtDatabase.init(self, None)

if self.is_connection_usable() and self.auto_reflect:
with self.atomic():
Expand Down

0 comments on commit 7163fa5

Please sign in to comment.