Spaces:
Build error
Build error
Hkoradiya123
feat: Initialize frontend with Zustand for state management, Tailwind CSS for styling, and TypeScript for type safety
4854e2b Download backend/app/core/database.py from jinksQspider/fmpro: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/spaces/jinksQspider/fmpro/resolve/main/backend/app/core/database.py
- Command line
-
hf download hf://spaces/jinksQspider/fmpro/backend/app/core/database.py
-
curl -L -o database.py https://huggingface.co/spaces/jinksQspider/fmpro/resolve/main/backend/app/core/database.py
1.47 kB
| """Database configuration and session management""" | |
| from sqlalchemy import create_engine, event | |
| from sqlalchemy.orm import sessionmaker, Session, declarative_base | |
| from contextlib import contextmanager | |
| from typing import Generator | |
| import logging | |
| from app.core.config import settings | |
| logger = logging.getLogger(__name__) | |
| # Create engine | |
| engine = create_engine( | |
| settings.DATABASE_URL, | |
| echo=settings.DEBUG, | |
| pool_pre_ping=True, | |
| pool_size=20, | |
| max_overflow=40, | |
| ) | |
| # Session factory | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| # Base class for ORM models | |
| Base = declarative_base() | |
| def get_db() -> Generator[Session, None, None]: | |
| """Dependency injection for database sessions""" | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def get_db_context() -> Generator[Session, None, None]: | |
| """Context manager for database sessions""" | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def init_db() -> None: | |
| """Initialize database tables""" | |
| Base.metadata.create_all(bind=engine) | |
| logger.info("Database initialized") | |
| # Enable foreign key constraints for SQLite (for development) | |
| def set_sqlite_pragma(dbapi_conn, connection_record): | |
| if "sqlite" in settings.DATABASE_URL: | |
| cursor = dbapi_conn.cursor() | |
| cursor.execute("PRAGMA foreign_keys=ON") | |
| cursor.close() | |