2021-03-18 16:00:01 +00:00
|
|
|
import asyncpg
|
|
|
|
from typing import Any, Union, Optional
|
2020-07-25 13:27:15 +00:00
|
|
|
from src.config import settings
|
2020-07-09 22:24:23 +00:00
|
|
|
|
2021-03-18 16:00:01 +00:00
|
|
|
connection: Optional[asyncpg.Connection] = None
|
|
|
|
|
|
|
|
|
|
|
|
async def setup_connection():
|
|
|
|
global connection
|
|
|
|
# Establish a connection to an existing database named "test"
|
|
|
|
# as a "postgres" user.
|
|
|
|
connection: asyncpg.connection = await asyncpg.connect(user=settings["pg_user"], host=settings.get("pg_host", "localhost"),
|
|
|
|
database=settings.get("pg_db", "RcGcDb"), password=settings.get("pg_pass"))
|
|
|
|
|
|
|
|
|
|
|
|
async def shutdown_connection():
|
|
|
|
global connection
|
|
|
|
await connection.close()
|