Aalexbit-codemod

mine-prisma-sql-index-risks

Detect possible missing-index risks in Prisma queries and embedded SQL

prismasqlindexesmininganalysis
Public
3 executions

Run locally

npx codemod mine-prisma-sql-index-risks

mine-prisma-sql-index-risks

Read-only mining codemod that reports possible missing-index risks in JavaScript and TypeScript source.

What It Detects

  • Prisma object-literal queries on findMany, findFirst, and findUnique
  • Embedded SQL in string literals, template literals, and SQL-tagged or Prisma raw-query templates

The codemod emits warning findings with rule id possible-missing-db-index and does not modify source files.

Prisma Findings

Flags Prisma calls when either condition is present:

  • where combined with orderBy
  • nested contains inside where

When available, findings include:

  • model name
  • operation name
  • predicate fields from where
  • order fields from orderBy
  • source location
  • a compact query summary

Example:

ts

Embedded SQL Findings

Flags embedded SQL when either condition is present:

  • WHERE together with ORDER BY
  • leading-wildcard LIKE '%...' or ILIKE '%...'

When available, findings include:

  • table name from FROM ...
  • obvious predicate columns from WHERE
  • obvious sort columns from ORDER BY
  • whether leading-wildcard matching was detected
  • source location

Example:

ts

Suppressions

The codemod skips obvious test and mock paths:

  • __tests__
  • test
  • tests
  • fixtures
  • __mocks__
  • mocks
  • files ending in .test.* or .spec.*

Usage

bash

Development

bash

Test Coverage

Fixtures cover:

  • Prisma findMany with where and orderBy
  • Prisma findFirst with contains
  • Prisma findUnique with where and orderBy
  • orderBy arrays
  • embedded SQL strings with WHERE ... ORDER BY
  • embedded SQL strings with leading-wildcard LIKE
  • tagged template and Prisma raw-query usage
  • suppressed test and mock paths
  • no source rewrites for mining-only runs

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.