P
💻DeveloppementIntermediateAll AIs

Optimize Your Prisma and Drizzle ORM Queries Like a Pro

A prompt to analyze your Prisma or Drizzle ORM queries and get concrete optimizations: N+1 elimination, targeted selection, indexes and verified SQL queries.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un expert en bases de données et en ORM JavaScript/TypeScript, spécialisé dans Prisma et Drizzle ORM. Analyse et optimise les requêtes suivantes pour améliorer les performances de mon application.

Contexte du projet :

  • ORM utilisé : [PRISMA | DRIZZLE]
  • Base de données : [POSTGRESQL | MYSQL | SQLITE]
  • Description du modèle de données : [DÉCRIRE LES TABLES/MODÈLES PRINCIPAUX ET LEURS RELATIONS]
  • Requêtes à optimiser :
[COLLER VOS REQUÊTES ORM ICI]
  • Problème observé : [LENTEUR | REQUÊTES N+1 | CONSOMMATION MÉMOIRE | TIMEOUT]

Pour chaque requête, fournis :

  1. Diagnostic : Identifie les problèmes de performance (requêtes N+1, select *, jointures manquantes, absence d'index, chargement eager vs lazy inadapté).

  2. Requête optimisée : Réécris la requête avec les bonnes pratiques :

    • Sélection des champs nécessaires uniquement (select/columns)
    • Utilisation correcte des includes/relations/with
    • Pagination côté base de données
    • Agrégations côté SQL plutôt que JavaScript
    • Transactions quand nécessaire
  3. Index recommandés : Propose les index à créer dans le schéma (migration) pour supporter ces requêtes.

  4. Requête SQL générée : Montre la requête SQL brute équivalente pour vérifier ce que l'ORM produit réellement.

  5. Métriques attendues : Estime le gain de performance (nombre de requêtes SQL réduites, volume de données transférées).

Présente chaque optimisation dans un bloc de code TypeScript commenté, avec un avant/après clair.

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

<p>This prompt transforms AI into a specialized database performance consultant via ORM. By providing your actual queries and schema context, you get a precise diagnosis of common anti-patterns like N+1 queries, unnecessary <strong>select *</strong> or misconfigured joins.</p><p>The before/after approach is essential: it shows you not only the optimized query but also the <strong>underlying SQL query</strong> generated by the ORM. This helps you understand what is actually happening on the database side and verify that the ORM produces what you expect.</p><p>For better results, include your <strong>Prisma schema or Drizzle table definitions</strong> in the data model variable. The more precise the context (relationship cardinality, data volume, read/write use cases), the more relevant the index and restructuring recommendations will be.</p>

Use Cases

Eliminate N+1 queries in a REST or GraphQL APIOptimize listing pages with pagination and complex filtersReduce dashboard response times with heavy aggregations

Expected Output

A structured report for each query with problem diagnosis, optimized ORM query in TypeScript, SQL indexes to create, equivalent raw SQL query and estimated performance gains.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Pour un diagnostic fiable, ajoutez les logs SQL réels (Prisma : `log: ['query']`, Drizzle : `logger`) et le plan d’exécution `EXPLAIN ANALYZE` des requêtes lentes. Indiquez aussi l’ordre de grandeur du volume de données : sans ces infos, les optimisations restent génériques. Pensez à demander une pagination par curseur (keyset) plutôt qu’`offset` dès que vous dépassez quelques milliers de lignes.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Generate a code coverage report plan

Plan test coverage improvements

0226
💻DeveloppementAdvancedAll AIs

Security Code Review

Audit code for common security vulnerabilities

0216
💻DeveloppementIntermediateAll AIs

Complete GitHub Actions Pipeline

Create a complete CI/CD pipeline

0170
💻DeveloppementIntermediateAll AIs

Mistral Prompt for Creating a Prototype

Mistral, the leading French AI model, stands out as a powerful tool for accelerating prototype creation. Whether you're developing a web application, an API, or a digital product, Mistral can generate functional code, structure your architecture, and produce a testable prototype in minutes. Unlike a traditional approach where prototyping requires several days of development, using Mistral allows you to quickly validate an idea by obtaining a complete functional skeleton. The model particularly excels at generating structured code, proposing coherent architectures, and creating basic but functional user interfaces. By crafting a precise prompt that describes your product vision, key features, and technical constraints, you get a prototype that serves as a solid foundation for iteration. This approach is especially popular with startups, product managers, and independent developers looking to test a market hypothesis without investing weeks of development. Here's how to leverage Mistral to turn your idea into a concrete prototype.

0153