
prisma-next-queries
Write Prisma Next queries for Postgres, SQLite, or Mongo — pick a lane (Postgres/SQLite db.orm. + db.sql. ; Mongo db.orm. + db.query.from(...) pipeline builder), filter / project / sort / paginate, eager-load with .include(...), Postgres/SQLite db.transaction(...), Postgres/SQLite ORM .aggregate(...), Mongo aggregations via query builder, namespace-aware accessors (db.orm. . , db.sql. . ). Triggers: query, where, match, select, project, orderBy, take, skip, include, lookup, first, all, count, aggregate, group, create, update, delete, upsert, returning, transaction, db.close, script teardown, variant, polymorphism, drizzle-style, kysely-style. Notes: .all() is a Thenable (just await it), iterators are single-use (RUNTIME.ITERATORCONSUMED), Postgres count is number while sum/avg/min/max are number null, ranges use chained .where() or and(...) (no .between(...)).
- Installs
- 2.1K
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/prisma/prisma-next --skill prisma-next-queries- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads prisma-next-queries automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Prisma Next — Queries
Edit your data contract. Prisma handles the rest.
Once the contract is emitted and the DB is up to date, this skill covers everything you do with the data: reading, writing, eager-loading relations, aggregating, and the choice between the ORM and the lower-level query lane.
When to Use
- User wants to read, write, update, or delete data.
- User wants to include / eager-load relations.
- User wants to paginate, sort, filter, project.
- User wants to wrap operations in a transaction (
db.transaction(...)— Postgres and SQLite). - User wants to aggregate (
count,sum,avg, …). - User asks about query lanes (ORM vs SQL builder / query builder).
- User mentions: query, select, where, orderBy, take, skip, include, eager load, first, all, count, aggregate, create, update, delete, upsert, returning, drizzle-style, kysely-style, prisma client.
When Not to Use
- User wants to add / change a model →
prisma-next-contract. - User wants to wire
db.tsor add middleware →prisma-next-runtime. - User is querying through a Supabase role-bound db (
asUser/asAnon/asServiceRole, RLS,auth.*admin reads) →prisma-next-supabasefor the role-binding surface; everything in this skill then applies to the returnedRoleBoundDb. - User wants to debug a query failure (structured error envelope) →
prisma-next-debug.
Pick your target
Prisma Next ships two query lanes per target on the same db value from src/prisma/db.ts. Before writing queries, read db.ts and load the matching target guide:
Runtime import in db.ts | Load |
|---|---|
@prisma-next/postgres/runtime | postgres.md — db.orm.<Model> + db.sql.<table> |
@prisma-next/mongo/runtime | mongo.md — db.orm.<root> + db.query.from(...) |
@prisma-next/extension-supabase/runtime | postgres.md — a Supabase RoleBoundDb is a Postgres surface (db.orm.<Model> + db.sql.<table>); bind a role first via prisma-next-supabase |
Both targets share the contract and connection on one db value. Reach for the ORM first; drop to the lower-level lane when the ORM can't express the shape. Lane choice is local — one query function picks one lane, not the whole app.
Do not mix target examples. Postgres uses PascalCase model roots (db.orm.User) and db.sql.user; Mongo uses lowercased plural roots (db.orm.users) and db.query.from('users'). There is no db.sql on Mongo and no db.query SQL-builder equivalent on Postgres.
Namespace-aware accessors
When a contract declares more than one namespace (e.g. public and auth), models and tables are addressed by namespace coordinate:
- ORM:
db.orm.<namespace>.<Model>— e.g.db.orm.public.User,db.orm.auth.User - SQL builder:
db.sql.<namespace>.<table>— e.g.db.sql.public.users,db.sql.auth.users
The flat db.orm.User / db.sql.users form still works for single-namespace contracts (or when all table names are unique across namespaces). When the same bare name appears in more than one namespace, you must use the namespace coordinate.
See postgres.md § Namespace-aware accessors for a worked example.
Consuming the result: await, .toArray(), or for await
Critical to get right early — on both Postgres and Mongo, .all() returns an AsyncIterableResult<Row>, which is both a PromiseLike<Row[]> and an AsyncIterable<Row>. That means three consumption forms all work, and the canonical one is the shortest:
const users = await db.orm.User.select('id', 'email').all();
// ^? Row[] ← the Thenable resolves to a real array. This is the default idiom.
You do not need a collect() / toArray() helper — await is enough. Internally await invokes the result's then(...), which buffers the rows into an array. Two equivalent alternatives exist for the cases where they read better:
// `.toArray()` returns a genuine `Promise<Row[]>`. Reach for it only when
// something needs a real `Promise` and not merely a thenable: a slot typed
// `Promise<Row[]>` (an `AsyncIterableResult` has only `then`, not `catch` /
// `finally`, so it does not satisfy that annotation), or a runtime
// `instanceof Promise` check. Note that `await` and the `Promise.all` /
// `Promise.race` combinators all accept the thenable directly — those are
// NOT reasons to call `.toArray()`. Whenever you are just going to await it
// here, use `await ...all()` and skip `.toArray()`.
const rows: Promise<User[]> = db.orm.User.select('id', 'email').all().toArray();
// Streaming — process rows one at a time without buffering the whole result.
// Use for genuinely large result sets (anything that wouldn't fit comfortably
// in memory) or pipelines where you can start work before all rows arrive.
for await (const user of db.orm.User.select('id', 'email').all()) {
process(user);
}
Two single-row shortcuts also exist on the result, in addition to the collection-level .first() (which issues LIMIT 1 on Postgres):
const user = await db.orm.User.where({ id }).all().first();
// ^? Row | null ← buffers, returns the first row or null. Issues no LIMIT.
const required = await db.orm.User.where({ id }).all().firstOrThrow();
// ^? Row ← buffers; throws `RUNTIME.NO_ROWS` if empty.
For genuine single-row reads, prefer the collection-level .first() (which adds LIMIT 1 to the SQL on Postgres) over .all().first() (which fetches all rows and discards the rest). The result-level helpers are for cases where you already need the full result and want the first row without an extra round-trip.
The result is single-consumption. Each AsyncIterableResult instance can be consumed once — by await, by .toArray(), or by for await. Trying to consume it a second time throws RUNTIME.ITERATOR_CONSUMED. The fix is almost always to store the array in a variable on first consumption and reuse the variable:
// Bad — second await throws RUNTIME.ITERATOR_CONSUMED.
const result = db.orm.User.select('id', 'email').all();
const a = await result;
const b = await result;
// Good — buffer once, reuse the array.
const users = await db.orm.User.select('id', 'email').all();
const a = users;
const b = users;
If you've seen collect(...) / toArray(...) helpers in a codebase wrapping .all(), they're vestigial — await does the same thing for free. Remove them when you touch the surrounding code.
Running queries from a short script
When the user is running a one-off tsx my-script.ts (not a long-lived server), call await db.close() at the end so the process exits cleanly — on Postgres the façade-owned pool keeps Node's event loop alive; on Mongo the façade-owned MongoClient does the same. See prisma-next-runtime § Running as a script (teardown) for the full pattern including await using.
// src/scripts/seed.ts
import { db } from '../prisma/db';
// Postgres — PascalCase model root from contract
for (const u of users) {
await db.orm.User.create(u);
}
// Mongo — lowercased plural root from contract (e.g. users, not User)
// for (const u of users) {
// await db.orm.users.create(u);
// }
console.log('Seeded.');
await db.close();
Common Pitfalls (cross-target)
- Using Postgres examples on a Mongo project (or vice versa). Check
db.tsand load the correct target guide (postgres.mdormongo.md). - Writing a
collect()/toArray()helper to convert.all()to an array..all()returns anAsyncIterableResult<Row>which is aPromiseLike<Row[]>—await collection.all()directly yieldsRow[]. See Consuming the result above. - Consuming an
AsyncIterableResulttwice. Each result is single-use. The second consumer throwsRUNTIME.ITERATOR_CONSUMED. Buffer once into a variable and reuse the variable.
Target-specific pitfalls live in the per-target guides.
What Prisma Next doesn't do yet
- N:M
.include()across a junction table. The contract IR supports many-to-many relations with athroughjunction table, andN:Mrelations appear as valid relation names on the ORM collection. However,.include()on an N:M relation does not emit the two-step junction join — the query plan builder only handles the direct join columns (localColumn/targetColumn) and ignores thethroughmetadata. Attempting it either produces wrong results or an error. Workaround: express the N:M traversal throughdb.sql.<table>with an explicit join on the junction table. - N:M nested mutations.
mutation-executor.tsexplicitly throws'N:M nested mutations are not supported yet'for nested creates/links through an N:M relation. and/or/notcombinators in the postgres façade. The combinators currently import from@prisma-next/sql-orm-client(an internal package). Workaround today: import them from@prisma-next/sql-orm-clientdirectly, the way the example apps do. If you want them on@prisma-next/postgres/runtime, file a feature request viaprisma-next-feedback..orderBy(...)/.take(...)on grouped aggregates (Postgres).db.orm.<Model>.groupBy(...).aggregate(...)materializes aPromise<Array<Group & Aggregates>>and exposes neither ordering nor row limits at the DB layer. Result: a "top-N groups by SUM" query falls back to JS-side sort + slice over the full grouped result, which is fine at small cardinalities and bad at scale. Workarounds: (a) drop todb.sql.<table>and write theGROUP BY+ORDER BY+LIMITagainst the aggregated table directly; (b) live with the JS-side sort/slice if the grouped cardinality is bounded. File a feature request viaprisma-next-feedbackif this is hitting you in production.- A raw-SQL lane. Prisma Next does not currently expose a user-facing raw-SQL surface (no
db.sql.raw(...)). Workaround: model the query through the SQL builder or — for shapes the builder can't yet express — file a feature request viaprisma-next-feedbackdescribing the shape so the team can decide whether to grow the builder or ship a raw lane. - TypedSQL (
.sqlfiles compiled into typed callables). Not implemented. Workaround: stick to the SQL builder; for repeated queries, extract a function that returns the built plan and calldb.runtime().execute(plan)at the call site. If you want a.sql-file compile path, file a feature request viaprisma-next-feedback. EXPLAIN/ query-plan inspection. Prisma Next does not expose an.explain()method. Workaround: connect apg.Poolyou control via the runtime'spg:binding (seeprisma-next-runtime) and issueEXPLAIN ANALYZEthrough it. If you want a first-class plan-inspection surface, file a feature request viaprisma-next-feedback.- Streaming large result sets. No
.stream()cursor today. Workaround: paginate via.skip(n).take(m)for moderate sizes; for very large sets, hold apg.Clientfrom the runtime'spg:binding and stream through it directly. If you want a built-in streaming surface, file a feature request viaprisma-next-feedback. - Multi-statement batching (Prisma-7-style
db.$transaction([call1, call2])). Prisma Next runs each call sequentially. Workaround: wrap atomically-related work indb.transaction(async (tx) => { ... })on Postgres. If you want batch-as-array semantics, file a feature request viaprisma-next-feedback. - Mongo façade transactions.
@prisma-next/mongo/runtimedoes not exposedb.transaction(...). Multi-document atomicity is not yet wrapped in the Prisma Next Mongo façade. Workaround: use the MongoDB driver's session API directly if you control the client binding (mongoClient:option). File a feature request viaprisma-next-feedbackif you need a first-class façade surface. - Mongo ORM aggregates. No
.aggregate(...)/.groupBy(...)ondb.orm.<root>. Workaround: express aggregations throughdb.query.from(...).group(...).build()andruntime.execute(plan). - Mongo filter helpers on the façade. Rich filters (
.in, ranges, boolean composition) currently import from@prisma-next/mongo-query-ast/execution(MongoFieldFilter, etc.) — not yet re-exported on@prisma-next/mongo/runtime. Workaround: use object equality.where({ field: value })where possible; import from the internal package only when necessary. Tracked alongside façade-completeness gaps in LinearTML-2526. - Automatic N+1 detection. Prisma Next does not warn when an
.include(...)is missing. Workaround: be deliberate about.include(...)in code review; thelintsmiddleware (seeprisma-next-runtime) catches the more common authoring slips (missingWHEREon aDELETE/UPDATE, missingLIMITon aSELECT).
Reference Files
This skill is split for selective loading. Target-specific reference paths live in the per-target guides:
- Postgres —
postgres.md§ Reference Files - Mongo —
mongo.md§ Reference Files
Checklist
- Confirmed the active target from
db.tsand loaded the matching guide (postgres.mdormongo.md). - For multi-namespace contracts, used
db.orm.<ns>.<Model>/db.sql.<ns>.<table>coordinates when the same bare name exists in more than one namespace. - Chose the right lane (ORM by default; lower-level builder for shapes the ORM doesn't express).
- Used
.first()/.first({ pk })(Postgres) or.where({ ... }).first()(Mongo) for single-row reads — not.all(). - Consumed
.all()with plainawait(not acollect()/toArray()helper). Usedfor awaitonly when streaming is actually wanted, and never iterated the same result twice. - Did NOT use
db.sqlon a Mongo project ordb.querywhere the Postgres SQL builder is meant. - Completed the target-specific checklist in the loaded guide.
FAQ
What does the prisma-next-queries skill do?
Write Prisma Next queries for Postgres, SQLite, or Mongo — pick a lane (Postgres/SQLite db.orm. + db.sql. ; Mongo db.orm. + db.query.from(...) pipeline builder), filter / project / sort / paginate, eager-load with .include(...), Postgres/SQLite db.transaction(...), Postgres/SQLite ORM .aggregate(...), Mongo aggregations via query builder, namespace-aware accessors (db.orm. . , db.sql. . ). Triggers: query, where, match, select, project, orderBy, take, skip, include, lookup, first, all, count, aggregate, group, create, update, delete, upsert, returning, transaction, db.close, script teardown, variant, polymorphism, drizzle-style, kysely-style. Notes: .all() is a Thenable (just await it), iterators are single-use (RUNTIME.ITERATORCONSUMED), Postgres count is number while sum/avg/min/max are number null, ranges use chained .where() or and(...) (no .between(...)).
How do I install prisma-next-queries?
Run npx skills add https://github.com/prisma/prisma-next --skill prisma-next-queries in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/prisma-next-queries/ (personal) or .claude/skills/prisma-next-queries/ (project).
Which AI agents can use prisma-next-queries?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is prisma-next-queries safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains prisma-next-queries?
It is published by prisma in prisma/prisma-next, and it is an official skill from the maker of the technology it covers. It has 2,071 recorded installs.
More from prisma/prisma-next
prisma-next
prisma/prisma-next
Route a vague Prisma Next prompt to the right specific skill. Use for "help me with Prisma Next", "what is Prisma Next", "explain Prisma Next", "I'm new to PN", "where do I start", "what can I do with Prisma Next", "what can I do next with Prisma", "just ran createprisma", "tour of Prisma Next", "Prisma Next overview", and comparison questions like "Prisma Next vs Prisma 7", "PN vs Drizzle", "PN vs Kysely", "PN vs TypeORM". Do NOT use when the prompt clearly matches a workflow skill — adoption / quickstart / first-touch orientation / brownfield introspection, schema / contract editing, migration authoring (db update / migration plan / migrate), migration review on deploy / concurrent migrations, queries / db.orm / db.sql / TypedSQL, Supabase / RLS / role binding, runtime / db.ts / middleware wiring, build / Vite plugin / Next.js plugin, debug / structured error envelopes / PN- error codes, or feedback / bug report / feature request — load that sibling skill directly.
prisma-next-migrations
prisma/prisma-next
Author Prisma Next migrations — choose db update vs migration plan, edit the framework-rendered migration.ts (replace placeholder sentinels with dataTransform closures), recover from MIGRATION.HASHMISMATCH or PN-MIG-2001 unfilled placeholder. Use for prisma migrate dev, prisma migrate deploy, prisma db push, db update, db update --dry-run, migration plan, migrate, migration new, migration show, db verify, db sign, data migration, this.dataTransform, dataTransform, placeholder, generated migration.ts, edit migration.ts, MIGRATION.HASHMISMATCH, schema drift.
prisma-next-migration-review
prisma/prisma-next
Review what Prisma Next migrations will run on merge or deploy, render the migration graph, resolve concurrent / diamond-convergence conflicts, and configure environment refs for CI. Use for "what migrations are going to run", "what runs on deploy", merge conflict, diamond convergence, concurrent migrations, migration status, ref management, staging, production, MIGRATION.DIVERGED, MIGRATION.NOMARKER, MIGRATION.MARKERNOTINHISTORY, prisma migrate status, prisma migrate diff, prisma migrate resolve.
prisma-next-debug
prisma/prisma-next
Read a Prisma Next structured error envelope and route to the right recovery — code, domain, severity, why, fix, meta. Use for error, exception, my emit failed, my query won't typecheck, my query crashed, my migration won't apply, MIGRATION.HASHMISMATCH, BUDGET.ROWSEXCEEDED, BUDGET.TIMEEXCEEDED, RUNTIME.ABORTED, PLAN.HASHMISMATCH, CONTRACT.MARKERMISSING, PN-RUN-3001, PN-RUN-3002, PN-RUN-3030, PN-MIG-2001, PN-CLI-4011, PN-SCHEMA-0001, drift, capability missing, planner conflict, prisma studio, EXPLAIN, query log, db.end, db.close, script won't exit, hangs, close connection, pool.end, client is closed.
prisma-next-runtime
prisma/prisma-next
Wire the Prisma Next runtime — db.ts setup using postgres (...) from @prisma-next/postgres/runtime, sqlite (...) from @prisma-next/sqlite/runtime, or mongo (...) from @prisma-next/mongo/runtime; middleware composition (telemetry from @prisma-next/middleware-telemetry; lints and budgets), DATABASEURL config, per-environment branching, switching between Postgres, SQLite, and Mongo façades. Use for db.ts, postgres(), sqlite(), mongo(), middleware, telemetry, lints, budgets, DATABASEURL, .env, connection pool, poolOptions, dev vs prod config, transactions, db.transaction, read replicas, multi-database, script won't exit, hangs, close connection, db.end, db.close, pool.end, [Symbol.asyncDispose], await using.
prisma-next-build
prisma/prisma-next
Wire Prisma Next into the project's build system with the right build-tool plugin — Vite today via @prisma-next/vite-plugin-contract-emit (Vite 7 / 8); Next.js / Webpack / esbuild / Rollup / Turbopack are named as gaps rather than fabricated. Always offers the Vite plugin proactively when the project is using Vite. Use for vite plugin, vite-plugin, vite.config.ts, prismaVitePlugin, contract emit on save, HMR, hot reload contract, dev server, Next.js plugin, next plugin, withPrismaNext, webpack plugin, esbuild plugin, rollup plugin, build integration, dev server plugin, vite 7, vite 8.
Popular data & databases skills
supabase-postgres-best-practices
supabase/agent-skills
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pgcron, pgmq), vector/semantic search (pgvector), and restoring dumps (pgrestore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.
prisma-client-api
prisma/skills
Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on "prisma query", "findMany", "create", "update", "delete", "$transaction".
prisma-database-setup
prisma/skills
Deprecated compatibility name for prisma-orm-setup. Use only when a user or existing integration explicitly invokes prisma-database-setup; otherwise select prisma-orm-setup.
prisma-cli
prisma/skills
Prisma ORM 7 CLI reference for existing Prisma 7 applications or explicitly selected Prisma 7 workflows. Covers prisma init, generate, migrate, db, dev, studio, and mcp. For setup, connection repair, or Prisma 8, use prisma-orm-setup; not the Prisma Platform CLI.
prisma-postgres
prisma/skills
Deprecated compatibility name for prisma-postgres-setup. Use only when a user or existing integration explicitly invokes prisma-postgres; otherwise select prisma-postgres-setup.
prisma-driver-adapter-implementation
prisma/skills
Required reference for Prisma ORM 7 SQL driver adapter work. Use when implementing or modifying adapters, adding database drivers, or touching SqlDriverAdapter, Transaction, savepoint, result mapping, or DriverAdapterError behavior. Covers current transaction lifecycle, optional savepoint hooks, original database-error preservation, and verification.