db-connection
设置数据库连接
此技能为在 Python 和 FastAPI 应用程序中配置数据库连接提供专业指导。它涵盖 Neon PostgreSQL 设置、连接池、SSL 配置以及 SQLAlchemy 引擎创建,并提供生产环境部署的最佳实践。
Baixar o ZIP da skill
Upload no Claude
Vá em Configurações → Capacidades → Skills → Upload skill
Ative e comece a usar
Testar
A utilizar "db-connection". 为我的 FastAPI 应用程序使用 Neon PostgreSQL 设置数据库连接
Resultado esperado:
- 引擎创建成功,pool_size=5
- 连接字符串已验证,SSL 模式:require
- 会话工厂已配置为依赖注入
- 健康检查端点位于 /health/db
A utilizar "db-connection". 为我的生产应用程序配置连接池设置
Resultado esperado:
- 池大小调整为 10 个连接
- 最大溢出设置为 20
- 连接超时配置为 30 秒
- 连接回收设置为 1800 秒
- 已启用池预连接以检查连接健康
A utilizar "db-connection". 添加数据库健康检查端点
Resultado esperado:
- 已创建 GET /health/db 端点
- 返回状态:健康或不健康
- 包含延迟测量(毫秒)
- 显示数据库连接池统计信息
Auditoria de Segurança
SeguroThis skill is a documentation-based skill containing database connection examples. The only script (verify.py) only reads and validates the SKILL.md file. All static findings are false positives: regex flags were misidentified as cryptographic algorithms, markdown backticks as shell commands, and standard documentation URLs as hardcoded targets. No network calls, no command execution, no credential exfiltration detected.
Fatores de risco
⚡ Contém scripts (1)
📁 Acesso ao sistema de arquivos (1)
Pontuação de qualidade
O Que Você Pode Construir
连接 FastAPI 到 Neon
为使用 Neon PostgreSQL 的 FastAPI 应用程序配置 SQLAlchemy 引擎和会话管理
调整连接池
为无服务器和生产环境优化池大小、超时和回收设置
添加健康检查
实现数据库健康检查端点用于监控和部署验证
Tente Estes Prompts
为我的 FastAPI 应用程序使用 Neon PostgreSQL 设置数据库连接。我需要带连接池的 SQLAlchemy 引擎配置。
为我的生产 FastAPI 应用程序配置连接池设置。当前问题:负载下响应缓慢,连接超时。
为我的 FastAPI 应用程序添加数据库健康检查端点。它应返回状态、延迟和池统计信息。
为 Vercel 无服务器函数优化数据库连接设置。我需要避免连接限制错误。
Melhores Práticas
- 使用 pool_pre_ping 在使用前验证连接,避免陈旧连接
- 始终在 finally 块中关闭数据库会话或使用上下文管理器
- 配置适当的超时和池回收以防止连接泄漏
Evitar
- 为每个请求创建新数据库连接而不是使用连接池
- 不进行适当清理就保持连接打开,导致池耗尽
- 硬编码连接 URL 而不是使用带 SecretStr 的环境变量
Perguntas Frequentes
支持哪些 Python 版本?
支持哪些数据库平台?
如何与现有的 FastAPI 应用程序集成?
我的连接数据安全吗?
为什么我遇到连接超时错误?
这与 @sqlmodel-crud 有什么不同?
Detalhes do Desenvolvedor
Autor
Awais68Licença
MIT
Repositório
https://github.com/Awais68/hackathon-2-phase-ii-full-stack-web-app/tree/main/.claude/skills/db-connectionReferência
main