Registry / database / prisma-mysql-explain

prisma-mysql-explain

JSON →
library0.3.0jsnpmunverified

Execute MySQL EXPLAIN for Prisma queries in development environments. Current stable version is 0.3.0, released on an as-needed cadence. It intercepts Prisma query events, runs EXPLAIN, and caches results to avoid redundant executions. Key differentiators: deeply integrates with Prisma's event system, supports multiple caching strategies (by query, by params, or none), and provides typed results. Designed exclusively for development; not safe for production.

npm install prisma-mysql-explain
INSTALL
IMPORT
SIG · PRISMA-MYSQL-EXPLA
P
prisma-mysql-explain
databasejavascriptv0.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createExplain
import { createExplain } from 'prisma-mysql-explain'
const createExplain = require('prisma-mysql-explain')
Package is ESM-only since v0.1.0; CommonJS require will fail.
ExplainResult
import type { ExplainResult } from 'prisma-mysql-explain'
TypeScript only; no runtime value.
Option
import type { Option } from 'prisma-mysql-explain'
TypeScript only; no runtime value.

Set up Prisma with query event logging and create an explain listener that logs EXPLAIN results for every query.

import { PrismaClient } from '@prisma/client'; import { createExplain } from 'prisma-mysql-explain'; const prisma = new PrismaClient({ log: [{ level: 'query', emit: 'event' }] }); const prismaExplain = createExplain(prisma, { cacheType: 'query' }); prisma.$on('query', async (event) => { const result = await prismaExplain.explain(event); if (result) { console.log(result); } }); async function main() { const users = await prisma.user.findMany(); console.log(users); } main() .catch(e => console.error(e)) .finally(() => prisma.$disconnect());
Debug
Known issues
breakingcreateExplain API changed from synchronous to asynchronous in v0.2.0
fix
Update code: use `const explainer = createExplain(prisma, opts);` (no longer `new Explain()`).
affects: <0.2.0
gotchaOnly works with MySQL databases; will throw or return empty results for other database types.
fix
Ensure PrismaClient is connected to a MySQL database.
affects: >=0.1.0
gotchaRequires Prisma query event logging to be enabled: `log: [{ level: 'query', emit: 'event' }]`.
fix
Pass the log option when instantiating PrismaClient.
affects: >=0.1.0
deprecatedThe `param` cacheType option is deprecated and will be removed in a future version.
fix
Use `query` cacheType instead to achieve similar behavior.
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: createExplain is not a function
Imported using default import instead of named import.
fix
Use `import { createExplain } from 'prisma-mysql-explain'`.
Cannot find module 'prisma-mysql-explain' or its corresponding type declarations.
Package is ESM-only; using CommonJS require or missing tsconfig.json settings.
fix
Ensure tsconfig.json has `"module": "ESNext"` or run with `--experimental-modules` flag.
Property 'explain' does not exist on type 'typeof import(...)'.
Using wrong import for the explain function.
fix
Import `createExplain` and then call it to get an object with the `explain` method.
Expected 1-2 arguments, but got 0.
Calling `createExplain()` without any arguments.
fix
Call `createExplain(prisma)` or `createExplain(prisma, { cacheType: 'query' })`.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
@prisma/clientrequiredPeer dependency; needed to access PrismaClient and QueryEvent types
prismarequiredPeer dependency; required for Prisma CLI and schema generation
Agent activity
7 hits · last 30 days
node
6
Resources
prisma-mysql-explain — npm install prisma-mysql-explain · libregistry