Skip to main content

Build

Netlify Db

NetlifyOfficialCertified

Guide for using Netlify DB (managed Neon Postgres). Use when the project needs a relational database, structured data storage, SQL queries, or data that will grow over time. Covers provisioning, raw SQL via @netlify/neon, Drizzle ORM integration, migrations, and deploy preview branching. Also covers when to use Netlify Blobs instead.

  • New
  • v1.0.0
  • Reviewed Jul 21
  • No reviews yet

Capabilities

  • When to Use DB vs Blobs

    See the netlify-blobs skill for Blobs usage

  • Raw SQL via @netlify/neon

  • Drizzle ORM Integration

    For most projects, use Drizzle ORM on top of Netlify DB

  • Migrations

Getting started

Full instructions

Example command

Setup

npm install @netlify/neon

Instructions: SKILL.mdv1.0.0

Netlify DB

Netlify DB provisions a managed Neon Postgres database automatically. No Neon account required.

When to Use DB vs Blobs

Use Netlify DB when:

  • Storing structured, relational data
  • Data will grow over time
  • Need queries, filtering, joins, or aggregations

Use Netlify Blobs instead when:

  • Storing files (images, documents, exports)
  • A handful of records with no growth expectation
  • Simple key-value storage with no relational needs
  • Want zero dependencies beyond @netlify/blobs

See the netlify-blobs skill for Blobs usage.

Setup

bash
npm install @netlify/neon
netlify db init    # Provisions database and sets up Drizzle ORM

Prerequisites: logged into Netlify CLI and site linked (netlify link).

Raw SQL via @netlify/neon

@netlify/neon wraps @neondatabase/serverless. No connection string needed — it auto-configures.

typescript
import { neon } from "@netlify/neon";
const sql = neon();

const users = await sql("SELECT * FROM users");
await sql("INSERT INTO users (name) VALUES ($1)", ["Jane"]);
await sql("UPDATE users SET name = $1 WHERE id = $2", ["Jane", 1]);
await sql("DELETE FROM users WHERE id = $1", [1]);

Drizzle ORM Integration

For most projects, use Drizzle ORM on top of Netlify DB.

drizzle.config.ts

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

export default defineConfig({
  dialect: "postgresql",
  dbCredentials: { url: process.env.NETLIFY_DATABASE_URL! },
  schema: "./db/schema.ts",
  out: "./migrations",
  migrations: { prefix: "timestamp" }, // Avoids conflicts across branches
});

db/index.ts

typescript
import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from "./schema";

const sql = neon(process.env.NETLIFY_DATABASE_URL!);
export const db = drizzle(sql, { schema });
export * from "./schema";

Schema Example

typescript
// db/schema.ts
import { integer, pgTable, varchar, text, boolean, timestamp } from "drizzle-orm/pg-core";

export const items = pgTable("items", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  title: varchar({ length: 255 }).notNull(),
  description: text(),
  isActive: boolean("is_active").notNull().default(true),
  createdAt: timestamp("created_at").defaultNow(),
  updatedAt: timestamp("updated_at").defaultNow(),
});

export type Item = typeof items.$inferSelect;
export type NewItem = typeof items.$inferInsert;

Query Patterns

typescript
import { db, items } from "../db";
import { eq } from "drizzle-orm";

const all = await db.select().from(items);
const [one] = await db.select().from(items).where(eq(items.id, id)).limit(1);
const [created] = await db.insert(items).values({ title: "New" }).returning();
const [updated] = await db.update(items).set({ title: "Updated" }).where(eq(items.id, id)).returning();
await db.delete(items).where(eq(items.id, id));

Migrations

json
{
  "scripts": {
    "db:generate": "drizzle-kit generate",
    "db:migrate": "netlify dev:exec drizzle-kit migrate",
    "db:push": "netlify dev:exec drizzle-kit push",
    "db:studio": "netlify dev:exec drizzle-kit studio"
  }
}

Workflow: modify schema, run db:generate, then db:migrate.

Deploy Preview Branching

Netlify DB supports branching — production branch gets the production database, all other branches and deploy previews get a separate preview branch. Develop and test migrations on preview, merge to main, then apply to production.

Environment Variables

  • NETLIFY_DATABASE_URL — Auto-set by Netlify when database is provisioned
  • Retrieve manually: netlify env:get NETLIFY_DATABASE_URL

Local Development

Run netlify dev or use @netlify/vite-plugin to get database access locally. Use netlify dev:exec to run migration commands with the proper environment.

Explore more skills

Browse all
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

More from Netlify

View source →
netlify-databaseUse this skill whenever a Netlify project needs a Postgres database. It covers Netlify Database setup, queries from Functions or Edge Functions, schema changes through migrations in netlify/database/migrations, Drizzle ORM wiring, local…2 installsnetlify-access-controlPicks the right Netlify site-protection layer and disambiguates the three unrelated "auth" concepts users conflate — app-user login (Netlify Identity), site-load gating (Password Protection / project visibility), and dashboard SAML SSO.…1 installsnetlify-edge-functionsWrite, route, cache, and debug Netlify Edge Functions, the Deno-based TypeScript or JavaScript handlers in netlify/edge-functions that run at the network edge in front of static files and serverless functions. Activate this skill whenever…0 installsnetlify-configConfigure Netlify builds and routing via netlify.toml, _redirects, and _headers. Use when setting a build command or publish directory, validating netlify.toml against its JSON schema, adding redirects/rewrites/proxies or an SPA fallback…0 installsnetlify-serverBuild and deploy a long-lived Node.js backend on Netlify Server (Early Access) from netlify/server/index.ts. Use this skill whenever someone wants to run an Express, Fastify, Hono or Koa app on Netlify as it is, add a backend or…0 installsnetlify-image-cdnTransform, resize, crop, and convert images on demand through Netlify Image CDN at the /.netlify/images endpoint. Use this skill whenever someone asks to optimize images, generate thumbnails or responsive sizes, serve WebP or AVIF…0 installs

Frequently asked questions about netlify-db

What does the netlify-db skill do?

Guide for using Netlify DB (managed Neon Postgres). Use when the project needs a relational database, structured data storage, SQL queries, or data that will grow over time. Covers provisioning, raw SQL via @netlify/neon, Drizzle ORM integration, migrations, and deploy preview branching. Also covers when to use Netlify Blobs instead. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the netlify-db skill?

Run `npx @skills-hub-ai/cli install netlify-db` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/netlify-db/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does netlify-db work with?

netlify-db runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the netlify-db skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use netlify-db after installing it?

In Claude Code, type `/netlify-db` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the netlify-db skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.

Badge for your README

Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.

Install on Skills Hub badge preview
Markdown
[![Install on Skills Hub](https://skills-hub.ai/api/badges/skill/netlify-db)](https://skills-hub.ai/skills/netlify-db)
HTML
<a href="https://skills-hub.ai/skills/netlify-db"><img src="https://skills-hub.ai/api/badges/skill/netlify-db" alt="Install on Skills Hub"></a>

More options in the badge docs.