neon-postgres
Neon PostgreSQL serverless database - connection pooling, branching, serverless driver, and optimization. Use when deploying to Neon or building serverless applications.
What this skill does
# Neon PostgreSQL Skill Serverless PostgreSQL with branching, autoscaling, and instant provisioning. ## Quick Start ### Create Database 1. Go to [console.neon.tech](https://console.neon.tech) 2. Create a new project 3. Copy connection string ### Installation ```bash # npm npm install @neondatabase/serverless # pnpm pnpm add @neondatabase/serverless # yarn yarn add @neondatabase/serverless # bun bun add @neondatabase/serverless ``` ## Connection Strings ```env # Direct connection (for migrations, scripts) DATABASE_URL=postgresql://user:[email protected]/dbname?sslmode=require # Pooled connection (for application) DATABASE_URL_POOLED=postgresql://user:[email protected]/dbname?sslmode=require ``` ## Key Concepts | Concept | Guide | |---------|-------| | **Serverless Driver** | [reference/serverless-driver.md](reference/serverless-driver.md) | | **Connection Pooling** | [reference/pooling.md](reference/pooling.md) | | **Branching** | [reference/branching.md](reference/branching.md) | | **Autoscaling** | [reference/autoscaling.md](reference/autoscaling.md) | ## Examples | Pattern | Guide | |---------|-------| | **Next.js Integration** | [examples/nextjs.md](examples/nextjs.md) | | **Edge Functions** | [examples/edge.md](examples/edge.md) | | **Migrations** | [examples/migrations.md](examples/migrations.md) | | **Branching Workflow** | [examples/branching-workflow.md](examples/branching-workflow.md) | ## Templates | Template | Purpose | |----------|---------| | [templates/db.ts](templates/db.ts) | Database connection | | [templates/neon.config.ts](templates/neon.config.ts) | Neon configuration | ## Connection Methods ### HTTP (Serverless - Recommended) Best for: Edge functions, serverless, one-shot queries ```typescript import { neon } from "@neondatabase/serverless"; const sql = neon(process.env.DATABASE_URL!); // Simple query const posts = await sql`SELECT * FROM posts WHERE published = true`; // With parameters const post = await sql`SELECT * FROM posts WHERE id = ${postId}`; // Insert await sql`INSERT INTO posts (title, content) VALUES (${title}, ${content})`; ``` ### WebSocket (Connection Pooling) Best for: Long-running connections, transactions ```typescript import { Pool } from "@neondatabase/serverless"; const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const client = await pool.connect(); try { await client.query("BEGIN"); await client.query("INSERT INTO posts (title) VALUES ($1)", [title]); await client.query("COMMIT"); } catch (e) { await client.query("ROLLBACK"); throw e; } finally { client.release(); } ``` ## With Drizzle ORM ### HTTP Driver ```typescript // src/db/index.ts import { neon } from "@neondatabase/serverless"; import { drizzle } from "drizzle-orm/neon-http"; import * as schema from "./schema"; const sql = neon(process.env.DATABASE_URL!); export const db = drizzle(sql, { schema }); ``` ### WebSocket Driver ```typescript // src/db/index.ts import { Pool } from "@neondatabase/serverless"; import { drizzle } from "drizzle-orm/neon-serverless"; import * as schema from "./schema"; const pool = new Pool({ connectionString: process.env.DATABASE_URL }); export const db = drizzle(pool, { schema }); ``` ## Branching Neon branches are copy-on-write clones of your database. ### CLI Commands ```bash # Install Neon CLI npm install -g neonctl # Login neonctl auth # List branches neonctl branches list # Create branch neonctl branches create --name feature-x # Get connection string neonctl connection-string feature-x # Delete branch neonctl branches delete feature-x ``` ### Branch Workflow ```bash # Create branch for feature neonctl branches create --name feature-auth --parent main # Get connection string for branch export DATABASE_URL=$(neonctl connection-string feature-auth) # Work on feature... # When done, merge via application migrations neonctl branches delete feature-auth ``` ### CI/CD Integration ```yaml # .github/workflows/preview.yml name: Preview on: pull_request jobs: preview: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Create Neon Branch uses: neondatabase/create-branch-action@v5 id: branch with: project_id: ${{ secrets.NEON_PROJECT_ID }} api_key: ${{ secrets.NEON_API_KEY }} branch_name: preview-${{ github.event.pull_request.number }} - name: Run Migrations env: DATABASE_URL: ${{ steps.branch.outputs.db_url }} run: npx drizzle-kit migrate ``` ## Connection Pooling ### When to Use Pooling | Scenario | Connection Type | |----------|-----------------| | Edge/Serverless functions | HTTP (neon) | | API routes with transactions | WebSocket Pool | | Long-running processes | WebSocket Pool | | One-shot queries | HTTP (neon) | ### Pooler URL ```env # Without pooler (direct) postgresql://user:[email protected]/db # With pooler (add -pooler to endpoint) postgresql://user:[email protected]/db ``` ## Autoscaling Configure in Neon console: - **Min compute**: 0.25 CU (can scale to zero) - **Max compute**: Up to 8 CU - **Scale to zero delay**: 5 minutes (default) ### Handle Cold Starts ```typescript import { neon } from "@neondatabase/serverless"; const sql = neon(process.env.DATABASE_URL!, { fetchOptions: { // Increase timeout for cold starts signal: AbortSignal.timeout(10000), }, }); ``` ## Best Practices ### 1. Use HTTP for Serverless ```typescript // Good - HTTP for serverless import { neon } from "@neondatabase/serverless"; const sql = neon(process.env.DATABASE_URL!); // Avoid - Pool in serverless (connection exhaustion) import { Pool } from "@neondatabase/serverless"; const pool = new Pool({ connectionString: process.env.DATABASE_URL }); ``` ### 2. Connection String per Environment ```env # .env.development DATABASE_URL=postgresql://...@ep-dev-branch... # .env.production DATABASE_URL=postgresql://...@ep-main... ``` ### 3. Use Prepared Statements ```typescript // Good - parameterized query const result = await sql`SELECT * FROM users WHERE id = ${userId}`; // Bad - string interpolation (SQL injection risk) const result = await sql(`SELECT * FROM users WHERE id = '${userId}'`); ``` ### 4. Handle Errors ```typescript import { neon, NeonDbError } from "@neondatabase/serverless"; const sql = neon(process.env.DATABASE_URL!); try { await sql`INSERT INTO users (email) VALUES (${email})`; } catch (error) { if (error instanceof NeonDbError) { if (error.code === "23505") { // Unique violation throw new Error("Email already exists"); } } throw error; } ``` ## Next.js App Router ```typescript // app/posts/page.tsx import { neon } from "@neondatabase/serverless"; const sql = neon(process.env.DATABASE_URL!); export default async function PostsPage() { const posts = await sql`SELECT * FROM posts ORDER BY created_at DESC`; return ( <ul> {posts.map((post) => ( <li key={post.id}>{post.title}</li> ))} </ul> ); } ``` ## Drizzle + Neon Complete Setup ```typescript // src/db/index.ts import { neon } from "@neondatabase/serverless"; import { drizzle } from "drizzle-orm/neon-http"; import * as schema from "./schema"; const sql = neon(process.env.DATABASE_URL!); export const db = drizzle(sql, { schema }); // src/db/schema.ts import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core"; export const posts = pgTable("posts", { id: serial("id").primaryKey(), title: text("title").notNull(), content: text("content"), createdAt: ti
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.