技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
drizzle-nextjs-postgres【数据与研究】Drizzle ORM against PostgreSQL inside a Next.js App Router app. Covers client construction (globalThis singleton across HMR, serverless pool sizing, `prepare:false` behind PgBouncer/Supavisor, driver choice when you need interactive transactions, `server-only`), reads in Server Components under Next.js 16 Cache Components (`use cache` superseding `un…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
prepare:false behind PgBouncer/Supavisor, driver choice when you need interactive transactions, server-only), reads in Server Components under Next.js 16 Cache Components (use cache superseding unstable_cache and the revalidate/dynamic segment configs, Suspense boundaries, React cache() dedupe), Server Actions (authorization inside the action, updateTag vs revalidateTag, after()), Postgres schema types (timestamptz, identity vs serial, jsonb, numeric-as-string, bigint modes), drizzle-kit migrations (generate vs push, CONCURRENTLY outside the migrator, NOT VALID constraints, rename prompts), transactions and pooled connections, and Postgres query traps (keyset pagination, count cost, driver-dependent db.execute() shape, NOT IN nulls, prepared statements). Use when writing or reviewing Drizzle + Postgres code in Next.js.Library-reference skill for Drizzle ORM on PostgreSQL inside the Next.js App Router — 36 rules across 7 categories. Each rule names the wrong default it corrects; there is no rule for things a capable model already gets right.
This skill is self-contained: it includes the migration-workflow and type-inference rules a Postgres + Next.js developer needs even where the underlying wrong default is not Postgres-specific, so you never have to load a second skill mid-task. A few of those knowingly overlap the sibling drizzle-sqlite skill (same wrong default, restated for this context); the rest are decisions that only exist, or only bite differently, because the dialect is PostgreSQL or the code runs in the App Router.
Pinned to drizzle-orm 0.45.2, drizzle-kit 0.31.10, Next.js 16.2.11, PostgreSQL 14+.
lib/db module — driver choice, pooling, singletons, server-onlygenerateMetadata with db.select() / db.query.*use cache, cacheLife, cacheTag, React cache(), or nothingpgTable — column types, indexes, enums, constraintsdrizzle-kit generate / migrate / push, or hand-editing a generated .sql filedb.transaction(), or debugging a race, deadlock, or exhausted pool| # | Category | Prefix | Covers |
|---|---|---|---|
| 1 | Client Construction & Driver Choice | conn- | Singletons across HMR, serverless pool sizing, poolers, driver capability, server-only, passing schema |
| 2 | Reads in Server Components | rsc- | Suspense boundaries, use cache / cacheLife / cacheTag, request dedupe, waterfalls, runtime choice |
| 3 | Server Actions & Mutations | mut- | Authorization and validation in the action, cache invalidation, deferred writes |
| 4 | Postgres Schema Definition | schema- | timestamptz, identity columns, text vs varchar, numeric, jsonb, bigint modes, table config, enums |
| 5 | Migrations & Schema Change Safety | migrate- | generate vs push, concurrent indexes, where migrations run, renames, lock-safe constraints |
| 6 | Transactions & Pooled Connections | tx- | Connection cost of a held transaction, row locking, serialization retries |
| 7 | Postgres Query Building | query- | Keyset pagination, count cost, driver-dependent execute shape, NULL semantics, prepared statements |
conn-singleton-across-hmr — Cache the pool on globalThis so dev hot reloads don't exhaust connectionsconn-pool-sizing-for-serverless — Total connections is instances × max; max: 1 doesn't helpconn-disable-prepare-behind-transaction-pooler — postgres(url, { prepare: false }) behind PgBouncer/Supavisor transaction modeconn-driver-choice-follows-transactions — neon-http throws on db.transaction; db.batch() is still atomic. Pick by read-then-decide-then-writeconn-server-only-db-module — import 'server-only' in the client module, not in the schema fileconn-pass-schema-for-relational-queries — db.query is empty without { schema }, and with needs relations()rsc-suspense-around-uncached-reads — A query at the top of a page costs the route its static shellrsc-use-cache-replaces-unstable-cache — use cache + cacheLife + cacheTag supersede unstable_cache and segment configsrsc-no-request-apis-inside-use-cache — cookies() throws inside use cache; pass the tenant id as an argumentrsc-use-cache-is-per-instance-memory — use cache is in-memory per instance; it is not durable query cachingrsc-dedupe-with-react-cache — React cache() dedupes a lookup across layout, page, and metadatarsc-node-runtime-not-edge — runtime = 'edge' is unsupported with Cache Componentsmut-authorize-inside-the-action — An action is a public POST endpoint; check auth and input in its bodymut-updatetag-vs-revalidatetag — updateTag for read-your-own-writes, revalidateTag(tag, 'max') for SWRmut-after-for-post-response-writes — after() moves audit and analytics writes off the response pathschema-timestamptz-not-timestamp — Bare timestamp() is not a point in timeschema-identity-not-serial — generatedAlwaysAsIdentity() over serial()schema-text-not-varchar-length — text() unless the length limit is a real ruleschema-numeric-is-a-string — numeric infers as string; store money as integer centsschema-jsonb-with-dollar-type — jsonb for indexability, $type<>() for the shapeschema-bigint-mode-truncation — mode: 'number' silently rounds past 2^53schema-table-extras-are-an-array — The third pgTable argument returns an array; the object form is deprecatedschema-enum-values-are-append-only — A new enum value cannot be used until its transaction commitsmigrate-generate-not-push — push applies an unreviewed diff; generate produces a file you can readmigrate-concurrent-index-outside-transaction — migrate() runs all files in one transaction, so CONCURRENTLY fails inside itmigrate-run-in-deploy-step-not-at-runtime — Concurrent cold starts race on migrate(); run it once, before trafficmigrate-map-renames-explicitly — Picking "create column" at the prompt drops the renamed column's datamigrate-add-constraints-not-valid-then-validate — NOT VALID skips the blocking scan; validate in a second deploytx-no-external-io-inside — A transaction pins a connection; a network call inside it drains the pooltx-lock-rows-for-read-modify-write — read committed lets two transactions read the same stale rowtx-retry-serialization-failures — serializable aborts with SQLSTATE 40001 and expects a retryquery-keyset-not-offset — OFFSET reads and discards every row it skipsquery-count-scans-the-table — Postgres stores no row count; count(*) visits rows every timequery-execute-shape-is-driver-dependent — Raw db.execute() returns .rows on node-postgres, a bare array on postgres-jsquery-not-in-null-trap — One NULL in the subquery makes NOT IN return nothingquery-prepared-statements-need-names — .prepare() needs a name, and a transaction pooler defeats itRead a reference file when its decision comes up. Each rule names the wrong default it corrects, then shows the canonical way (with an incorrect/correct contrast only where the wrong way is a real trap).
drizzle-sqlite — the same ORM against SQLite-family backends; covers the dialect-agnostic query-building rules this skill deliberately omitsnextjs — App Router patterns beyond the data layerrelational-database-design — choosing the schema this skill teaches you to declare| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and source references |