Automated Action 512d53de73 Create simple Todo application with FastAPI and SQLite
- Created CRUD operations for todos
- Added database models and SQLAlchemy integration
- Set up Alembic for database migrations
- Added health endpoint
- Updated README with installation and usage instructions

generated with BackendIM... (backend.im)
2025-05-12 10:34:56 +00:00

30 lines
746 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# Create database directory if it doesn't exist
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()
# Dependency to get DB session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
def create_tables():
Base.metadata.create_all(bind=engine)