Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions db_wrapper/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ConnectionParameters:
"""Defines connection parameters for database."""

host: str
port: int
user: str
password: str
database: str
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions example/example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import json
import logging
import os
from uuid import uuid4, UUID
from typing import Any, List
Expand All @@ -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."""
Expand All @@ -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'))
Expand Down
8 changes: 4 additions & 4 deletions example/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion example/requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)