[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7ENYP15JR2AD9TPP13V5M5E":3,"skill-same:01M7ENYP15JR2AD9TPP13V5M5E":72},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":36,"commitSha":37,"skillDirectory":38,"forksCount":39,"repositoryHtmlUrl":40,"repositoryHomepageUrl":6,"ownerHtmlUrl":41,"ownerBlogUrl":6,"ownerDescription":42,"updatedAt":43,"install":44,"resources":57},"01M7ENYP15JR2AD9TPP13V5M5E","neon",null,"Use when you have picked Neon (serverless Postgres) and need to connect correctly from a serverless or edge runtime, wire database branching into dev, preview and CI, or stop being burned by scale-to-zero cold starts and pooler limits — including choosing HTTP versus WebSocket connections and pooled versus direct endpoints for migrations. NOT generic Postgres schema, index, EXPLAIN, RLS or migration-engine work (that is `postgresdb`).","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fneon\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: neon\ndescription: \"Use when you have picked Neon (serverless Postgres) and need to connect correctly from a serverless or edge runtime, wire database branching into dev, preview and CI, or stop being burned by scale-to-zero cold starts and pooler limits — including choosing HTTP versus WebSocket connections and pooled versus direct endpoints for migrations. NOT generic Postgres schema, index, EXPLAIN, RLS or migration-engine work (that is `postgresdb`).\"\ntags: [neon, postgres, serverless, database, branching, edge]\nrecommends: [postgresdb, drizzle-orm, prisma-orm, vercel]\norigin: risco\n---\n\n# Neon — serverless Postgres as a platform\n\nNeon is Postgres with three platform features the engine doesn't have: a **serverless driver** that\ntalks over HTTP\u002FWebSocket (so you can query from edge runtimes), **built-in connection pooling**, and\n**copy-on-write branching** that makes a fork of production data appear instantly. This skill owns\nthat platform layer. The Postgres *engine* underneath — schema, indexes, EXPLAIN, RLS, zero-downtime\nDDL — is identical to any Postgres 16 and belongs to `..\u002Fpostgresdb\u002FSKILL.md`. Don't re-derive engine\ncraft here; connect correctly and branch correctly.\n\n## When to use \u002F When NOT to use\n\n**When to use:**\n\n- Code imports `@neondatabase\u002Fserverless`, or `DATABASE_URL` points at `*.neon.tech` \u002F `*.aws.neon.tech`.\n- Connecting from Vercel (Edge\u002FNode), Cloudflare Workers, AWS Lambda, or any serverless\u002Fedge function — choosing HTTP `neon()` vs WebSocket `Pool`.\n- Setting up branching: dev branch off production, a branch per PR in CI, `neonctl` usage, the Neon + Vercel preview integration.\n- Neon-specific symptoms: cold start after scale-to-zero, \"too many connections\" despite being serverless, pooled-vs-direct string confusion, autoscaling CU sizing\u002Fcost.\n- Picking the connection string for migrations (direct) vs app queries (pooled).\n\n**When NOT to use — route to the sibling:**\n\n- Schema design, index choice, EXPLAIN\u002FANALYZE, query tuning, RLS, VACUUM, partitioning, expand-contract migrations → `..\u002Fpostgresdb\u002FSKILL.md`. Neon adds nothing to the engine; defer.\n- Drizzle schema\u002Fmigrations → `..\u002Fdrizzle-orm\u002FSKILL.md`; Prisma → `prisma-orm`. Neon supplies only the *driver adapter* line.\n- A different managed Postgres\u002FBaaS: Supabase (auth + storage + realtime) → `supabase`; PlanetScale → `planetscale`; Turso\u002FlibSQL → `sqlite-turso`.\n- Where to deploy the app talking to Neon → `..\u002Fvercel\u002FSKILL.md` \u002F `cloudflare` \u002F `railway`.\n- Backup\u002FPITR strategy as a discipline → `backups` (Neon branch-as-restore is mentioned here, not owned).\n\n## Non-negotiables\n\n1. A WebSocket `Pool`\u002F`Client` is **created and closed inside one request handler** — never at module scope in a serverless function. Module scope = a connection that outlives the invocation and leaks.\n2. **App queries use the pooled string** (host contains `-pooler`). **Migrations \u002F DDL \u002F advisory locks \u002F session features use the direct string** (no `-pooler`). Mixing them is the #1 Neon foot-gun.\n3. The HTTP `neon()` driver **always** uses the pooled endpoint — don't hand it a direct string and expect session state.\n4. HTTP `neon()` has **no interactive transactions**. Need `BEGIN ... COMMIT` across round-trips? Use `sql.transaction([...])` (batched, non-interactive) or a WebSocket `Pool`.\n5. On Node.js ≤ 21 you **must** set `neonConfig.webSocketConstructor = ws` before opening a Pool\u002FClient. Node 22+ and edge runtimes have a global `WebSocket`; don't set it there.\n6. Pin the driver: `@neondatabase\u002Fserverless` is at **v1.1.0** (npm latest, 2026-04-17). It is a drop-in replacement for `pg`.\n\n## Pick your connection method\n\nKeyed by runtime and what the query needs. Pick the lightest transport that satisfies the need.\n\n| You need | Use | Why |\n| --- | --- | --- |\n| One independent read\u002Fwrite per request (edge, Lambda, RSC) | HTTP `neon()` | Single fetch round-trip (~3 round trips vs ~8 for TCP setup); no connection to manage or leak. |\n| Several queries that must be atomic, no logic between them | `sql.transaction([q1, q2])` over HTTP | One round-trip, real transaction, still no socket lifecycle. |\n| Interactive transaction — read a row, branch in app code, then write | WebSocket `Pool` (open+close in handler) | HTTP can't hold `BEGIN` open; WebSocket keeps the session alive within the request. |\n| Full `pg`-API compatibility (cursors, LISTEN\u002FNOTIFY, COPY) | WebSocket `Client`\u002F`Pool` | HTTP is one-shot; node-postgres semantics need the socket. |\n| Migrations \u002F DDL \u002F `pg_advisory_lock` \u002F session GUCs | direct (non-`-pooler`) string with `pg` or WebSocket `Client` | PgBouncer transaction-pooling breaks session-level state. |\n\nIf you're behind Drizzle or Prisma, you don't call these directly — you pass the driver to the\nadapter. See the ORM pointers below.\n\n## Connection strings: pooled vs direct\n\nNeon gives every branch two connection strings that differ in **one** thing: the host of the pooled\none contains `-pooler`.\n\n```text\npooled:  postgresql:\u002F\u002Fuser:pass@ep-cool-name-123456-pooler.us-east-2.aws.neon.tech\u002Fdb?sslmode=require\ndirect:  postgresql:\u002F\u002Fuser:pass@ep-cool-name-123456.us-east-2.aws.neon.tech\u002Fdb?sslmode=require\n```\n\n| Use case | String | Reason |\n| --- | --- | --- |\n| App runtime (queries from your functions) | **pooled** (`-pooler`) | PgBouncer fans many short-lived serverless invocations onto a small pool; up to 10,000 concurrent client connections per project. |\n| HTTP `neon()` driver | **pooled** (it forces it regardless) | The HTTP path is stateless; pooling is the right model. |\n| Migrations, DDL, schema introspection | **direct** | Transaction pooling drops session state; advisory locks and prepared statements need a stable session. |\n| `psql` interactive \u002F debugging | **direct** | You want one real session, not a pooled handle. |\n\nBad → Good for a typical setup:\n\n```bash\n# Bad: one string everywhere — migrations sporadically fail under PgBouncer.\nDATABASE_URL=\"postgresql:\u002F\u002F...-pooler...\u002Fdb?sslmode=require\"\n\n# Good: split them. App uses the pooled one; the migration tool uses DIRECT.\nDATABASE_URL=\"postgresql:\u002F\u002F...-pooler...\u002Fdb?sslmode=require\"          # app runtime\nDIRECT_URL=\"postgresql:\u002F\u002F......\u002Fdb?sslmode=require\"                    # migrations\u002FDDL\n```\n\n## Serverless driver patterns\n\nAll examples assume `@neondatabase\u002Fserverless@1.1.0`.\n\nHTTP one-shot — the default for edge\u002Fserverless reads and writes:\n\n```ts\nimport { neon } from \"@neondatabase\u002Fserverless\";\n\nconst sql = neon(process.env.DATABASE_URL!); \u002F\u002F pooled endpoint, no socket to manage\nexport async function getUser(id: string) {\n  const [row] = await sql`select id, email from users where id = ${id}`;\n  return row; \u002F\u002F parameterized; ${id} is bound, not interpolated\n}\n```\n\nBatched atomic writes over HTTP — atomicity without a WebSocket and without interactivity:\n\n```ts\nimport { neon } from \"@neondatabase\u002Fserverless\";\n\nconst sql = neon(process.env.DATABASE_URL!);\nawait sql.transaction([\n  sql`insert into orders (id, total) values (${id}, ${total})`,\n  sql`update inventory set qty = qty - 1 where sku = ${sku}`,\n]); \u002F\u002F one round-trip, both succeed or both roll back\n```\n\nInteractive transaction — WebSocket `Pool`, opened **and closed inside the handler**:\n\n```ts\nimport { Pool, neonConfig } from \"@neondatabase\u002Fserverless\";\nimport ws from \"ws\"; \u002F\u002F Node ≤21 only; omit on edge \u002F Node 22+\n\nneonConfig.webSocketConstructor = ws; \u002F\u002F required on Node ≤21; do NOT set on edge runtimes\n\nexport async function transfer(from: string, to: string, cents: number) {\n  const pool = new Pool({ connectionString: process.env.DATABASE_URL }); \u002F\u002F inside the handler\n  const client = await pool.connect();\n  try {\n    await client.query(\"begin\");\n    const { rows } = await client.query(\"select balance from accounts where id=$1 for update\", [from]);\n    if (rows[0].balance \u003C cents) throw new Error(\"insufficient\");\n    await client.query(\"update accounts set balance=balance-$1 where id=$2\", [cents, from]);\n    await client.query(\"update accounts set balance=balance+$1 where id=$2\", [cents, to]);\n    await client.query(\"commit\");\n  } catch (e) {\n    await client.query(\"rollback\");\n    throw e;\n  } finally {\n    client.release();\n    await pool.end(); \u002F\u002F close before the function returns — no leaked connection\n  }\n}\n```\n\nEdge runtime (Vercel Edge, Cloudflare Workers): use HTTP `neon()`; the global `WebSocket` exists, so a\n`Pool` works without `ws`, but prefer HTTP unless you truly need an interactive transaction.\n\nORM adapters — you wire the driver, the ORM owns the query API:\n\n- Drizzle: pass `neon()`\u002F`Pool` into `drizzle-orm\u002Fneon-http` or `neon-serverless` → `..\u002Fdrizzle-orm\u002FSKILL.md`.\n- Prisma: use the `@prisma\u002Fadapter-neon` driver adapter → `prisma-orm`.\n\n## Branching for dev \u002F preview \u002F CI\n\nA Neon branch is **copy-on-write**: created instantly with no data copied, it forks production at a\npoint in time, gets its own compute endpoint, and scales to zero independently. That makes a branch a\ncheap, isolated, full-data environment — not a backup substitute (test the restore).\n\n| Situation | Do | Why |\n| --- | --- | --- |\n| Per-developer or per-PR isolated data | **branch off production** | Instant, real prod-shaped data, separate endpoint, auto scale-to-zero → near-free idle. |\n| A genuinely separate product\u002Ftenant with its own billing & limits | **new project** | Branches share the project's quotas and pooled-connection ceiling. |\n| Throwaway query you can run against staging | **same branch** | Don't manufacture a branch for a one-off SELECT. |\n\n`neonctl` (alias `neon`) drives create\u002Fconnect\u002Fteardown:\n\n```bash\nneonctl branches create --name pr-$PR_NUMBER --parent main\nneonctl connection-string pr-$PR_NUMBER --pooled   # feed to the preview app\nneonctl branches delete pr-$PR_NUMBER              # on PR merge\u002Fclose\n```\n\n**Vercel preview integration:** with the Neon + Vercel integration, each preview deployment gets its\nown branch forked from production, auto-deleted when the PR merges or closes — zero CI code. If you're\nnot on Vercel, replicate it in CI: create branch on PR open → run migrations (direct string) → seed →\nexpose the pooled connection string to the app → delete on PR close. Full GitHub Actions workflow,\n`neonctl` reference, and the Neon API endpoints: [branching-ci](references\u002Fbranching-ci.md).\n\n**Branch-as-restore (PITR):** to recover, branch from an earlier point in time and either read from it\nor promote it. It's a fast undo, not a tested backup discipline — own that in `backups`.\n\n## Autoscaling & scale-to-zero\n\nEach branch's compute endpoint **autoscales** between a min and max CU (vCPU\u002FRAM) on its own, with no\nnoisy neighbors across branches. Idle compute **scales to zero** after **5 minutes** of inactivity\n(default), then resumes on the next connection with a millisecond-to-sub-second cold start.\n\nCost mental model: non-prod branches sit at zero almost always, so a dozen PR branches cost close to\nnothing. The cold start is the price.\n\nProd endpoint sizing checklist:\n\n- [ ] Set a sane **min\u002Fmax CU** for the prod branch — not maxed \"just in case\" (you pay for the max headroom you actually use).\n- [ ] Latency-sensitive prod with sparse traffic? **Disable scale-to-zero** or set **min CU > 0** so there's no cold start in p99.\n- [ ] Treat the cold start as real: warm the connection on deploy, or accept it on non-prod and account for it in latency SLOs.\n- [ ] Keep non-prod branches on scale-to-zero — that's where the near-free economics come from.\n\n## Anti-patterns\n\n| Anti-pattern | Why it bites | Do instead |\n| --- | --- | --- |\n| `new Pool(...)` at module scope in a serverless function | Connection outlives the invocation; you exhaust the pool → \"too many connections\". | Create and `await pool.end()` inside the handler, or use HTTP `neon()`. |\n| Pooled (`-pooler`) string for migrations\u002FDDL | PgBouncer transaction-pooling drops session state; advisory locks\u002Fprepared statements fail intermittently. | Use the **direct** string for migrations; pooled only for app runtime. |\n| Direct (non-`-pooler`) string as the app `DATABASE_URL` | No pooling → serverless concurrency exhausts raw connections fast. | App runtime always uses the **pooled** string. |\n| Expecting `BEGIN`\u002Finteractive txns from HTTP `neon()` | HTTP is one-shot, stateless — there's no open session to hold a transaction. | `sql.transaction([...])` for batched atomicity, or a WebSocket `Pool` for interactive. |\n| Opening a `Pool` without `neonConfig.webSocketConstructor = ws` on Node ≤21 | No global `WebSocket` → the connection silently fails. | Set `webSocketConstructor = ws` on Node ≤21; omit on edge \u002F Node 22+. |\n| Ignoring scale-to-zero in p99 latency | First request after 5 min idle pays the resume cold start; users see a slow request. | Disable scale-to-zero or set min CU > 0 on latency-sensitive prod. |\n| One shared branch for all PRs | PRs clobber each other's data; no isolation. | One branch per PR, deleted on close. |\n| Treating a branch as a backup without testing restore | Branches share project quotas and aren't an exercised recovery path. | Verify branch-as-restore; own real backup strategy in `backups`. |\n| Maxing CU \"to be safe\" | You pay for headroom you don't use; autoscaling already handles spikes. | Set a realistic min\u002Fmax; let autoscaling expand. |\n| Doing schema\u002Findex design in this skill | Engine craft is identical to any Postgres; duplicating it drifts. | Defer to `..\u002Fpostgresdb\u002FSKILL.md`. |\n\n## Cross-references\n\n- Engine craft (schema, indexes, EXPLAIN, RLS, zero-downtime DDL): `..\u002Fpostgresdb\u002FSKILL.md`.\n- Next.js App Router data layer that calls Neon: `..\u002Fnextjs\u002FSKILL.md`.\n- ORM query APIs over the Neon driver: `..\u002Fdrizzle-orm\u002FSKILL.md`, `prisma-orm`.\n- Deployment targets: `..\u002Fvercel\u002FSKILL.md`, `cloudflare`, `railway`. Backups discipline: `backups`.\n- Other managed DBs (route away): `supabase`, `planetscale`, `sqlite-turso`.\n","# Neon — serverless Postgres as a platform\n\nNeon is Postgres with three platform features the engine doesn't have: a **serverless driver** that\ntalks over HTTP\u002FWebSocket (so you can query from edge runtimes), **built-in connection pooling**, and\n**copy-on-write branching** that makes a fork of production data appear instantly. This skill owns\nthat platform layer. The Postgres *engine* underneath — schema, indexes, EXPLAIN, RLS, zero-downtime\nDDL — is identical to any Postgres 16 and belongs to `..\u002Fpostgresdb\u002FSKILL.md`. Don't re-derive engine\ncraft here; connect correctly and branch correctly.\n\n## When to use \u002F When NOT to use\n\n**When to use:**\n\n- Code imports `@neondatabase\u002Fserverless`, or `DATABASE_URL` points at `*.neon.tech` \u002F `*.aws.neon.tech`.\n- Connecting from Vercel (Edge\u002FNode), Cloudflare Workers, AWS Lambda, or any serverless\u002Fedge function — choosing HTTP `neon()` vs WebSocket `Pool`.\n- Setting up branching: dev branch off production, a branch per PR in CI, `neonctl` usage, the Neon + Vercel preview integration.\n- Neon-specific symptoms: cold start after scale-to-zero, \"too many connections\" despite being serverless, pooled-vs-direct string confusion, autoscaling CU sizing\u002Fcost.\n- Picking the connection string for migrations (direct) vs app queries (pooled).\n\n**When NOT to use — route to the sibling:**\n\n- Schema design, index choice, EXPLAIN\u002FANALYZE, query tuning, RLS, VACUUM, partitioning, expand-contract migrations → `..\u002Fpostgresdb\u002FSKILL.md`. Neon adds nothing to the engine; defer.\n- Drizzle schema\u002Fmigrations → `..\u002Fdrizzle-orm\u002FSKILL.md`; Prisma → `prisma-orm`. Neon supplies only the *driver adapter* line.\n- A different managed Postgres\u002FBaaS: Supabase (auth + storage + realtime) → `supabase`; PlanetScale → `planetscale`; Turso\u002FlibSQL → `sqlite-turso`.\n- Where to deploy the app talking to Neon → `..\u002Fvercel\u002FSKILL.md` \u002F `cloudflare` \u002F `railway`.\n- Backup\u002FPITR strategy as a discipline → `backups` (Neon branch-as-restore is mentioned here, not owned).\n\n## Non-negotiables\n\n1. A WebSocket `Pool`\u002F`Client` is **created and closed inside one request handler** — never at module scope in a serverless function. Module scope = a connection that outlives the invocation and leaks.\n2. **App queries use the pooled string** (host contains `-pooler`). **Migrations \u002F DDL \u002F advisory locks \u002F session features use the direct string** (no `-pooler`). Mixing them is the #1 Neon foot-gun.\n3. The HTTP `neon()` driver **always** uses the pooled endpoint — don't hand it a direct string and expect session state.\n4. HTTP `neon()` has **no interactive transactions**. Need `BEGIN ... COMMIT` across round-trips? Use `sql.transaction([...])` (batched, non-interactive) or a WebSocket `Pool`.\n5. On Node.js ≤ 21 you **must** set `neonConfig.webSocketConstructor = ws` before opening a Pool\u002FClient. Node 22+ and edge runtimes have a global `WebSocket`; don't set it there.\n6. Pin the driver: `@neondatabase\u002Fserverless` is at **v1.1.0** (npm latest, 2026-04-17). It is a drop-in replacement for `pg`.\n\n## Pick your connection method\n\nKeyed by runtime and what the query needs. Pick the lightest transport that satisfies the need.\n\n| You need | Use | Why |\n| --- | --- | --- |\n| One independent read\u002Fwrite per request (edge, Lambda, RSC) | HTTP `neon()` | Single fetch round-trip (~3 round trips vs ~8 for TCP setup); no connection to manage or leak. |\n| Several queries that must be atomic, no logic between them | `sql.transaction([q1, q2])` over HTTP | One round-trip, real transaction, still no socket lifecycle. |\n| Interactive transaction — read a row, branch in app code, then write | WebSocket `Pool` (open+close in handler) | HTTP can't hold `BEGIN` open; WebSocket keeps the session alive within the request. |\n| Full `pg`-API compatibility (cursors, LISTEN\u002FNOTIFY, COPY) | WebSocket `Client`\u002F`Pool` | HTTP is one-shot; node-postgres semantics need the socket. |\n| Migrations \u002F DDL \u002F `pg_advisory_lock` \u002F session GUCs | direct (non-`-pooler`) string with `pg` or WebSocket `Client` | PgBouncer transaction-pooling breaks session-level state. |\n\nIf you're behind Drizzle or Prisma, you don't call these directly — you pass the driver to the\nadapter. See the ORM pointers below.\n\n## Connection strings: pooled vs direct\n\nNeon gives every branch two connection strings that differ in **one** thing: the host of the pooled\none contains `-pooler`.\n\n```text\npooled:  postgresql:\u002F\u002Fuser:pass@ep-cool-name-123456-pooler.us-east-2.aws.neon.tech\u002Fdb?sslmode=require\ndirect:  postgresql:\u002F\u002Fuser:pass@ep-cool-name-123456.us-east-2.aws.neon.tech\u002Fdb?sslmode=require\n```\n\n| Use case | String | Reason |\n| --- | --- | --- |\n| App runtime (queries from your functions) | **pooled** (`-pooler`) | PgBouncer fans many short-lived serverless invocations onto a small pool; up to 10,000 concurrent client connections per project. |\n| HTTP `neon()` driver | **pooled** (it forces it regardless) | The HTTP path is stateless; pooling is the right model. |\n| Migrations, DDL, schema introspection | **direct** | Transaction pooling drops session state; advisory locks and prepared statements need a stable session. |\n| `psql` interactive \u002F debugging | **direct** | You want one real session, not a pooled handle. |\n\nBad → Good for a typical setup:\n\n```bash\n# Bad: one string everywhere — migrations sporadically fail under PgBouncer.\nDATABASE_URL=\"postgresql:\u002F\u002F...-pooler...\u002Fdb?sslmode=require\"\n\n# Good: split them. App uses the pooled one; the migration tool uses DIRECT.\nDATABASE_URL=\"postgresql:\u002F\u002F...-pooler...\u002Fdb?sslmode=require\"          # app runtime\nDIRECT_URL=\"postgresql:\u002F\u002F......\u002Fdb?sslmode=require\"                    # migrations\u002FDDL\n```\n\n## Serverless driver patterns\n\nAll examples assume `@neondatabase\u002Fserverless@1.1.0`.\n\nHTTP one-shot — the default for edge\u002Fserverless reads and writes:\n\n```ts\nimport { neon } from \"@neondatabase\u002Fserverless\";\n\nconst sql = neon(process.env.DATABASE_URL!); \u002F\u002F pooled endpoint, no socket to manage\nexport async function getUser(id: string) {\n  const [row] = await sql`select id, email from users where id = ${id}`;\n  return row; \u002F\u002F parameterized; ${id} is bound, not interpolated\n}\n```\n\nBatched atomic writes over HTTP — atomicity without a WebSocket and without interactivity:\n\n```ts\nimport { neon } from \"@neondatabase\u002Fserverless\";\n\nconst sql = neon(process.env.DATABASE_URL!);\nawait sql.transaction([\n  sql`insert into orders (id, total) values (${id}, ${total})`,\n  sql`update inventory set qty = qty - 1 where sku = ${sku}`,\n]); \u002F\u002F one round-trip, both succeed or both roll back\n```\n\nInteractive transaction — WebSocket `Pool`, opened **and closed inside the handler**:\n\n```ts\nimport { Pool, neonConfig } from \"@neondatabase\u002Fserverless\";\nimport ws from \"ws\"; \u002F\u002F Node ≤21 only; omit on edge \u002F Node 22+\n\nneonConfig.webSocketConstructor = ws; \u002F\u002F required on Node ≤21; do NOT set on edge runtimes\n\nexport async function transfer(from: string, to: string, cents: number) {\n  const pool = new Pool({ connectionString: process.env.DATABASE_URL }); \u002F\u002F inside the handler\n  const client = await pool.connect();\n  try {\n    await client.query(\"begin\");\n    const { rows } = await client.query(\"select balance from accounts where id=$1 for update\", [from]);\n    if (rows[0].balance \u003C cents) throw new Error(\"insufficient\");\n    await client.query(\"update accounts set balance=balance-$1 where id=$2\", [cents, from]);\n    await client.query(\"update accounts set balance=balance+$1 where id=$2\", [cents, to]);\n    await client.query(\"commit\");\n  } catch (e) {\n    await client.query(\"rollback\");\n    throw e;\n  } finally {\n    client.release();\n    await pool.end(); \u002F\u002F close before the function returns — no leaked connection\n  }\n}\n```\n\nEdge runtime (Vercel Edge, Cloudflare Workers): use HTTP `neon()`; the global `WebSocket` exists, so a\n`Pool` works without `ws`, but prefer HTTP unless you truly need an interactive transaction.\n\nORM adapters — you wire the driver, the ORM owns the query API:\n\n- Drizzle: pass `neon()`\u002F`Pool` into `drizzle-orm\u002Fneon-http` or `neon-serverless` → `..\u002Fdrizzle-orm\u002FSKILL.md`.\n- Prisma: use the `@prisma\u002Fadapter-neon` driver adapter → `prisma-orm`.\n\n## Branching for dev \u002F preview \u002F CI\n\nA Neon branch is **copy-on-write**: created instantly with no data copied, it forks production at a\npoint in time, gets its own compute endpoint, and scales to zero independently. That makes a branch a\ncheap, isolated, full-data environment — not a backup substitute (test the restore).\n\n| Situation | Do | Why |\n| --- | --- | --- |\n| Per-developer or per-PR isolated data | **branch off production** | Instant, real prod-shaped data, separate endpoint, auto scale-to-zero → near-free idle. |\n| A genuinely separate product\u002Ftenant with its own billing & limits | **new project** | Branches share the project's quotas and pooled-connection ceiling. |\n| Throwaway query you can run against staging | **same branch** | Don't manufacture a branch for a one-off SELECT. |\n\n`neonctl` (alias `neon`) drives create\u002Fconnect\u002Fteardown:\n\n```bash\nneonctl branches create --name pr-$PR_NUMBER --parent main\nneonctl connection-string pr-$PR_NUMBER --pooled   # feed to the preview app\nneonctl branches delete pr-$PR_NUMBER              # on PR merge\u002Fclose\n```\n\n**Vercel preview integration:** with the Neon + Vercel integration, each preview deployment gets its\nown branch forked from production, auto-deleted when the PR merges or closes — zero CI code. If you're\nnot on Vercel, replicate it in CI: create branch on PR open → run migrations (direct string) → seed →\nexpose the pooled connection string to the app → delete on PR close. Full GitHub Actions workflow,\n`neonctl` reference, and the Neon API endpoints: [branching-ci](references\u002Fbranching-ci.md).\n\n**Branch-as-restore (PITR):** to recover, branch from an earlier point in time and either read from it\nor promote it. It's a fast undo, not a tested backup discipline — own that in `backups`.\n\n## Autoscaling & scale-to-zero\n\nEach branch's compute endpoint **autoscales** between a min and max CU (vCPU\u002FRAM) on its own, with no\nnoisy neighbors across branches. Idle compute **scales to zero** after **5 minutes** of inactivity\n(default), then resumes on the next connection with a millisecond-to-sub-second cold start.\n\nCost mental model: non-prod branches sit at zero almost always, so a dozen PR branches cost close to\nnothing. The cold start is the price.\n\nProd endpoint sizing checklist:\n\n- [ ] Set a sane **min\u002Fmax CU** for the prod branch — not maxed \"just in case\" (you pay for the max headroom you actually use).\n- [ ] Latency-sensitive prod with sparse traffic? **Disable scale-to-zero** or set **min CU > 0** so there's no cold start in p99.\n- [ ] Treat the cold start as real: warm the connection on deploy, or accept it on non-prod and account for it in latency SLOs.\n- [ ] Keep non-prod branches on scale-to-zero — that's where the near-free economics come from.\n\n## Anti-patterns\n\n| Anti-pattern | Why it bites | Do instead |\n| --- | --- | --- |\n| `new Pool(...)` at module scope in a serverless function | Connection outlives the invocation; you exhaust the pool → \"too many connections\". | Create and `await pool.end()` inside the handler, or use HTTP `neon()`. |\n| Pooled (`-pooler`) string for migrations\u002FDDL | PgBouncer transaction-pooling drops session state; advisory locks\u002Fprepared statements fail intermittently. | Use the **direct** string for migrations; pooled only for app runtime. |\n| Direct (non-`-pooler`) string as the app `DATABASE_URL` | No pooling → serverless concurrency exhausts raw connections fast. | App runtime always uses the **pooled** string. |\n| Expecting `BEGIN`\u002Finteractive txns from HTTP `neon()` | HTTP is one-shot, stateless — there's no open session to hold a transaction. | `sql.transaction([...])` for batched atomicity, or a WebSocket `Pool` for interactive. |\n| Opening a `Pool` without `neonConfig.webSocketConstructor = ws` on Node ≤21 | No global `WebSocket` → the connection silently fails. | Set `webSocketConstructor = ws` on Node ≤21; omit on edge \u002F Node 22+. |\n| Ignoring scale-to-zero in p99 latency | First request after 5 min idle pays the resume cold start; users see a slow request. | Disable scale-to-zero or set min CU > 0 on latency-sensitive prod. |\n| One shared branch for all PRs | PRs clobber each other's data; no isolation. | One branch per PR, deleted on close. |\n| Treating a branch as a backup without testing restore | Branches share project quotas and aren't an exercised recovery path. | Verify branch-as-restore; own real backup strategy in `backups`. |\n| Maxing CU \"to be safe\" | You pay for headroom you don't use; autoscaling already handles spikes. | Set a realistic min\u002Fmax; let autoscaling expand. |\n| Doing schema\u002Findex design in this skill | Engine craft is identical to any Postgres; duplicating it drifts. | Defer to `..\u002Fpostgresdb\u002FSKILL.md`. |\n\n## Cross-references\n\n- Engine craft (schema, indexes, EXPLAIN, RLS, zero-downtime DDL): `..\u002Fpostgresdb\u002FSKILL.md`.\n- Next.js App Router data layer that calls Neon: `..\u002Fnextjs\u002FSKILL.md`.\n- ORM query APIs over the Neon driver: `..\u002Fdrizzle-orm\u002FSKILL.md`, `prisma-orm`.\n- Deployment targets: `..\u002Fvercel\u002FSKILL.md`, `cloudflare`, `railway`. Backups discipline: `backups`.\n- Other managed DBs (route away): `supabase`, `planetscale`, `sqlite-turso`.\n",{"name":5,"tags":24,"origin":30,"recommends":31,"description":7},[5,25,26,27,28,29],"postgres","serverless","database","branching","edge","risco",[32,33,34,35],"postgresdb","drizzle-orm","prisma-orm","vercel","main","d69096e239f2a89aabc2cd078c47664a9d3b1e11","04-安全渗透\u002Fneon",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":45,"prompt":55,"zipAvailable":56},[46,49,52],{"tool":47,"command":48},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill neon",{"tool":50,"command":51},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill neon",{"tool":53,"command":54},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill neon","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fneon\u002FSKILL.md",true,[58,64,68],{"path":59,"resourceType":60,"resourceTypeDesc":61,"sizeBytes":62,"sourceHtmlUrl":63},"evals\u002Fcases.yaml","REFERENCE","参考文档",3035,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fneon\u002Fevals\u002Fcases.yaml",{"path":65,"resourceType":60,"resourceTypeDesc":61,"sizeBytes":66,"sourceHtmlUrl":67},"evals\u002FREADME.md",855,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fneon\u002Fevals\u002FREADME.md",{"path":69,"resourceType":60,"resourceTypeDesc":61,"sizeBytes":70,"sourceHtmlUrl":71},"references\u002Fbranching-ci.md",3594,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fneon\u002Freferences\u002Fbranching-ci.md",[73,81,86,93,100,107],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":80},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":82,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":80},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":80},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":80},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":80},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":80},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]