API
This commit is contained in:
18
app/services/db.py
Normal file
18
app/services/db.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import asyncpg
|
||||
from app.config import settings
|
||||
|
||||
pool: asyncpg.Pool | None = None
|
||||
|
||||
|
||||
async def get_pool() -> asyncpg.Pool:
|
||||
global pool
|
||||
if pool is None:
|
||||
pool = await asyncpg.create_pool(settings.DATABASE_URL, min_size=2, max_size=10)
|
||||
return pool
|
||||
|
||||
|
||||
async def close_pool():
|
||||
global pool
|
||||
if pool:
|
||||
await pool.close()
|
||||
pool = None
|
||||
Reference in New Issue
Block a user