Spaces:
Sleeping
Sleeping
Download app/database.py from kirimdata369/NexusBridge-Ultra: direct link, hf CLI and curl.
- Browser
- Download file 827 Bytes
-
https://huggingface.co/spaces/kirimdata369/NexusBridge-Ultra/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/kirimdata369/NexusBridge-Ultra/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/kirimdata369/NexusBridge-Ultra/resolve/main/app/database.py
827 Bytes
| import os | |
| from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker | |
| from sqlalchemy.orm import DeclarativeBase | |
| from app.config import settings | |
| # Ensure we use an absolute path for the database | |
| BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| DB_PATH = os.path.join(BASE_DIR, "nexusbridge.db") | |
| DATABASE_URL = f"sqlite+aiosqlite:///{DB_PATH}" | |
| engine = create_async_engine(DATABASE_URL, echo=settings.DEBUG) | |
| SessionLocal = async_sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession, expire_on_commit=False) | |
| class Base(DeclarativeBase): | |
| pass | |
| async def get_db(): | |
| async with SessionLocal() as session: | |
| yield session | |
| async def init_db(): | |
| async with engine.begin() as conn: | |
| await conn.run_sync(Base.metadata.create_all) | |