28 lines
447 B
Python
28 lines
447 B
Python
import os
|
|
import asyncpg
|
|
|
|
DATABASE_URL = os.getenv(
|
|
"DATABASE_URL",
|
|
"postgresql://messenger:secret_password@postgres:5432/messenger_db"
|
|
)
|
|
|
|
pool: asyncpg.Pool = None
|
|
|
|
|
|
async def init_db():
|
|
global pool
|
|
pool = await asyncpg.create_pool(
|
|
DATABASE_URL,
|
|
min_size=2,
|
|
max_size=10
|
|
)
|
|
|
|
|
|
async def close_db():
|
|
global pool
|
|
if pool:
|
|
await pool.close()
|
|
|
|
|
|
def get_pool() -> asyncpg.Pool:
|
|
return pool |