Automated Action fec0fa72e7 Initial project setup with FastAPI, SQLite, and Alembic
- Set up SQLite database configuration and directory structure
- Configure Alembic for proper SQLite migrations
- Add initial model schemas and API endpoints
- Fix OAuth2 authentication
- Implement proper code formatting with Ruff
2025-05-27 20:34:02 +00:00

30 lines
765 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from app.core.config import SQLALCHEMY_DATABASE_URL
# Create SQLAlchemy engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False} # Only needed for SQLite
)
# Create SessionLocal class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create Base class for models
Base = declarative_base()
# Dependency to get DB session
def get_db():
"""
Dependency for getting the database session.
Creates a new session for each request and closes it when done.
"""
db = SessionLocal()
try:
yield db
finally:
db.close()