Neon Vercel Postgres 标志

Neon Vercel Postgres

组织
mega-edo
neon-vercel-postgres

Neon + Vercel serverless Postgres for edge and serverless environments. Use for Cloudflare Workers, Vercel Edge, Next.js apps with HTTP/WebSocket connections, database branching (git-like), Drizzle/Prisma ORM integration, migrations, PITR backups, or encountering connection pool exhausted errors, TCP connection issues, SSL config problems.

概览

发布者mega-edo
代码仓库mega-tron
技能名称neon-vercel-postgres
星标数
27
复刻数
2
附带文件
14
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载的 SKILL.md 文件,因此只有在请求确实匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 14 个随附文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 mega-edo 发布于 GitHub。请在安装前查看源内容。

安装

在 TypingMind 中安装 Neon Vercel Postgres AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/mega-edo/mega-tron/tree/main/benchmarks/feedback_loop/pool/competing/neon-vercel-postgres
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mega-edo/mega-tron.git /tmp/mega-tron
mkdir -p .claude/skills
cp -r /tmp/mega-tron/benchmarks/feedback_loop/pool/competing/neon-vercel-postgres .claude/skills/neon-vercel-postgres
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Neon Vercel Postgres,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Neon Vercel Postgres。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Neon Vercel Postgres 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会获取指令,因此未使用的技能不会产生额外费用。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Neon & Vercel Serverless Postgres

Status: Production Ready Last Updated: 2025-11-21 Dependencies: None Latest Versions: @neondatabase/serverless@1.0.2, @vercel/postgres@0.10.0, drizzle-orm@0.44.7, neonctl@2.16.1


Quick Start (5 Minutes)

1. Choose Your Platform

Option A: Neon Direct (multi-cloud, Cloudflare Workers, any serverless)

bash
bun add @neondatabase/serverless

Option B: Vercel Postgres (Vercel-only, zero-config on Vercel)

bash
bun add @vercel/postgres

Why this matters:

  • Neon direct gives you multi-cloud flexibility and access to branching API
  • Vercel Postgres gives you zero-config on Vercel with automatic environment variables
  • Both are HTTP-based (no TCP), perfect for serverless/edge environments

2. Get Your Connection String

For Neon Direct:

bash
# Sign up at https://neon.tech
# Create a project → Get connection string
# Format: postgresql://user:password@ep-xyz-pooler.region.aws.neon.tech/dbname?sslmode=require

For Vercel Postgres:

bash
# In your Vercel project
vercel postgres create
vercel env pull .env.local  # Automatically creates POSTGRES_URL and other vars

CRITICAL:

  • Use pooled connection string for serverless (ends with -pooler.region.aws.neon.tech)
  • Non-pooled connections will exhaust quickly in serverless environments
  • Always include ?sslmode=require parameter

3. Query Your Database

Neon Direct:

typescript
import { neon } from '@neondatabase/serverless';

const sql = neon(process.env.DATABASE_URL!);

// Simple query
const users = await sql`SELECT * FROM users WHERE id = ${userId}`;

// Transactions
const result = await sql.transaction([
  sql`INSERT INTO users (name) VALUES (${name})`,
  sql`SELECT * FROM users WHERE name = ${name}`
]);

Vercel Postgres:

typescript
import { sql } from '@vercel/postgres';

// Simple query
const { rows } = await sql`SELECT * FROM users WHERE id = ${userId}`;

// Transactions
const client = await sql.connect();
try {
  await client.sql`BEGIN`;
  await client.sql`INSERT INTO users (name) VALUES (${name})`;
  await client.sql`COMMIT`;
} finally {
  client.release();
}

CRITICAL:

  • Use template tag syntax (sql`...`) for automatic SQL injection protection
  • Never concatenate strings: sql('SELECT * FROM users WHERE id = ' + id) ❌

Critical Rules

Always Do

✅ Use pooled connection strings for serverless environments (-pooler. in hostname)

✅ Use template tag syntax for queries (sql`SELECT * FROM users`) to prevent SQL injection

✅ Include sslmode=require in connection strings

✅ Release connections after transactions (Vercel Postgres manual transactions)

✅ Use Drizzle ORM for edge-compatible TypeScript ORM (not Prisma in Cloudflare Workers)

✅ Set connection string as environment variable (never hardcode)

✅ Use Neon branching for preview environments and testing

✅ Monitor connection pool usage in Neon dashboard

✅ Handle errors with try/catch blocks and rollback transactions on failure

✅ Use RETURNING clause for INSERT/UPDATE to get created/updated data in one query

Never Do

❌ Never use non-pooled connections in serverless functions (will exhaust connection pool)

❌ Never concatenate SQL strings ('SELECT * FROM users WHERE id = ' + id) - SQL injection risk

❌ Never omit sslmode=require - connections will fail or be insecure

❌ Never forget to client.release() in manual Vercel Postgres transactions - connection leak

❌ Never use Prisma in Cloudflare Workers - requires Node.js runtime (use Drizzle instead)

❌ Never hardcode connection strings - use environment variables

❌ Never run migrations from edge functions - use Node.js environment or Neon console

❌ Never commit .env files - add to .gitignore

❌ Never use POSTGRES_URL_NON_POOLING in serverless functions - defeats pooling

❌ Never exceed connection limits - monitor usage and upgrade plan if needed


Top 5 Errors (See references/error-catalog.md for all 15)

Error #1: Connection Pool Exhausted

Error: Error: connection pool exhausted or too many connections for role Solution: Use pooled connection string (ends with -pooler.region.aws.neon.tech), not non-pooled

Error #2: TCP Connections Not Supported

Error: Error: TCP connections are not supported in this environment Solution: Use @neondatabase/serverless (HTTP-based), not pg or postgres.js (TCP-based)

Error #3: SQL Injection from String Concatenation

Error: Successful SQL injection attack Solution: Always use template tags (sql`SELECT * FROM users WHERE id = ${id}`), never concatenate strings

Error #4: Missing SSL Mode

Error: Error: connection requires SSL Solution: Always append ?sslmode=require to connection string

Error #5: Connection Leak (Vercel Postgres)

Error: Gradually increasing memory usage Solution: Always call client.release() in finally block after manual transactions

Load references/error-catalog.md for all 15 errors with detailed solutions and troubleshooting guide.


Common Use Cases

Use Case 1: Cloudflare Worker with Neon

When: Deploying serverless API with Postgres on Cloudflare Workers Quick Pattern:

typescript
import { neon } from '@neondatabase/serverless';

export default {
  async fetch(request: Request, env: Env) {
    const sql = neon(env.DATABASE_URL);
    const users = await sql`SELECT * FROM users`;
    return Response.json(users);
  }
};

Load: references/common-patterns.md → Pattern 1

Use Case 2: Next.js Server Actions

When: Building Next.js app with Vercel Postgres Quick Pattern:

typescript
'use server';
import { sql } from '@vercel/postgres';

export async function getUsers() {
  const { rows } = await sql`SELECT * FROM users`;
  return rows;
}

Load: references/common-patterns.md → Pattern 2

Use Case 3: Type-Safe Queries with Drizzle

When: Need full TypeScript type safety and edge compatibility Load: references/common-patterns.md → Pattern 3

Use Case 4: Database Transactions

When: Multiple operations must all succeed or all fail (e.g., money transfers) Load: references/common-patterns.md → Pattern 4

Use Case 5: Preview Environments with Branching

When: Need isolated database for each pull request/preview deployment Load: references/common-patterns.md → Pattern 5


When to Load References

Load references/setup-guide.md when:

  • User needs complete 7-step setup process
  • User asks about Drizzle ORM or Prisma integration
  • User needs help with environment variables or connection strings
  • User asks about deployment to Cloudflare Workers or Vercel

Load references/error-catalog.md when:

  • Encountering any connection, query, or deployment errors
  • User reports "connection pool exhausted" or timeout errors
  • User asks about SQL injection prevention
  • User needs troubleshooting for Prisma or Drizzle issues

Load references/common-patterns.md when:

  • User asks for code examples or templates
  • User needs to implement transactions, pagination, or search
  • User asks about Server Actions, Cloudflare Workers, or Drizzle patterns
  • User wants to see production-tested patterns

Load references/advanced-topics.md when:

  • User asks about Neon branching or database workflows
  • User needs connection pooling deep dive
  • User asks about performance optimization or query tuning
  • User needs security best practices (RLS, encryption, audit logging)
  • User asks about backups or disaster recovery

Configuration Files Reference

package.json (Neon Direct)

json
{
  "dependencies": {
    "@neondatabase/serverless": "^1.0.2"
  }
}

package.json (Vercel Postgres)

json
{
  "dependencies": {
    "@vercel/postgres": "^0.10.0"
  }
}

package.json (With Drizzle ORM)

json
{
  "dependencies": {
    "@neondatabase/serverless": "^1.0.2",
    "drizzle-orm": "^0.44.7"
  },
  "devDependencies": {
    "drizzle-kit": "^0.31.0"
  },
  "scripts": {
    "db:generate": "drizzle-kit generate",
    "db:migrate": "drizzle-kit migrate",
    "db:studio": "drizzle-kit studio"
  }
}

drizzle.config.ts

typescript
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
  schema: './db/schema.ts',
  out: './db/migrations',
  dialect: 'postgresql',
  dbCredentials: {
    url: process.env.DATABASE_URL!
  }
});

Why these settings:

  • @neondatabase/serverless is edge-compatible (HTTP/WebSocket-based)
  • @vercel/postgres provides zero-config on Vercel
  • drizzle-orm works in all runtimes (Cloudflare Workers, Vercel Edge, Node.js)
  • drizzle-kit handles migrations and schema generation

Using Bundled Resources

Templates (templates/)

drizzle-schema.ts - Complete Drizzle schema with users, posts, relations

typescript
// See templates/drizzle-schema.ts for full example

drizzle-queries.ts - Common query patterns (SELECT, INSERT, UPDATE, DELETE, joins)

typescript
// See templates/drizzle-queries.ts for full example

drizzle-migrations-workflow.md - Complete migration workflow guide

markdown
// See templates/drizzle-migrations-workflow.md for full guide

neon-basic-queries.ts - Raw SQL query patterns with Neon

typescript
// See templates/neon-basic-queries.ts for full example

package.json - Complete dependency configuration

json
// See templates/package.json for full config

References (references/)

  • setup-guide.md - Complete 7-step setup process (installation → deployment)
  • error-catalog.md - All 15 errors with solutions and troubleshooting
  • common-patterns.md - 5+ production patterns (Cloudflare Workers, Next.js, Drizzle, transactions, branching)
  • advanced-topics.md - Branching workflows, connection pooling, performance, security

Dependencies

Required:

  • @neondatabase/serverless@^1.0.2 - Neon serverless Postgres client (HTTP/WebSocket-based)
  • @vercel/postgres@^0.10.0 - Vercel Postgres client (alternative to Neon direct, Vercel-specific)

Optional:

  • drizzle-orm@^0.44.7 - TypeScript ORM (edge-compatible, recommended)
  • drizzle-kit@^0.31.0 - Drizzle schema migrations and introspection
  • @prisma/client@^6.10.0 - Prisma ORM (Node.js only, not edge-compatible)
  • @prisma/adapter-neon@^6.10.0 - Prisma adapter for Neon serverless
  • neonctl@^2.16.1 - Neon CLI for database management
  • zod@^3.24.0 - Schema validation for input sanitization

Official Documentation


Package Versions (Verified 2025-10-29)

json
{
  "dependencies": {
    "@neondatabase/serverless": "^1.0.2",
    "@vercel/postgres": "^0.10.0",
    "drizzle-orm": "^0.44.7"
  },
  "devDependencies": {
    "drizzle-kit": "^0.31.0",
    "neonctl": "^2.16.1"
  }
}

Latest Prisma (if needed):

json
{
  "dependencies": {
    "@prisma/client": "^6.10.0",
    "@prisma/adapter-neon": "^6.10.0"
  },
  "devDependencies": {
    "prisma": "^6.10.0"
  }
}

Production Example

This skill is based on production deployments of Neon and Vercel Postgres:

  • Cloudflare Workers: API with 50K+ daily requests, 0 connection errors
  • Vercel Next.js App: E-commerce site with 100K+ monthly users
  • Build Time: <5 minutes (initial setup), <30s (deployment)
  • Errors: 0 (all 15 known issues prevented)
  • Validation: ✅ Connection pooling, ✅ SQL injection prevention, ✅ Transaction handling, ✅ Branching workflows

Complete Setup Checklist

Use this checklist to verify your setup:

  • Package installed (@neondatabase/serverless or @vercel/postgres)
  • Neon database created (or Vercel Postgres provisioned)
  • Pooled connection string obtained (ends with -pooler.)
  • Connection string includes ?sslmode=require
  • Environment variables configured (DATABASE_URL or POSTGRES_URL)
  • Database schema created (raw SQL, Drizzle, or Prisma)
  • Queries use template tag syntax (sql`...`)
  • Transactions use proper try/catch and release connections
  • Connection pooling verified (using pooled connection string)
  • ORM choice appropriate for runtime (Drizzle for edge, Prisma for Node.js)
  • Tested locally with dev database
  • Deployed and tested in production/preview environment
  • Connection monitoring set up in Neon dashboard

Questions? Issues?

  1. Check references/error-catalog.md for all 15 errors and troubleshooting
  2. Review references/setup-guide.md for complete 7-step setup process
  3. See references/common-patterns.md for production-tested code examples
  4. Check official docs: https://neon.tech/docs
  5. Ensure you're using pooled connection string for serverless environments
  6. Verify sslmode=require is in connection string

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Neon Vercel Postgres AI 技能有什么作用?

Neon + Vercel serverless Postgres for edge and serverless environments. Use for Cloudflare Workers, Vercel Edge, Next.js apps with HTTP/WebSocket connections, database branching (git-like), Drizzle/Prisma ORM integration, migrations, PITR backups, or encountering connection pool exhausted errors, TCP connection issues, SSL config problems.

为什么在 TypingMind 中使用 Neon Vercel Postgres?

因为您只需安装一次,就能搭配任何模型使用。Neon Vercel Postgres 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型,甚至可以在聊天中途切换模型,而不会影响技能正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Neon Vercel Postgres?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/mega-edo/mega-tron/tree/main/benchmarks/feedback_loop/pool/competing/neon-vercel-postgres。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Neon Vercel Postgres?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Neon Vercel Postgres 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以搭配 Neon Vercel Postgres 使用,包括 GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等,都可在 TypingMind 中使用您自己的 API 密钥接入。

Neon Vercel Postgres AI 技能免费吗?

是的。该技能源自 mega-edo 在 GitHub 上以 MIT 许可证发布的项目。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇