Skip to main content

# Writing Queries & Migrations with AI Assistance

Complex Queries Made Simple

Instead of reading Prisma docs for 20 minutes, describe what you want:

Prompt: "Write a Prisma query to get all projects for an organization, including the count of tasks in each status, the most recent task, and the assigned users."

// AI-generated query
const projects = await prisma.project.findMany({
  where: { organizationId: orgId },
  include: {
    tasks: {
      select: {
        status: true,
      },
    },
    _count: {
      select: { tasks: true },
    },
  },
  orderBy: { updatedAt: 'desc' },
});

Unlock this lesson

Upgrade to Pro to access the full content

What you'll learn:

  • Write complex Prisma queries with nested includes, filters, and aggregations using AI
  • Generate and customize database migrations safely
  • Debug slow queries by analyzing query plans with AI assistance