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

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

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

💻DeveloppementAdvancedAll AIs

Design a Versioned API

Evolving a public API without breaking integrations

0339
💻DeveloppementIntermediateGemini

Create a CLI Tool with Node.js

Create a professional Node.js CLI tool with Commander.js, Inquirer, visual feedback, and npm publishing.

23732
💻DeveloppementIntermediateAll AIs

Sora Prompt for Generating JavaScript Code

Sora, developed by OpenAI, is a versatile artificial intelligence model that can be used to assist in various creative and technical tasks, including JavaScript code generation. Although Sora is primarily known for its video generation capabilities, its integration into the OpenAI ecosystem allows you to leverage its text features to produce functional code snippets. By crafting precise and structured prompts, you can obtain clean, commented, and ready-to-use JavaScript code for your web projects. Whether you need utility functions, interactive components, or complete scripts, the key lies in the quality of your prompt. A well-constructed prompt should specify the usage context, technical constraints, desired code style, and edge cases to handle. In this guide, we offer optimized prompts to get the most out of Sora for JavaScript code generation, with variants suitable for all expertise levels. Discover how to structure your requests to obtain reliable, maintainable code that meets modern web development standards.

0314
💻DeveloppementIntermediateAll AIs

Perplexity Prompt for Generating SQL Queries

Perplexity stands out from traditional search engines by its ability to synthesize technical information from multiple reliable sources. For generating SQL queries, this tool becomes a true development assistant: it can analyze your database schema, understand your business intent, and produce optimized queries based on the official documentation of PostgreSQL, MySQL, or SQL Server. Unlike a simple code generator, Perplexity contextualizes its responses by citing best practices from Stack Overflow, official documentation, and reputable technical blogs. Whether you need a complex join, an aggregation query with windowing, or performance optimization via indexes, Perplexity provides not only the query but also an explanation of each clause. This educational approach makes it a particularly suitable tool for developers who want to improve their SQL skills while delivering production-ready code. The major advantage lies in its ability to consider the specifics of your DBMS and propose alternatives based on available versions.

0511