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 FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 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 Database Access Patterns

Prisma Database Access Patterns

Comprehensive Prisma ORM patterns for Google Antigravity projects with type-safe database queries and relations.

prismaormdatabasetypescriptpostgresql
by antigravity-team
⭐0Stars
.antigravity
# Prisma Database Access Patterns for Google Antigravity

Prisma ORM provides the best developer experience for database access in modern TypeScript applications. When combined with Google Antigravity's intelligent code generation powered by Gemini 3, you can build robust, type-safe database layers with minimal effort.

## Prisma Schema Design

Start with a well-structured schema that leverages Prisma's powerful modeling capabilities:

```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?
  role      Role     @default(USER)
  posts     Post[]
  profile   Profile?
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

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

model Profile {
  id     String  @id @default(cuid())
  bio    String?
  avatar String?
  userId String  @unique
  user   User    @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@map("profiles")
}

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

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

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

  @@map("categories")
}

enum Role {
  USER
  ADMIN
  MODERATOR
}
```

## Prisma Client Singleton

Create a singleton instance to prevent connection exhaustion in serverless environments:

```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;
```

## Type-Safe Query Patterns

Implement repository patterns with full type safety:

```typescript
// lib/repositories/user-repository.ts
import prisma from "@/lib/prisma";
import { Prisma, User } from "@prisma/client";

export type UserWithProfile = Prisma.UserGetPayload<{
  include: { profile: true };
}>;

export type UserWithPosts = Prisma.UserGetPayload<{
  include: { posts: true };
}>;

export const userRepository = {
  async findById(id: string): Promise<User | null> {
    return prisma.user.findUnique({
      where: { id },
    });
  },

  async findByIdWithProfile(id: string): Promise<UserWithProfile | null> {
    return prisma.user.findUnique({
      where: { id },
      include: { profile: true },
    });
  },

  async findByEmail(email: string): Promise<User | null> {
    return prisma.user.findUnique({
      where: { email },
    });
  },

  async create(data: Prisma.UserCreateInput): Promise<User> {
    return prisma.user.create({ data });
  },

  async update(id: string, data: Prisma.UserUpdateInput): Promise<User> {
    return prisma.user.update({
      where: { id },
      data,
    });
  },

  async delete(id: string): Promise<User> {
    return prisma.user.delete({
      where: { id },
    });
  },

  async findMany(params: {
    skip?: number;
    take?: number;
    where?: Prisma.UserWhereInput;
    orderBy?: Prisma.UserOrderByWithRelationInput;
  }): Promise<User[]> {
    const { skip, take, where, orderBy } = params;
    return prisma.user.findMany({
      skip,
      take,
      where,
      orderBy,
    });
  },
};
```

## Transaction Patterns

Handle complex operations with transactions:

```typescript
// lib/services/user-service.ts
import prisma from "@/lib/prisma";
import { User, Profile } from "@prisma/client";

export async function createUserWithProfile(
  userData: { email: string; name: string },
  profileData: { bio?: string; avatar?: string }
): Promise<User & { profile: Profile }> {
  return prisma.$transaction(async (tx) => {
    const user = await tx.user.create({
      data: {
        email: userData.email,
        name: userData.name,
        profile: {
          create: profileData,
        },
      },
      include: { profile: true },
    });

    await tx.post.create({
      data: {
        title: "Welcome Post",
        content: "Welcome to the platform!",
        authorId: user.id,
        published: true,
      },
    });

    return user as User & { profile: Profile };
  });
}

export async function transferPosts(
  fromUserId: string,
  toUserId: string
): Promise<void> {
  await prisma.$transaction([
    prisma.post.updateMany({
      where: { authorId: fromUserId },
      data: { authorId: toUserId },
    }),
    prisma.user.delete({
      where: { id: fromUserId },
    }),
  ]);
}
```

## Pagination with Cursor

Implement efficient cursor-based pagination:

```typescript
// lib/utils/pagination.ts
import prisma from "@/lib/prisma";
import { Post } from "@prisma/client";

interface PaginatedResult<T> {
  items: T[];
  nextCursor: string | null;
  hasMore: boolean;
}

export async function getPaginatedPosts(
  cursor?: string,
  limit: number = 10
): Promise<PaginatedResult<Post>> {
  const posts = await prisma.post.findMany({
    take: limit + 1,
    cursor: cursor ? { id: cursor } : undefined,
    where: { published: true },
    orderBy: { createdAt: "desc" },
    skip: cursor ? 1 : 0,
  });

  const hasMore = posts.length > limit;
  const items = hasMore ? posts.slice(0, -1) : posts;
  const nextCursor = hasMore ? items[items.length - 1]?.id : null;

  return { items, nextCursor, hasMore };
}
```

## Best Practices

1. **Use select for partial queries** - Only fetch fields you need
2. **Index frequently queried fields** - Add @@index annotations
3. **Handle soft deletes** - Use deletedAt instead of hard deletes
4. **Use transactions for related operations** - Ensure data consistency
5. **Implement connection pooling** - Use PgBouncer for serverless

Prisma with Google Antigravity enables rapid, type-safe database development with intelligent autocompletion and error prevention.

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...