22 lines
527 B
Python
22 lines
527 B
Python
from urllib.parse import quote_plus
|
|
|
|
from sqlalchemy import create_engine
|
|
|
|
from app.core.config import settings
|
|
|
|
|
|
def build_db_url() -> str:
|
|
user = quote_plus(settings.DB_USER)
|
|
password = quote_plus(settings.DB_PASSWORD)
|
|
host = settings.DB_HOST
|
|
port = settings.DB_PORT
|
|
db = quote_plus(settings.DB_NAME)
|
|
|
|
return (
|
|
f"postgresql+psycopg://{user}:{password}@{host}:{port}/{db}"
|
|
f"?sslmode={quote_plus(settings.DB_SSLMODE)}"
|
|
)
|
|
|
|
|
|
engine = create_engine(build_db_url(), pool_pre_ping=True)
|