Automated Action 6d123e4b89 Create simple todo app with FastAPI and SQLite
- Set up project structure
- Create database models with SQLAlchemy
- Add Alembic migrations
- Implement CRUD API endpoints
- Update README with documentation

generated with BackendIM... (backend.im)
2025-05-14 01:42:06 +00:00

27 lines
673 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
def create_db_and_tables():
Base.metadata.create_all(bind=engine)