prisma-client-api-raw-queries

par prisma

Requêtes brutes. Référence lors de l'utilisation de cette fonctionnalité Prisma.

npx skills add https://github.com/prisma/cursor-plugin --skill prisma-client-api-raw-queries

Raw Queries

Execute raw SQL when Prisma's query API isn't sufficient.

$queryRaw

Execute SELECT queries and get typed results:

const users = await prisma.$queryRaw`
  SELECT * FROM "User" WHERE email LIKE ${'%@prisma.io'}
`

With type

type User = { id: number; email: string; name: string | null }

const users = await prisma.$queryRaw<User[]>`
  SELECT id, email, name FROM "User" WHERE role = ${'ADMIN'}
`

Dynamic table/column names

Use Prisma.raw() for identifiers (not safe for user input):

import { Prisma } from '../generated/client'

const column = 'email'
const users = await prisma.$queryRaw`
  SELECT ${Prisma.raw(column)} FROM "User"
`

With Prisma.sql

Build queries dynamically:

import { Prisma } from '../generated/client'

const email = 'alice@prisma.io'
const query = Prisma.sql`SELECT * FROM "User" WHERE email = ${email}`
const users = await prisma.$queryRaw(query)

Join multiple SQL fragments

import { Prisma } from '../generated/client'

const conditions = [
  Prisma.sql`role = ${'ADMIN'}`,
  Prisma.sql`verified = ${true}`
]

const users = await prisma.$queryRaw`
  SELECT * FROM "User" 
  WHERE ${Prisma.join(conditions, ' AND ')}
`

$executeRaw

Execute INSERT, UPDATE, DELETE (returns affected count):

const count = await prisma.$executeRaw`
  UPDATE "User" SET verified = true WHERE email LIKE ${'%@prisma.io'}
`
console.log(`Updated ${count} users`)

Delete example

const deleted = await prisma.$executeRaw`
  DELETE FROM "User" WHERE "deletedAt" < ${thirtyDaysAgo}
`

Insert example

const inserted = await prisma.$executeRaw`
  INSERT INTO "Log" (message, level, timestamp)
  VALUES (${message}, ${level}, ${new Date()})
`

$queryRawUnsafe / $executeRawUnsafe

For fully dynamic queries (use with caution!):

// ⚠️ SQL injection risk - only use with trusted input
const table = 'User'
const users = await prisma.$queryRawUnsafe(
  `SELECT * FROM "${table}" WHERE id = $1`,
  userId
)

Parameterized unsafe query

const result = await prisma.$executeRawUnsafe(
  'UPDATE "User" SET name = $1 WHERE id = $2',
  'Alice',
  1
)

SQL Injection Prevention

Safe (parameterized)

// ✅ User input is parameterized
const email = userInput
const users = await prisma.$queryRaw`
  SELECT * FROM "User" WHERE email = ${email}
`

Unsafe (concatenation)

// ❌ SQL injection vulnerability!
const email = userInput
const users = await prisma.$queryRawUnsafe(
  `SELECT * FROM "User" WHERE email = '${email}'`
)

Database-Specific Features

PostgreSQL

// Array operations
const users = await prisma.$queryRaw`
  SELECT * FROM "User" WHERE 'admin' = ANY(roles)
`

// JSON operations
const users = await prisma.$queryRaw`
  SELECT * FROM "User" WHERE metadata->>'theme' = 'dark'
`

MySQL

// Full-text search
const posts = await prisma.$queryRaw`
  SELECT * FROM Post WHERE MATCH(title, content) AGAINST(${searchTerm})
`

Transactions with Raw Queries

await prisma.$transaction(async (tx) => {
  await tx.$executeRaw`UPDATE "Account" SET balance = balance - ${amount} WHERE id = ${senderId}`
  await tx.$executeRaw`UPDATE "Account" SET balance = balance + ${amount} WHERE id = ${recipientId}`
})

Handling Results

BigInt handling

PostgreSQL returns BigInt for COUNT:

const result = await prisma.$queryRaw<[{ count: bigint }]>`
  SELECT COUNT(*) as count FROM "User"
`
const count = Number(result[0].count)

Date handling

type Result = { createdAt: Date }
const users = await prisma.$queryRaw<Result[]>`
  SELECT "createdAt" FROM "User"
`
// createdAt is already a Date object

Plus de skills de prisma

prisma-cli-migrate-reset
prisma
prisma migrate reset
official
prisma-cli-validate
prisma
Validation Prisma. Référence lors de l'utilisation de cette fonctionnalité Prisma.
official
prisma-next-extension-upgrade
prisma
Upgrade Prisma Next in your extension. Bumps every `@prisma-next/*` dependency to the requested target (or npm `latest`), runs the per-transition upgrade…
official
adr-review
prisma
Examiner un ou plusieurs ADR avec un regard neuf (en tant que membre de l’équipe sans contexte préalable), identifier les problèmes narratifs et structurels, puis les réécrire. À utiliser lorsque le…
official
prisma-next-upgrade
prisma
Upgrade Prisma Next in your app. Bumps every `@prisma-next/*` dependency from the version pinned in the lockfile to the requested target (or npm `latest`),…
official
prisma-cli
prisma
We need to translate the given text from English to French, preserving the name "prisma-cli" and other technical terms. The text is a description of a directory item for an agent skill. We must not add any extra commentary, labels, or formatting. Just the translation. The text: "Complete reference for Prisma CLI commands, options, and workflows across setup, migrations, and database operations. Covers 20+ commands organized by priority: setup ( init ), generation ( generate ), development ( dev ), database operations ( db pull/push/seed/execute ), and migrations ( migrate dev/deploy/reset/status/diff/resolve ) Includes Prisma 7.x changes: new prisma.config.ts configuration file, removed flags ( --skip-generate , --skip-seed , --schema , --url ), and explicit..." We need to translate into French. Keep technical terms like "Prisma CLI", "init", "generate", "dev", "db pull/push/seed/execute", "migrate dev/deploy/reset/status/diff/resolve
official
prisma-client-api
prisma
Référence complète de l'API Prisma Client pour les requêtes de modèle, les opérations CRUD, le filtrage, les relations et les transactions. Couvre 17 méthodes de requête de modèle, dont findUnique, findMany, create, update, delete, upsert et les opérations en masse avec variantes de retour. Fournit des options de requête pour façonner les résultats : select, include, omit, orderBy, take, skip, cursor et distinct. Inclut les opérateurs de filtre scalaires et logiques (equals, in, contains, startsWith, lt, gt) ainsi que les filtres de relation (some,...
official
prisma-compute
prisma
Prisma Compute deployment and hosting guide. Use whenever the user mentions Prisma Compute, `prisma.compute.ts`, `defineComputeConfig`, deploying or hosting a Prisma app, `@prisma/cli app deploy`, `compute:deploy`, `create-prisma --deploy`, `PRISMA_SERVICE_TOKEN`, `auth workspace`, Compute apps/deployments/build logs/domains, `@prisma/cli agent install`, localhost vs `0.0.0.0`, deploy port binding, or framework deploy readiness for Hono, Elysia, Next.js, TanStack Start, Astro, Nuxt, Svelte,...
developmentdevopsofficial