initial commit
worked on async alembic migrations, User model. Current issue: web_1 | INFO: 172.20.0.1:62958 - "POST /users/ HTTP/1.1" 500 Internal Server Error web_1 | ERROR: Exception in ASGI application web_1 | Traceback (most recent call last): ... web_1 | response web_1 | value is not a valid dict (type=type_error.dict) when trying to create new user
This commit is contained in:
49
app/db.py
Normal file
49
app/db.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from sqlalchemy import future
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||
from app.settings import settings
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
# engine = create_async_engine(settings.DATABASE_URL, echo=True, future=True)
|
||||
|
||||
# Session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
# def get_session():
|
||||
# with Session() as session:
|
||||
# yield session
|
||||
|
||||
class AsyncDatabaseSession:
|
||||
def __init__(self):
|
||||
self._session = None
|
||||
self._engine = None
|
||||
self._engine = create_async_engine(
|
||||
settings.DATABASE_URL,
|
||||
future=True,
|
||||
echo=True,
|
||||
)
|
||||
self._session = sessionmaker(
|
||||
self._engine, expire_on_commit=False, class_=AsyncSession
|
||||
)()
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self._session, name)
|
||||
|
||||
# def init(self):
|
||||
|
||||
db = AsyncDatabaseSession()
|
||||
|
||||
# async def get_session() -> AsyncSession:
|
||||
# async_session = sessionmaker(
|
||||
# engine, class_=AsyncSession, expire_on_commit=False
|
||||
# )
|
||||
# async with async_session() as session:
|
||||
# yield session
|
||||
# # from sqlalchemy import create_engine
|
||||
# # from sqlalchemy.ext.declarative import declarative_base
|
||||
# # from sqlalchemy.orm import sessionmaker
|
||||
|
||||
# engine = create_engine(settings.DATABASE_URL)
|
||||
# SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user