17 lines
463 B
Python
17 lines
463 B
Python
|
|
import asyncpg
|
||
|
|
|
||
|
|
from onguard24.config import Settings
|
||
|
|
|
||
|
|
|
||
|
|
def normalize_dsn(url: str) -> str:
|
||
|
|
if url.startswith("postgres://"):
|
||
|
|
return url.replace("postgres://", "postgresql://", 1)
|
||
|
|
return url
|
||
|
|
|
||
|
|
|
||
|
|
async def create_pool(settings: Settings) -> asyncpg.Pool | None:
|
||
|
|
if not settings.database_url.strip():
|
||
|
|
return None
|
||
|
|
dsn = normalize_dsn(settings.database_url.strip())
|
||
|
|
return await asyncpg.create_pool(dsn=dsn, min_size=1, max_size=10)
|