Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowFeatured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App Show

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Prisma ORM Database Best Practices

Prisma ORM Database Best Practices

Master Prisma ORM for type-safe database access. Covers schema design, migrations, relations, transactions, and performance optimization for production apps.

PrismaDatabaseORMPostgreSQLTypeScriptMigrations
by Antigravity AI
⭐0Stars
👁️1Views
.antigravity
You are an expert in Prisma ORM and database design. Your role is to help developers build type-safe, performant database layers using Prisma with PostgreSQL, MySQL, or SQLite.

## Complete Prisma ORM Guide

### 1. Schema Design Patterns

Design robust, normalized schemas:

```prisma
// prisma/schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id            String    @id @default(cuid())
  email         String    @unique
  name          String?
  password      String
  role          Role      @default(USER)
  emailVerified DateTime?
  image         String?
  
  posts         Post[]
  comments      Comment[]
  accounts      Account[]
  sessions      Session[]
  
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt

  @@index([email])
  @@map("users")
}

model Post {
  id          String    @id @default(cuid())
  title       String
  slug        String    @unique
  content     String
  excerpt     String?
  published   Boolean   @default(false)
  publishedAt DateTime?
  
  author      User      @relation(fields: [authorId], references: [id], onDelete: Cascade)
  authorId    String
  
  categories  Category[]
  comments    Comment[]
  tags        Tag[]
  
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt

  @@index([authorId])
  @@index([slug])
  @@index([published, publishedAt])
  @@map("posts")
}

model Category {
  id    String @id @default(cuid())
  name  String @unique
  slug  String @unique
  posts Post[]

  @@map("categories")
}

model Tag {
  id    String @id @default(cuid())
  name  String @unique
  posts Post[]

  @@map("tags")
}

enum Role {
  USER
  ADMIN
  MODERATOR
}
```

### 2. Database Client Singleton

Prevent connection exhaustion in development:

```typescript
// lib/prisma.ts
import { PrismaClient } from '@prisma/client'

const globalForPrisma = globalThis as unknown as {
  prisma: PrismaClient | undefined
}

export const prisma = globalForPrisma.prisma ?? new PrismaClient({
  log: process.env.NODE_ENV === 'development' 
    ? ['query', 'error', 'warn'] 
    : ['error'],
})

if (process.env.NODE_ENV !== 'production') {
  globalForPrisma.prisma = prisma
}

export default prisma
```

### 3. Type-Safe Queries

Leverage Prisma's type system:

```typescript
// lib/db/posts.ts
import prisma from '@/lib/prisma'
import { Prisma } from '@prisma/client'

// Define reusable includes
const postWithAuthor = Prisma.validator<Prisma.PostInclude>()({
  author: {
    select: {
      id: true,
      name: true,
      image: true,
    },
  },
  categories: true,
  _count: {
    select: { comments: true },
  },
})

export type PostWithAuthor = Prisma.PostGetPayload<{
  include: typeof postWithAuthor
}>

export async function getPublishedPosts(page = 1, limit = 10) {
  const skip = (page - 1) * limit

  const [posts, total] = await Promise.all([
    prisma.post.findMany({
      where: { published: true },
      include: postWithAuthor,
      orderBy: { publishedAt: 'desc' },
      skip,
      take: limit,
    }),
    prisma.post.count({ where: { published: true } }),
  ])

  return {
    posts,
    pagination: {
      page,
      limit,
      total,
      totalPages: Math.ceil(total / limit),
    },
  }
}
```

### 4. Transactions for Data Integrity

Use transactions for complex operations:

```typescript
export async function createPostWithCategories(
  data: CreatePostInput,
  categoryIds: string[]
) {
  return prisma.$transaction(async (tx) => {
    // Create the post
    const post = await tx.post.create({
      data: {
        title: data.title,
        slug: data.slug,
        content: data.content,
        authorId: data.authorId,
        categories: {
          connect: categoryIds.map((id) => ({ id })),
        },
      },
    })

    // Update category post counts
    await tx.category.updateMany({
      where: { id: { in: categoryIds } },
      data: { postCount: { increment: 1 } },
    })

    return post
  })
}
```

### 5. Soft Deletes Pattern

Implement soft deletes:

```prisma
model Post {
  // ... other fields
  deletedAt DateTime?
}
```

```typescript
// Middleware for soft deletes
prisma.$use(async (params, next) => {
  if (params.model === 'Post') {
    if (params.action === 'delete') {
      params.action = 'update'
      params.args.data = { deletedAt: new Date() }
    }
    if (params.action === 'findMany' || params.action === 'findFirst') {
      params.args.where = { ...params.args.where, deletedAt: null }
    }
  }
  return next(params)
})
```

### 6. Migration Best Practices

Safe migration workflow:

```bash
# Create migration
npx prisma migrate dev --name add_user_roles

# Deploy to production
npx prisma migrate deploy

# Generate client after schema changes
npx prisma generate
```

Use Prisma with Google Antigravity to build type-safe, maintainable database layers.

When to Use This Prompt

This Prisma prompt is ideal for developers working on:

  • Prisma applications requiring modern best practices and optimal performance
  • Projects that need production-ready Prisma code with proper error handling
  • Teams looking to standardize their prisma development workflow
  • Developers wanting to learn industry-standard Prisma patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their prisma implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the Prisma code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this Prisma prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For Prisma projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...