Phase5 neon-async-db
This skill should be used when setting up and managing reliable, high-performance asynchronous database connections for Neon Serverless PostgreSQL using SQLModel and SQLAlchemy's async capabilities.
install
source · Clone the upstream repo
git clone https://github.com/SyedaNabila559/phase5
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/SyedaNabila559/phase5 "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.claude/skills/neon-async-db" ~/.claude/skills/syedanabila559-phase5-neon-async-db && rm -rf "$T"
manifest:
.claude/skills/neon-async-db/SKILL.mdsource content
Neon PostgreSQL Async Connection
This skill providing guidance on setting up and managing reliable asynchronous database connections for Neon Serverless PostgreSQL.
Purpose
Setting up and managing reliable, high-performance asynchronous database connections for Neon Serverless PostgreSQL using SQLModel and SQLAlchemy's async capabilities.
Capabilities
- Environment-aware configuration using
.DATABASE_URL - Creating an asynchronous SQLAlchemy engine using the
driver.asyncpg - Implementing a
dependency utilizing proper async context management.get_async_session - Centralized
metadata management for SQLModel tables.Base - Connection health check utilities for operational monitoring.
- Serverless-optimized connection pooling configuration.
Implementation Details
Driver & Engine
Ensuring the
DATABASE_URL uses the postgresql+asyncpg:// scheme.
from sqlalchemy.ext.asyncio import create_async_engine from sqlmodel.ext.asyncio.session import AsyncSession from sqlalchemy.orm import sessionmaker engine = create_async_engine(DATABASE_URL, echo=False, pool_pre_ping=True) async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) async def get_async_session(): async with async_session() as session: yield session
Health Check
Implementing a lightweight query to verify connectivity.
async def check_db_health(): async with engine.begin() as conn: await conn.execute(text("SELECT 1"))
Best Practices
- Using
to handle stale connections commonly found in serverless environments.pool_pre_ping=True - Setting
in async sessions to allow access to object attributes after a commit.expire_on_commit=False - Always using async context managers (
) for sessions to ensure they are properly returned to the pool.async with