Skip to content

Commit

Permalink
fix database name, fix imports (direct -> utils) to catch situation w…
Browse files Browse the repository at this point in the history
…here psycopg is not installed
  • Loading branch information
akerlay committed Oct 10, 2024
1 parent 9212a5a commit 4e3ca11
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions peewee_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
PooledPostgresqlDatabase,
PooledPostgresqlExtDatabase,
PooledMySQLDatabase,
PooledPsycopg3PostgresqlDatabase,
Psycopg3Database,
)
from .pool import PostgresqlPoolBackend, MysqlPoolBackend
from .transactions import Transaction
Expand All @@ -44,6 +44,6 @@

register_database(PooledPostgresqlDatabase, 'postgres+pool+async', 'postgresql+pool+async')
register_database(PooledPostgresqlExtDatabase, 'postgresext+pool+async', 'postgresqlext+pool+async')
register_database(PooledPsycopg3PostgresqlDatabase, 'postgres+psycopg+pool+async', 'postgres+psycopg+pool+async')
register_database(Psycopg3Database, 'postgres+psycopg+pool+async', 'postgres+psycopg+pool+async')
register_database(PooledMySQLDatabase, 'mysql+pool+async')

2 changes: 1 addition & 1 deletion peewee_async/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def init(self, database: Optional[str], **kwargs: Any) -> None:
super().init(database, **kwargs)


class PooledPsycopg3PostgresqlDatabase(AioDatabase, peewee.PostgresqlDatabase):
class Psycopg3Database(AioDatabase, peewee.PostgresqlDatabase):
"""Extension for `peewee.PostgresqlDatabase` providing extra methods
for managing async connection based on psycopg3 pool backend.
Expand Down
7 changes: 2 additions & 5 deletions peewee_async/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import asyncio
from typing import Any, Optional, cast

import psycopg_pool
from psycopg import AsyncClientCursor

from .utils import aiopg, aiomysql, PoolProtocol, ConnectionProtocol, format_dsn
from .utils import aiopg, aiomysql, PoolProtocol, ConnectionProtocol, format_dsn, psycopg, psycopg_pool


class PoolBackend(metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -110,7 +107,7 @@ async def create(self) -> None:
max_lifetime=self.connect_params.get('pool_recycle', 60 * 60.0),
open=False,
kwargs={
'cursor_factory': AsyncClientCursor,
'cursor_factory': psycopg.AsyncClientCursor,
'autocommit': True,
}
)
Expand Down
2 changes: 2 additions & 0 deletions peewee_async/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

try:
import psycopg
import psycopg_pool
except ImportError:
psycopg = None # type: ignore
psycopg_pool = None # type: ignore

try:
import aiomysql
Expand Down
2 changes: 1 addition & 1 deletion tests/db_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
DB_CLASSES = {
'postgres-pool': peewee_async.PooledPostgresqlDatabase,
'postgres-pool-ext': peewee_async.PooledPostgresqlExtDatabase,
'psycopg-pool': peewee_async.PooledPsycopg3PostgresqlDatabase,
'psycopg-pool': peewee_async.Psycopg3Database,
'mysql-pool': peewee_async.PooledMySQLDatabase
}

0 comments on commit 4e3ca11

Please sign in to comment.