diff --git a/db_wrapper/connection.py b/db_wrapper/connection.py index 2c4ae05..731592a 100644 --- a/db_wrapper/connection.py +++ b/db_wrapper/connection.py @@ -24,6 +24,7 @@ class ConnectionParameters: """Defines connection parameters for database.""" host: str + port: int user: str password: str database: str @@ -37,15 +38,16 @@ async def _try_connect( user = connection_params.user password = connection_params.password host = connection_params.host + port = connection_params.port - dsn = f'dbname={database} user={user} password={password} host={host}' + dsn = f'dbname={database} user={user} password={password} host={host} port={port}' # PENDS python 3.9 support in pylint # pylint: disable=unsubscriptable-object connection: Optional[aiopg.Connection] = None LOGGER.info( - f'Attempting to connect to database {database} as {user}@{host}...') + f'Attempting to connect to database {database} as {user}@{host}:{port}...') while connection is None: try: diff --git a/example/example/example.py b/example/example/example.py index 372037b..ab29399 100644 --- a/example/example/example.py +++ b/example/example/example.py @@ -2,6 +2,7 @@ import asyncio import json +import logging import os from uuid import uuid4, UUID from typing import Any, List @@ -10,6 +11,8 @@ from models import AModel, ExtendedModel, ExtendedModelData +logging.basicConfig(level=logging.INFO) + class UUIDJsonEncoder(json.JSONEncoder): """Extended Json Encoder to allow encoding of objects containing UUID.""" @@ -23,6 +26,7 @@ def default(self, obj: Any) -> Any: conn_params = ConnectionParameters( host=os.getenv('DB_HOST', 'localhost'), + port=int(os.getenv('DB_PORT', '5432')), # user=os.getenv('DB_USER', 'postgres'), # password=os.getenv('DB_PASS', 'postgres'), # database=os.getenv('DB_NAME', 'postgres')) diff --git a/example/manage.py b/example/manage.py index c95a88d..4c8b7bc 100644 --- a/example/manage.py +++ b/example/manage.py @@ -14,11 +14,11 @@ import time from typing import Any, Optional, Generator, List, Tuple -from migra import Migration # type: ignore +from migra import Migration from psycopg2 import connect, OperationalError # type: ignore from psycopg2 import sql from psycopg2.sql import Composed -from sqlbag import ( # type: ignore +from sqlbag import ( S, load_sql_from_folder) @@ -170,13 +170,13 @@ def _get_schema_diff( def _temp_db(host: str, user: str, password: str) -> Generator[str, Any, Any]: """Create, yield, & remove a temporary database as context.""" connection = _resilient_connect( - f'postgres://{user}:{password}@{host}/{DB_NAME}') + f'postgresql://{user}:{password}@{host}/{DB_NAME}') connection.set_session(autocommit=True) name = _temp_name() with connection.cursor() as cursor: _create_db(cursor, name) - yield f'postgres://{user}:{password}@{host}/{name}' + yield f'postgresql://{user}:{password}@{host}/{name}' _drop_db(cursor, name) connection.close() diff --git a/example/requirements/prod.txt b/example/requirements/prod.txt index 773c6f6..3ef5cfd 100644 --- a/example/requirements/prod.txt +++ b/example/requirements/prod.txt @@ -1,2 +1,2 @@ psycopg2-binary>=2.8.6,<3.0.0 -https://github.com/cheese-drawer/lib-python-db-wrapper/releases/download/2.0.1/db_wrapper-2.0.1-py3-none-any.whl +https://github.com/cheese-drawer/lib-python-db-wrapper/releases/download/2.0.2/db_wrapper-2.0.2-py3-none-any.whl diff --git a/setup.py b/setup.py index b22bbeb..4e015f6 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="db_wrapper", - version="2.0.1", + version="2.0.2", author="Andrew Chang-DeWitt", author_email="andrew@andrew-chang-dewitt.dev", description="Simple wrapper on aiopg to handle postgres connections & basic Models.", diff --git a/test/helpers.py b/test/helpers.py index 4499c9b..ce64351 100644 --- a/test/helpers.py +++ b/test/helpers.py @@ -44,5 +44,5 @@ def wrapped(instance: Any) -> None: def get_client() -> Client: """Create a client with placeholder connection data.""" - conn_params = ConnectionParameters('a', 'a', 'a', 'a') + conn_params = ConnectionParameters('a', 'a', 'a', 'a', 'a') return Client(conn_params)