All skills
antfu avatar

/nitro

@d02c484 official
by Anthony Fuantfu/skills5.9k stars
335

Nitro is the framework-agnostic server toolkit (powering Nuxt) for building and deploying web servers anywhere. Use when working with nitro.config, server routes/event handlers, route rules, caching, storage, tasks, websockets, or deploying to Node/Bun/Deno/Cloudflare/Vercel.

Use this Skill: https://skilld.dev/gh/antfu/skills/nitro

This session only. Nothing lands on disk.

referencesfeatures-database.md

≈886 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Database

Nitro ships a lightweight SQL layer powered by db0. It defaults to SQLite (.data/db.sqlite) and works out of the box in dev and Node.js production. Experimental — enable the flag.

import { defineConfig } from "nitro";

export default defineConfig({
  experimental: { database: true },
});

Usage

Import useDatabase() from nitro/database (no auto-imports in v3). It returns a connection; the optional name defaults to "default".

import { defineHandler } from "nitro";
import { useDatabase } from "nitro/database";

export default defineHandler(async () => {
  const db = useDatabase();

  await db.sql`CREATE TABLE IF NOT EXISTS users (
    "id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT
  )`;

  const id = String(Math.round(Math.random() * 10_000));
  await db.sql`INSERT INTO users VALUES (${id}, 'John', 'Doe', '')`;

  const { rows } = await db.sql`SELECT * FROM users WHERE id = ${id}`;
  return { rows };
});

Connections are created lazily and cached per name.

Query APIs

// Tagged template with safe parameter binding
const { rows } = await db.sql`SELECT * FROM users WHERE id = ${id}`;
const res = await db.sql`INSERT INTO posts (title) VALUES (${"Hello"})`;
// res.rows, res.changes, res.lastInsertRowid

// Raw string execution
await db.exec("CREATE TABLE IF NOT EXISTS t (id TEXT)");

// Prepared statement
const stmt = db.prepare("SELECT * FROM users WHERE id = ?");
const result = await stmt.bind("1001").all();

Always use db.sql tagged templates (or prepare().bind()) for user input — they parameterize and prevent SQL injection.

Configuration

import { defineConfig } from "nitro";

export default defineConfig({
  experimental: { database: true },
  database: {
    default: { connector: "sqlite", options: { name: "db" } },
    users: {
      connector: "postgresql",
      options: { url: "postgresql://user:pass@host:5432/db" },
    },
  },
  // Use a local SQLite db in development while prod uses Postgres
  devDatabase: {
    default: { connector: "sqlite", options: { name: "dev-db" } },
  },
});

Use a named connection with useDatabase("users").

Connectors

All db0 connectors are supported, including: sqlite / node-sqlite, better-sqlite3, sqlite3, bun / bun-sqlite, libsql (+ libsql-http/libsql-web/libsql-core), postgresql, mysql2, pglite, planetscale, neon, cloudflare-d1, and Cloudflare Hyperdrive variants. Connector-specific settings (url, host, name, ...) go under options, not the top level. Third-party libs (e.g. pg for postgresql) are auto-detected/installed and passed via the connector's lib option.

Key Points

  • Requires experimental.database: true; defaults to a zero-config SQLite connection.
  • useDatabase() from nitro/database (explicit import — no auto-imports in v3); names default to "default".
  • Prefer db.sql tagged templates for safe, parameterized queries.
  • devDatabase replaces database entirely in dev (not merged per-name) — include every connection you need.
  • Integrates with db0-supported ORMs; prefer this layer over platform-specific DB bindings for portability.
<!-- Source references: - https://nitro.build/docs/database - https://db0.unjs.io -->

Source: SKILL.md on GitHub

No alerts3d3 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    The skill provides comprehensive documentation and guidelines for Nitro v3, a server toolkit for building web applications. It includes security best practices like using parameterized queries to prevent SQL injection and authenticating task execution. No security issues were detected.

  • Socket3d

    No alerts

  • Snyk3d

    Risk: LOW · No issues

Signed by skilld at d02c484. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 4 days ago
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.9.25",
  "source": "Generated from https://github.com/nitrojs/nitro, scripts located at https://github.com/antfu/skills"
}

README badge

README badge for antfu/skills/nitro