home / skills / andrelandgraf / fullstackrecipes / neon-drizzle-setup

neon-drizzle-setup skill

/.agents/skills/neon-drizzle-setup

This skill helps you connect a Next.js app to Neon Postgres using Drizzle ORM with optimized serverless pooling for Vercel.

npx playbooks add skill andrelandgraf/fullstackrecipes --skill neon-drizzle-setup

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
515 B
---
name: neon-drizzle-setup
description: Connect a Next.js app to Neon Postgres using Drizzle ORM with optimized connection pooling for Vercel serverless functions.
---

# Neon + Drizzle Setup

To set up Neon + Drizzle Setup, refer to the fullstackrecipes MCP server resource:

**Resource URI:** `recipe://fullstackrecipes.com/neon-drizzle-setup`

If the MCP server is not configured, fetch the recipe directly:

```bash
curl -H "Accept: text/plain" https://fullstackrecipes.com/api/recipes/neon-drizzle-setup
```

Overview

This skill bundles a tested setup to connect a Next.js app to Neon Postgres using Drizzle ORM, with connection pooling tuned for Vercel serverless environments. It provides a clear pattern, TypeScript examples, and deployment-ready configuration so serverless functions use stable pooled connections and avoid cold-start connection storms. The goal is reliable, low-latency DB access in production-grade full-stack AI apps.

How this skill works

The setup wires Drizzle ORM into Next.js API routes and server components while using Neon’s connection pooling guidance to reuse clients across invocations. It exports a singleton pool/client instance that survives across Vercel function warm cycles, and includes environment-driven configuration for connection limits, timeouts, and SSL. The recipe also provides commands and an alternative fetch endpoint to retrieve the canonical instructions.

When to use it

  • You run a Next.js app on Vercel and use Neon Postgres for production data.
  • You want a TypeScript-first ORM integration with Drizzle for queries and migrations.
  • You need connection pooling tuned to avoid exhausting Neon connections under bursty serverless traffic.
  • You prefer a battle-tested pattern with deployable defaults for latency-sensitive endpoints.
  • You are building AI-backed features where DB performance and stability impact UX.

Best practices

  • Export a single pooled client instance (singleton) and reuse it across invocations to minimize new connections.
  • Configure pool size based on Vercel concurrency and Neon limits; err on the conservative side for shared plans.
  • Use SSL and environment variables for credentials; never hard-code secrets in source.
  • Wrap heavy queries in optimized SQL or prepared statements and add indexes where necessary.
  • Monitor connection usage and query performance in Neon dashboard and iterate pool settings.

Example use cases

  • API routes that read/write embeddings and must handle spikes from user-driven AI requests.
  • Server-side rendered pages that fetch personalization data without creating excessive DB connections.
  • Background jobs or serverless cron endpoints that run batch updates and respect pool limits.
  • Prototype to production migration where you need a repeatable config for Neon + Drizzle connections.

FAQ

Where can I find the full step-by-step recipe?

Fetch the recipe from the published resource URI or retrieve it via curl at https://fullstackrecipes.com/api/recipes/neon-drizzle-setup.

Do I need a special Neon plan to use pooling?

Basic pooling works on most plans, but adjust pool size and timeouts to match your Neon account limits and expected concurrency.

Is this pattern compatible with Next.js server components and API routes?

Yes. The pattern supports both server components and API routes by exposing a reusable pooled client that can be imported where needed.