Automated Action 00174fd9dc Create REST API with FastAPI and SQLite
- Set up project structure with FastAPI
- Configure SQLite database with SQLAlchemy
- Set up Alembic for migrations
- Create Item model and schema
- Implement CRUD operations
- Add health endpoint

generated with BackendIM... (backend.im)
2025-05-13 21:57:29 +00:00

22 lines
538 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
# Create SQLAlchemy engine
engine = create_engine(
settings.SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False} # only needed for SQLite
)
# Create SessionLocal class for database sessions
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Dependency for database sessions
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()