
Security News
minimatch Patches 3 High-Severity ReDoS Vulnerabilities
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.
@prisma/sqlcommenter
Advanced tools
Type definitions for SQL commenter plugins in Prisma Client.
This package provides TypeScript types for creating SQL commenter plugins that add metadata to SQL queries as comments. The comments follow the sqlcommenter format developed by Google.
SQL comments are useful for:
traceparentnpm install @prisma/sqlcommenter
A SQL commenter plugin is a function that receives query context and returns key-value pairs to be added as comments:
import type { SqlCommenterPlugin, SqlCommenterContext } from '@prisma/sqlcommenter'
const myPlugin: SqlCommenterPlugin = (context: SqlCommenterContext) => {
return {
application: 'my-app',
version: '1.0.0',
}
}
Pass your plugins to the comments option when creating a PrismaClient instance:
import { PrismaClient } from '@prisma/client'
import { PrismaPg } from '@prisma/adapter-pg'
const adapter = new PrismaPg({ connectionString: `${process.env.DATABASE_URL}` })
const prisma = new PrismaClient({
adapter,
comments: [myPlugin],
})
Plugins receive a SqlCommenterContext object with information about the query being executed.
See API Reference for more details.
Plugins return a SqlCommenterTags object where keys can have undefined values. Keys with undefined values are automatically filtered out from the final comment:
import type { SqlCommenterPlugin } from '@prisma/sqlcommenter'
const conditionalPlugin: SqlCommenterPlugin = (context) => ({
model: context.query.modelName, // undefined for raw queries, automatically omitted
action: context.query.action,
// Include SQL length only when available (not available with Accelerate)
sqlLength: context.sql ? String(context.sql.length) : undefined,
})
import type { SqlCommenterPlugin } from '@prisma/sqlcommenter'
const applicationTags: SqlCommenterPlugin = (context) => ({
application: 'my-service',
environment: process.env.NODE_ENV ?? 'development',
operation: context.query.action,
model: context.query.modelName, // automatically omitted if undefined
})
import { AsyncLocalStorage } from 'node:async_hooks'
import type { SqlCommenterPlugin } from '@prisma/sqlcommenter'
const routeStorage = new AsyncLocalStorage<{ route: string }>()
const routeContext: SqlCommenterPlugin = () => ({
route: routeStorage.getStore()?.route,
})
The plugin outputs are merged, sorted by key, URL-encoded, and formatted according to the sqlcommenter specification:
SELECT "id", "name" FROM "User" /*application='my-app',environment='production',model='User'*/
SqlCommenterTagstype SqlCommenterTags = { readonly [key: string]: string | undefined }
Key-value pairs to add as SQL comments. Keys with undefined values are automatically filtered out and will not appear in the final comment.
SqlCommenterPlugininterface SqlCommenterPlugin {
(context: SqlCommenterContext): SqlCommenterTags
}
A function that receives query context and returns key-value pairs. Return an empty object to add no comments for a particular query. Keys with undefined values are automatically omitted.
SqlCommenterContextinterface SqlCommenterContext {
query: SqlCommenterQueryInfo
}
Context provided to plugins containing information about the query.
SqlCommenterQueryInfotype SqlCommenterQueryInfo =
| ({ type: 'single' } & SqlCommenterSingleQueryInfo)
| ({ type: 'compacted' } & SqlCommenterCompactedQueryInfo)
Information about the query or queries being executed.
type: 'single': A single Prisma query is being executedtype: 'compacted': Multiple queries have been batched into a single SQL statement (e.g., automatic findUnique batching)SqlCommenterSingleQueryInfointerface SqlCommenterSingleQueryInfo {
modelName?: string
action: SqlCommenterQueryAction
query: unknown
}
Information about a single Prisma query.
modelName: The model being queried (e.g., "User", "Post"). Undefined for raw queries.action: The Prisma operation (e.g., "findMany", "createOne", "queryRaw")query: The full query object with selection and arguments. Specifics of the query representation are not part of the public API yet.SqlCommenterCompactedQueryInfointerface SqlCommenterCompactedQueryInfo {
modelName?: string
action: SqlCommenterQueryAction
queries: unknown[]
}
Information about a compacted batch query.
modelName: The model being queried (e.g., "User", "Post").action: The Prisma operation (e.g., "findUnique")queries: The full query objects with selections and arguments. Specifics of the query representation are not part of the public API yet.undefined values are filtered out (they do not remove keys set by earlier plugins)\'Apache-2.0
FAQs
SQL commenter types for Prisma
The npm package @prisma/sqlcommenter receives a total of 7,705 weekly downloads. As such, @prisma/sqlcommenter popularity was classified as popular.
We found that @prisma/sqlcommenter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.

Research
/Security News
Socket uncovered 26 malicious npm packages tied to North Korea's Contagious Interview campaign, retrieving a live 9-module infostealer and RAT from the adversary's C2.

Research
An impersonated golang.org/x/crypto clone exfiltrates passwords, executes a remote shell stager, and delivers a Rekoobe backdoor on Linux.