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:
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
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)
|
||||
|
||||
|
||||
16
app/main.py
Normal file
16
app/main.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from fastapi import FastAPI
|
||||
from users.views import router as users_router
|
||||
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(users_router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def main():
|
||||
return {"Hello": "World"}
|
||||
|
||||
|
||||
|
||||
|
||||
9
app/settings.py
Normal file
9
app/settings.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import os
|
||||
from pydantic import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
SECRET_KEY: str = os.getenv("SECRET_KEY", "")
|
||||
DATABASE_URL: str = os.getenv("DATABASE_URL", "")
|
||||
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user