Automated Action b00b44023a Add FastAPI REST API with SQLite database
- Set up project structure
- Add database models and SQLAlchemy setup
- Configure Alembic for migrations
- Create API endpoints for items
- Add health check endpoint
- Update documentation

generated with BackendIM... (backend.im)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 22:33:58 +00:00

29 lines
686 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
# Create directory if it doesn't exist
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{settings.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():
"""
Dependency for getting DB session
"""
db = SessionLocal()
try:
yield db
finally:
db.close()