Skip to main content
Glama
jjsteffen23

CME Prediction Markets MCP Server

by jjsteffen23
database.py1.52 kB
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker from sqlalchemy.orm import declarative_base from sqlalchemy.pool import NullPool from contextlib import asynccontextmanager from typing import AsyncGenerator import structlog from src.config import get_settings logger = structlog.get_logger() settings = get_settings() Base = declarative_base() # Create async engine engine = create_async_engine( settings.DATABASE_URL, echo=settings.LOG_LEVEL == "DEBUG", pool_size=settings.DATABASE_POOL_SIZE, max_overflow=settings.DATABASE_MAX_OVERFLOW, pool_pre_ping=True, ) # Create session maker AsyncSessionLocal = async_sessionmaker( engine, class_=AsyncSession, expire_on_commit=False, autocommit=False, autoflush=False, ) @asynccontextmanager async def get_db() -> AsyncGenerator[AsyncSession, None]: """Dependency for getting async database sessions.""" async with AsyncSessionLocal() as session: try: yield session await session.commit() except Exception: await session.rollback() raise finally: await session.close() async def init_db(): """Initialize database tables.""" async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) logger.info("Database tables created") async def close_db(): """Close database connections.""" await engine.dispose() logger.info("Database connections closed")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jjsteffen23/dk_mcp_2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server