neon-serverless

Configures Neon Serverless Driver for Next.js, Vercel Edge Functions, AWS Lambda, and other serverless environments. Installs @neondatabase/serverless, sets up…

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.

Thêm skills từ neondatabase

add-neon-docs
neondatabase
Sử dụng kỹ năng này khi người dùng yêu cầu thêm tài liệu, thêm tài liệu hướng dẫn, thêm tài liệu tham khảo, hoặc cài đặt tài liệu về Neon. Thêm các liên kết tham khảo thực hành tốt nhất của Neon…
official
neon-auth
neondatabase
Thiết lập Neon Auth cho ứng dụng của bạn. Cấu hình xác thực, tạo các route xác thực và tạo các thành phần giao diện. Sử dụng khi thêm xác thực vào Next.js,…
official
neon-drizzle
neondatabase
Tạo một thiết lập Drizzle ORM đầy đủ chức năng với cơ sở dữ liệu Neon đã được cấp phát. Cài đặt các phụ thuộc, cấp phát thông tin xác thực cơ sở dữ liệu, cấu hình kết nối,…
official
neon-js
neondatabase
Thiết lập toàn bộ Neon JS SDK với xác thực hợp nhất và truy vấn cơ sở dữ liệu kiểu PostgREST. Cấu hình máy khách xác thực, máy khách dữ liệu và sinh kiểu. Sử dụng khi…
official
neon-serverless
neondatabase
Cấu hình Neon Serverless Driver cho Next.js, Vercel Edge Functions, AWS Lambda và các môi trường serverless khác. Cài đặt @neondatabase/serverless, thiết lập…
official
neon-toolkit
neondatabase
Tạo và quản lý các cơ sở dữ liệu Neon tạm thời cho mục đích kiểm thử, đường ống CI/CD và môi trường phát triển biệt lập. Sử dụng khi xây dựng cơ sở dữ liệu tạm thời cho…
official
logging-best-practices
neondatabase
Các phương pháp ghi log tốt nhất tập trung vào các sự kiện rộng (dòng log chuẩn) để hỗ trợ gỡ lỗi và phân tích mạnh mẽ
official
skill-creator
neondatabase
Hướng dẫn tạo kỹ năng hiệu quả. Kỹ năng này nên được sử dụng khi người dùng muốn tạo một kỹ năng mới (hoặc cập nhật kỹ năng hiện có) để mở rộng khả năng của Claude…
official