Automated Action e0b4ac8ba6 Create a REST API with FastAPI and SQLite
- Setup FastAPI project structure with main.py and requirements.txt
- Implement SQLAlchemy ORM with SQLite database
- Create Item model with CRUD operations
- Implement health endpoint for monitoring
- Setup Alembic for database migrations
- Add comprehensive documentation in README.md
- Configure Ruff for code linting
2025-05-23 10:10:10 +00:00

28 lines
653 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
# Ensure DB directory exists
Path(settings.DB_DIR).mkdir(parents=True, exist_ok=True)
engine = create_engine(
settings.SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False} # needed only for SQLite
)
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()