Prisma 6 New Features - TypeSafe ORM Gets Even Better

2025.12.12

Prisma 6 Overview

Prisma 6 brings full type safety to raw SQL queries through the introduction of Typed SQL. It also includes query performance improvements and new client features.

Typed SQL

Provides complete type safety for raw SQL queries.

// sql/getUserWithPosts.sql
-- @param {Int} $1:userId
SELECT
  u.id,
  u.name,
  u.email,
  json_agg(p.*) as posts
FROM users u
LEFT JOIN posts p ON p.author_id = u.id
WHERE u.id = $1
GROUP BY u.id;
// Generated type-safe function
import { getUserWithPosts } from '@prisma/client/sql';

const result = await prisma.$queryRawTyped(
  getUserWithPosts(123)
);

// result is fully typed
console.log(result.name);  // string
console.log(result.posts); // Post[]

Performance Improvements

Query Engine Optimization

Prisma 5 vs Prisma 6 Benchmark:
- Simple findMany: 15% faster
- Queries with relations: 25% faster
- Bulk data retrieval: 30% faster

Batch Processing Improvements

// Automatic batching
const users = await Promise.all([
  prisma.user.findUnique({ where: { id: 1 } }),
  prisma.user.findUnique({ where: { id: 2 } }),
  prisma.user.findUnique({ where: { id: 3 } }),
]);
// Internally batched into a single query

New Client Features

omit for Field Exclusion

// Exclude password field
const user = await prisma.user.findUnique({
  where: { id: 1 },
  omit: {
    password: true
  }
});
// user.password does not exist

relationLoadStrategy

// Explicit relation loading strategy
const user = await prisma.user.findUnique({
  where: { id: 1 },
  include: {
    posts: true
  },
  relationLoadStrategy: 'join' // or 'query'
});

Enhanced Prisma Client Extensions

const prisma = new PrismaClient().$extends({
  model: {
    user: {
      // Custom method
      async signUp(email: string, password: string) {
        const hashedPassword = await hash(password);
        return prisma.user.create({
          data: { email, password: hashedPassword }
        });
      }
    }
  },
  query: {
    $allModels: {
      // Hook applied to all models
      async $allOperations({ model, operation, args, query }) {
        const start = Date.now();
        const result = await query(args);
        console.log(`${model}.${operation}: ${Date.now() - start}ms`);
        return result;
      }
    }
  }
});

// Usage
await prisma.user.signUp('user@example.com', 'password123');

Migration Improvements

Diff Migrations

# Check diff before migrating
prisma migrate diff \
  --from-schema-datamodel prisma/schema.prisma \
  --to-schema-datasource prisma/schema.prisma

# Execute migration
prisma migrate dev --name add_user_profile

Migration Rollback

# Rollback last migration
prisma migrate rollback

Prisma Accelerate

Edge connection pooling and caching.

import { PrismaClient } from '@prisma/client/edge';
import { withAccelerate } from '@prisma/extension-accelerate';

const prisma = new PrismaClient().$extends(withAccelerate());

// Query with caching
const users = await prisma.user.findMany({
  cacheStrategy: {
    ttl: 60,
    swr: 120
  }
});

Migration Guide

# Upgrade to Prisma 6
npm install prisma@latest @prisma/client@latest

# Regenerate client
npx prisma generate

Breaking Changes

ChangeAction
Node.js 18+ requiredUpgrade Node.js
Some default value changesConfigure explicitly

Summary

Prisma 6 has evolved into an even more powerful ORM with Typed SQL for type-safe raw SQL, performance improvements, and new client features. Typed SQL is particularly useful when you need to write complex queries.

← Back to list