Skip to content

williamwa/prisma-ai-console

 
 

Repository files navigation

prisma-ai-console

AI-powered REPL console for Prisma ORM with natural language query generation

Screenshot

Screenshot Screenshot

Usage

  • From your project directory, run:
npx prisma-ai-console
  • Optional flags:
    • --client or -c: Set Prisma client path (default: ./node_modules/@prisma/client)
    • --schema or -s: Set schema file location for AI features (default: ./prisma/schema.prisma)
npx prisma-ai-console -c ./node_modules/@prisma/client -s ./prisma/schema.prisma

AI-Powered Query Generation 🤖

Generate Prisma queries using natural language! The console now includes an ai() function that understands your database schema and generates the appropriate Prisma commands.

Setup

Set your API key as an environment variable:

# For OpenAI
export OPENAI_API_KEY=your-api-key-here

# Or for Anthropic Claude
export ANTHROPIC_API_KEY=your-api-key-here

# Or for OpenRouter (supports multiple models)
export OPENROUTER_API_KEY=your-api-key-here
export OPENROUTER_MODEL=anthropic/claude-3.5-sonnet  # Optional, defaults to claude-3.5-sonnet

If multiple keys exist, OpenRouter will be used first, then OpenAI, then Anthropic.

Examples

// 1. ai(query) - Generate a Prisma command
await ai('find all users with gmail addresses')
// Displays the command, copy and paste to execute

// 2. run(query) - Generate and execute in one step
await run('get the top 10 most played songs with their artist names')
// Generates the command and runs it immediately, returns the result

Example

 > await ai('find all users created in the last 7 days')
🤖 Generating Prisma command...

 Generated command:
await prisma.user.findMany({ where: { createdAt: { gte: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) } } })

💡 Copy and paste to execute, or assign to a variable

Features

Two powerful commands:

  • ai(query) - Generate Prisma commands from natural language
  • run(query) - Generate and execute in one step

The AI automatically:

  • Reads your Prisma schema
  • Understands your database structure
  • Generates accurate Prisma Client queries
  • Supports complex queries with relations, filters, and aggregations

Acknowledgments

This project is built on top of prisma-console by Kinjal Raykarmakar. All the original REPL console features are still available, with AI-powered query generation added on top.

Original console feature included:

Screenshot Screenshot 2

About

AI-powered REPL console for Prisma ORM with natural language query generation

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%