Automated Action 993e1df71e Create REST API service with FastAPI and SQLite
- Set up project structure with app modules
- Configure SQLite database connection
- Set up Alembic for database migrations
- Implement Item model with CRUD operations
- Create API endpoints for items management
- Add health check endpoint
- Add API documentation
- Add comprehensive README
2025-05-19 15:58:21 +00:00

36 lines
749 B
Python

"""
Database session setup.
"""
from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Database directory
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
# Create engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False} # Required for SQLite
)
# Create session
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def get_db():
"""
Dependency function to get a database session.
Yields:
Session: Database session
"""
db = SessionLocal()
try:
yield db
finally:
db.close()