選項
首頁首頁 Skill 文件 nuxthub

在構建 NuxtHub v0.10.6 應用程式時使用——該版本提供資料庫功能(基於 Drizzle ORM,支援 sqlite、postgresql、mysql 資料庫),以及 KV 儲存、二進位制大物件儲存和快取 API。內容涵蓋配置設定、資料表結構定義、資料遷移功能、多雲部署方案(Cloudflare、Vercel),還有全新的 hub:db、hub:kv、hub:blob 虛擬模組匯入方式。

...展開全部
36
更新時間 2026-08-23

關於 nuxthub

NuxtHub 是一款 Claude Code 參考技能,用於在 NuxtHub v0.10.6 上構建全棧 Nuxt 應用,涵蓋了該平臺的資料庫、KV 儲存、二進位制大物件儲存以及快取 API 相關內容。它透過為 Claude 提供針對配置、模式定義、資料遷移、多雲部署以及新推出的 hub:db、hub:kv 和 hub:blob 虛擬模組匯入方式的最新參考資訊,幫助開發者編寫正確且符合版本要求的 NuxtHub 程式碼,從而避免依賴可能已經過時的通用知識。

該技能透過 Drizzle ORM 支援基於 SQLite、PostgreSQL 和 MySQL 的型別安全 SQL 語法,提供了模式示例、CRUD 操作模式,以及一套完整的遷移 CLI 工具(包括生成遷移檔案、執行遷移、執行原始 SQL 語句、刪除表、全部刪除、合併遷移記錄、標記遷移已完成等功能),這些工具可在開發與構建過程中自動應用。它還涵蓋了帶有過期時間限制和大小約束的 KV 儲存、包含上傳/下載/列表/提供內容功能及驗證機制的二進位制大物件儲存,以及快取 API 相關內容。該技能會將每種資料庫方言和對應提供商與本地及生產環境的後端系統以及所需的環境變數(如 D1、Turso、Neon、postgres-js、mysql2、Upstash、Redis、Cloudflare KV、Vercel、Deno)對應起來,同時還會介紹相關配置選項,包括用於在開發環境中使用生產環境繫結的遠端模式,以及 v0.10.6 版本對只讀副本的支援。另有兩份參考檔案分別介紹了 Cloudflare 場景下的 wrangler.jsonc 模板,以及 Vercel、Netlify、Deno 和 AWS 場景下的提供商配置方法,該技能還會指導使用者僅載入與當前任務相關的參考內容。

該技能主要面向那些需要在 Cloudflare、Vercel 及其他平臺上部署應用,且希望獲得準確 NuxtHub 資料層及部署指導的 Nuxt 與全棧開發者。它屬於文件類參考資料兼程式碼模式參考工具:關於憑證配置的說明僅限於為每個提供商指定標準的環境變數名稱。

常見問題

它支援哪些 NuxtHub 版本和資料庫?

該技能針對 NuxtHub v0.10.6 進行了文件編寫,涵蓋了基於 SQLite、PostgreSQL 和 MySQL 的 Drizzle ORM,其中包含模式示例、CRUD 操作模式,以及本地環境與生產環境後端之間的對應關係說明。

支援哪些部署目標?

它支援向 Cloudflare、Vercel、Deno 和 Netlify 等平臺進行多雲部署,同時提供了 Cloudflare 場景下的 wrangler.jsonc 模板參考檔案,以及 Vercel、Netlify、Deno 和 AWS 場景下的提供商配置參考檔案。

資料遷移是如何實現的?

該技能提供了完整的 CLI 工具,包括根據模式生成遷移檔案、執行遷移、執行原始 SQL 語句、刪除表、全部刪除、合併遷移記錄以及標記遷移已完成等功能。這些遷移操作會在 nuxi 開發與構建過程中自動應用,同時相關記錄會儲存在 _hub_migrations 表中。

什麼是遠端模式?

遠端模式(v0.10+ 版本支援)允許在本地開發時連線到生產環境中的 Cloudflare D1、KV 和 R2 繫結,而非使用本地模擬環境,這種方式有助於使用真實生產資料來進行測試。

應該如何載入參考檔案?

該技能建議使用者無需一次性載入所有檔案,而應僅載入與當前任務相關的參考內容:在配置 Cloudflare 時載入 wrangler-templates 參考檔案,而在部署到 Vercel、Netlify、Deno、AWS 或配置外部資料庫/儲存提供商時載入 providers 參考檔案。

所有檔案

3 個檔案SKILL.md13.1 KB檢視references/wrangler-templates.md4.4 KB檢視references/providers.md5.7 KB檢視

在 GitHub 上查看

Full-stack Nuxt framework with database, KV, blob, and cache. Multi-cloud support (Cloudflare, Vercel, Deno, Netlify).

For Nuxt server patterns: use nuxt skill (server.md)For content with database: use nuxt-content skill

Loading Files

Consider loading these reference files based on your task:

  • references/wrangler-templates.md - if manually configuring wrangler.jsonc for Cloudflare deployment
  • references/providers.md - if deploying to Vercel, Netlify, Deno, AWS, or configuring external database/storage providers

DO NOT load all files at once. Load only what's relevant to your current task.

Installation

npx nuxi module add hub

Configuration

// nuxt.config.tsexport default defineNuxtConfig({  modules: ['@nuxthub/core'],  hub: {    db: 'sqlite', // 'sqlite' | 'postgresql' | 'mysql'    kv: true,    blob: true,    cache: true,    dir: '.data', // local storage directory    remote: false // use production bindings in dev (v0.10+)  }})

Advanced Config

hub: {  db: {    dialect: 'postgresql',    driver: 'postgres-js', // Optional: auto-detected    casing: 'snake_case',  // camelCase JS -> snake_case DB (v0.10.3+)    migrationsDirs: ['server/db/custom-migrations/'],    applyMigrationsDuringBuild: true, // default    replica: { // Read replica support (v0.10.6+)      connection: { connectionString: process.env.DATABASE_REPLICA_URL }    }  },  remote: true // Use production Cloudflare bindings in dev (v0.10+)}

remote mode: When enabled, connects to production D1/KV/R2 during local development instead of local emulation. Useful for testing with production data.

Database replica (v0.10.6+): Configure read replicas to distribute database load. Queries use replicas automatically while writes go to primary.

Database

Type-safe SQL via Drizzle ORM. db and schema are auto-imported on server-side.

Schema Definition

Place in server/db/schema.ts or server/db/schema/*.ts:

// server/db/schema.ts (SQLite)import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'export const users = sqliteTable('users', {  id: integer().primaryKey({ autoIncrement: true }),  name: text().notNull(),  email: text().notNull().unique(),  createdAt: integer({ mode: 'timestamp' }).notNull()})

PostgreSQL variant:

import { pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core'export const users = pgTable('users', {  id: serial().primaryKey(),  name: text().notNull(),  email: text().notNull().unique(),  createdAt: timestamp().notNull().defaultNow()})

Database API

// db and schema are auto-imported on server-sideimport { db, schema } from 'hub:db'// Selectconst users = await db.select().from(schema.users)const user = await db.query.users.findFirst({ where: eq(schema.users.id, 1) })// Insertconst [newUser] = await db.insert(schema.users).values({ name: 'John', email: '[email protected]' }).returning()// Updateawait db.update(schema.users).set({ name: 'Jane' }).where(eq(schema.users.id, 1))// Deleteawait db.delete(schema.users).where(eq(schema.users.id, 1))

Migrations

npx nuxt db generate                  # Generate migrations from schemanpx nuxt db migrate                   # Apply pending migrationsnpx nuxt db sql "SELECT * FROM users" # Execute raw SQLnpx nuxt db drop <TABLE>              # Drop a specific tablenpx nuxt db drop-all                  # Drop all tables (v0.10+)npx nuxt db squash                    # Squash migrations into one (v0.10+)npx nuxt db mark-as-migrated [NAME]   # Mark as migrated without running

Migrations auto-apply during npx nuxi dev and npx nuxi build. Tracked in _hub_migrations table.

Database Providers

DialectLocalProduction
sqlite.data/db/sqlite.dbD1 (Cloudflare), Turso (TURSO_DATABASE_URL, TURSO_AUTH_TOKEN)
postgresqlPGlitepostgres-js (DATABASE_URL), neon-http (v0.10.2+, DATABASE_URL)
mysql-mysql2 (DATABASE_URL, MYSQL_URL)

KV Storage

Key-value storage. kv is auto-imported on server-side.

import { kv } from 'hub:kv'await kv.set('key', { data: 'value' })await kv.set('key', value, { ttl: 60 }) // TTL in secondsconst value = await kv.get('key')const exists = await kv.has('key')await kv.del('key')const keys = await kv.keys('prefix:')await kv.clear('prefix:')

Constraints: max value 25 MiB, max key 512 bytes.

KV Providers

ProviderPackageEnv Vars
Upstash@upstash/redisUPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN
RedisioredisREDIS_URL
Cloudflare KV-KV binding in wrangler.jsonc
Deno KV-Auto on Deno Deploy
Vercel-KV_REST_API_URL, KV_REST_API_TOKEN

Blob Storage

File storage. blob is auto-imported on server-side.

Blob API

import { blob } from 'hub:blob'// Uploadconst result = await blob.put('path/file.txt', body, {  contentType: 'text/plain',  access: 'public', // 'public' | 'private' (v0.10.2+)  addRandomSuffix: true,  prefix: 'uploads'})// Returns: { pathname, contentType, size, httpEtag, uploadedAt }// Downloadconst file = await blob.get('path/file.txt') // Returns Blob or null// Listconst { blobs, cursor, hasMore, folders } = await blob.list({ prefix: 'uploads/', limit: 10, folded: true })// Serve (with proper headers)return blob.serve(event, 'path/file.txt')// Deleteawait blob.del('path/file.txt')await blob.del(['file1.txt', 'file2.txt']) // Multiple// Metadata onlyconst meta = await blob.head('path/file.txt')

Upload Helpers

// Server: Validate + upload handlerexport default eventHandler(async (event) => {  return blob.handleUpload(event, {    formKey: 'files',    multiple: true,    ensure: { maxSize: '10MB', types: ['image/png', 'image/jpeg'] },    put: { addRandomSuffix: true, prefix: 'images' }  })})// Validate before manual uploadensureBlob(file, { maxSize: '10MB', types: ['image'] })// Multipart upload for large files (>10MB)export default eventHandler(async (event) => {  return blob.handleMultipartUpload(event) // Route: /api/files/multipart/[action]/[...pathname]})

Vue Composables

// Simple uploadconst upload = useUpload('/api/upload')const result = await upload(inputElement)// Multipart with progressconst mpu = useMultipartUpload('/api/files/multipart')const { completed, progress, abort } = mpu(file)

Blob Providers

ProviderPackageConfig
Cloudflare R2-BLOB binding in wrangler.jsonc
Vercel Blob@vercel/blobBLOB_READ_WRITE_TOKEN
S3aws4fetchS3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_BUCKET, S3_REGION

Cache

Response and function caching.

Route Handler Caching

export default cachedEventHandler((event) => {  return { data: 'cached', date: new Date().toISOString() }}, {  maxAge: 60 * 60, // 1 hour  getKey: event => event.path})

Function Caching

export const getStars = defineCachedFunction(  async (event: H3Event, repo: string) => {    const data = await $fetch(`https://api.github.com/repos/${repo}`)    return data.stargazers_count  },  { maxAge: 3600, name: 'ghStars', getKey: (event, repo) => repo })

Cache Invalidation

// Remove specificawait useStorage('cache').removeItem('nitro:functions:getStars:repo-name.json')// Clear by prefixawait useStorage('cache').clear('nitro:handlers')

Cache key pattern: ${group}:${name}:${getKey(...args)}.json (defaults: group='nitro', name='handlers'|'functions'|'routes')

Deployment

Cloudflare

NuxtHub auto-generates wrangler.json from your hub config - no manual wrangler.jsonc required:

// nuxt.config.tsexport default defineNuxtConfig({  hub: {    db: {      dialect: 'sqlite',      driver: 'd1',      connection: { databaseId: '<database-id>' }    },    kv: {      driver: 'cloudflare-kv-binding',      namespaceId: '<kv-namespace-id>'    },    cache: {      driver: 'cloudflare-kv-binding',      namespaceId: '<cache-namespace-id>'    },    blob: {      driver: 'cloudflare-r2',      bucketName: '<bucket-name>'    }  }})

Observability (recommended): Enable logging for production deployments:

// wrangler.jsonc (optional){  "observability": {    "logs": {      "enabled": true,      "head_sampling_rate": 1,      "invocation_logs": true,      "persist": true    }  }}

Create resources via Cloudflare dashboard or CLI:

npx wrangler d1 create my-db              # Get database-idnpx wrangler kv namespace create KV       # Get kv-namespace-idnpx wrangler kv namespace create CACHE    # Get cache-namespace-idnpx wrangler r2 bucket create my-bucket   # Get bucket-name

Deploy: Create Cloudflare Workers project, link Git repo. Bindings auto-configured at build time.

Environments: Use CLOUDFLARE_ENV=preview for preview deployments.

See references/wrangler-templates.md for manual wrangler.jsonc patterns and references/providers.md for all provider configurations.

Other Providers

See references/providers.md for detailed deployment patterns for:

  • Vercel: Postgres, Turso, Vercel Blob, Vercel KV
  • Netlify: External databases, S3, Upstash Redis
  • Deno Deploy: Deno KV
  • AWS/Self-hosted: S3, RDS, custom configs

D1 over HTTP

Query D1 from non-Cloudflare hosts:

hub: {  db: { dialect: 'sqlite', driver: 'd1-http' }}

Requires: NUXT_HUB_CLOUDFLARE_ACCOUNT_ID, NUXT_HUB_CLOUDFLARE_API_TOKEN, NUXT_HUB_CLOUDFLARE_DATABASE_ID

Build-time Hooks

// Extend schemanuxt.hook('hub:db:schema:extend', async ({ dialect, paths }) => {  paths.push(await resolvePath(`./schema/custom.${dialect}`))})// Add migration directoriesnuxt.hook('hub:db:migrations:dirs', (dirs) => {  dirs.push(resolve('./db-migrations'))})// Post-migration queries (idempotent)nuxt.hook('hub:db:queries:paths', (paths, dialect) => {  paths.push(resolve(`./seed.${dialect}.sql`))})

Type Sharing

// shared/types/db.tsimport type { users } from '~/server/db/schema'export type User = typeof users.$inferSelectexport type NewUser = typeof users.$inferInsert

WebSocket / Realtime

Enable experimental WebSocket:

// nuxt.config.tsnitro: { experimental: { websocket: true } }
// server/routes/ws/chat.tsexport default defineWebSocketHandler({  open(peer) {    peer.subscribe('chat')    peer.publish('chat', 'User joined')  },  message(peer, message) {    peer.publish('chat', message.text())  },  close(peer) {    peer.unsubscribe('chat')  }})

Deprecated (v0.10)

Removed Cloudflare-specific features:

  • hubAI() -> Use AI SDK with Workers AI Provider
  • hubBrowser() -> Puppeteer
  • hubVectorize() -> Vectorize
  • NuxtHub Admin -> Sunset Dec 31, 2025
  • npx nuxthub deploy -> Use wrangler deploy

Quick Reference

FeatureImportAccess
Databaseimport { db, schema } from 'hub:db'db.select(), db.insert(), etc.
KVimport { kv } from 'hub:kv'kv.get(), kv.set(), etc.
Blobimport { blob } from 'hub:blob'blob.put(), blob.get(), etc.

All are auto-imported on server-side.

Resources

  • Installation
  • Migration from v0.9
  • Database
  • Blob
  • KV
  • Cache
  • Deploy

所有檔案

0 個檔案

安裝 nuxthub

將技能檔案下載並解壓到您的 .claude/skills/ 目錄中。

下載 ZIP

複製儲存庫並將技能檔案複製到您的專案中。

git clone https://github.com/onmax/nuxt-skills/blob/main/skills/nuxthub/SKILL.md # Copy SKILL.md to your .claude/skills/ directory

複製 複製
快速設定: 將該技能資料夾複製到 .claude/skills/ 目錄中,Claude 會自動檢測並使用該技能。
儲存庫 onmax/nuxt-skills

相關技能

golang-dependency-injection
更新時間 2026-06-29
tc-tracker
更新時間 2026-08-27
code-quality
更新時間 2026-08-22
altimate-data-engineering-skills
更新時間 2026-08-23
OR