2022-06-10 01:48:02 +02:00
|
|
|
from urllib.parse import quote_plus
|
|
|
|
|
|
|
|
from sqlalchemy.engine import URL
|
|
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
|
|
|
import settings
|
|
|
|
|
2022-06-29 00:14:44 +02:00
|
|
|
encoded_password = quote_plus(settings.DB_PASSWORD)
|
|
|
|
engine = create_async_engine(
|
|
|
|
URL.create(
|
|
|
|
drivername="postgresql+asyncpg",
|
|
|
|
username=settings.DB_USERNAME,
|
|
|
|
password=encoded_password,
|
|
|
|
host=settings.DB_HOST,
|
|
|
|
port=settings.DB_PORT,
|
|
|
|
database=settings.DB_NAME,
|
|
|
|
),
|
|
|
|
pool_pre_ping=True,
|
2022-06-30 15:20:54 +02:00
|
|
|
future=True,
|
2022-06-29 00:14:44 +02:00
|
|
|
)
|
2022-06-10 01:48:02 +02:00
|
|
|
|
|
|
|
DBSession = sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession, expire_on_commit=False)
|