neon-serverless

作者: neondatabase

为 Next.js、Vercel Edge Functions、AWS Lambda 及其他无服务器环境配置 Neon Serverless Driver。安装 @neondatabase/serverless,设置…

npx skills add https://github.com/neondatabase/ai-rules --skill neon-serverless

Neon Serverless Skill

Configures the Neon Serverless Driver for optimal performance in serverless and edge computing environments.

When to Use

  • Setting up connections for edge functions (Vercel Edge, Cloudflare Workers)
  • Configuring serverless APIs (AWS Lambda, Google Cloud Functions)
  • Optimizing for low-latency database access
  • Implementing connection pooling for high-throughput apps

Not recommended for: Complex multi-statement transactions (use WebSocket Pool), persistent servers (use native PostgreSQL drivers), or offline-first applications.

Code Generation Rules

When generating TypeScript/JavaScript code:

  • BEFORE generating import statements, check tsconfig.json for path aliases (compilerOptions.paths)
  • If path aliases exist (e.g., "@/": ["./src/"]), use them (e.g., import { x } from '@/lib/utils')
  • If NO path aliases exist or unsure, ALWAYS use relative imports (e.g., import { x } from '../../../lib/utils')
  • Verify imports match the project's configuration
  • Default to relative imports - they always work regardless of configuration

Reference Documentation

Primary Resource: See [neon-serverless.mdc](https://raw.githubusercontent.com/neondatabase-labs/ai-rules/main/neon-serverless.mdc) in project root for comprehensive guidelines including:

  • Installation and compatibility requirements
  • HTTP vs WebSocket adapter selection
  • Connection pooling strategies
  • Query optimization patterns
  • Error handling and troubleshooting

Quick Setup

Installation

npm install @neondatabase/serverless

Connection Patterns

HTTP Client (recommended for edge/serverless):

import { neon } from '@neondatabase/serverless';
const sql = neon(process.env.DATABASE_URL!);
const rows = await sql`SELECT * FROM users WHERE id = ${userId}`;

WebSocket Pool (for Node.js long-lived connections):

import { Pool } from '@neondatabase/serverless';
const pool = new Pool({ connectionString: process.env.DATABASE_URL! });
const result = await pool.query('SELECT * FROM users WHERE id = $1', [userId]);

See templates/ for complete examples:

  • templates/http-connection.ts - HTTP client setup
  • templates/websocket-pool.ts - WebSocket pool configuration

Validation

Use scripts/validate-connection.ts to test your database connection before deployment.

Related Skills

  • neon-auth - Add authentication
  • neon-js - Full SDK with auth + data API
  • neon-drizzle - For ORM with serverless connections
  • neon-toolkit - For ephemeral database testing

Want best practices in your project? Run neon-plugin:add-neon-docs with parameter SKILL_NAME="neon-serverless" to add reference links.

来自 neondatabase 的更多技能

claimable-postgres
neondatabase
为本地开发、演示、原型设计和测试环境提供即时Postgres数据库。无需账户。除非认领到Neon账户,否则数据库将在72小时后过期。
neon
neondatabase
Neon平台概述,涵盖Postgres、Auth、Data API以及新服务:对象存储、计算函数和AI网关。当提到“Neon”时,用于概述如何与Neon协作及如何入门。否则,各项独立功能为触发点:“对象存储”或“S3兼容存储”、“无服务器函数”、“后台任务”或“在数据库附近运行代码”、“AI网关”、“LLM代理”、“模型路由”或“调用LLM”→...
apidatabasedevelopment
plugin-manager
neondatabase
管理此仓库在Cursor和Claude Code中的插件结构与配置。在创建、更新或审查插件文件夹时使用…
skill-creator
neondatabase
创建有效技能的指南。当用户想要创建新技能(或更新现有技能)以扩展Claude的功能时,应使用此技能。
using-neon
neondatabase
使用Neon Serverless Postgres的指南和最佳实践。涵盖入门、使用Neon进行本地开发、选择连接方法、Neon…
neon-js-react
neondatabase
在 React 应用(Vite、CRA)中设置完整的 Neon SDK,包含身份验证和数据库查询。创建类型化客户端、生成数据库类型并配置…
postgres-best-practices
neondatabase
使用Postgres的最佳实践和指南。涵盖模式设计、索引策略、查询优化、迁移以及常见陷阱。使用…
neon-postgres-egress-optimizer
neondatabase
指导用户诊断并修复导致其Postgres数据库产生过多数据传输(出站流量)的应用端查询模式。大多数高额出站流量账单源于应用程序获取的数据量超出实际使用量。