Skip to content

Releases: prisma/prisma

5.8.0

09 Jan 17:27
688a50a
Compare
Choose a tag to compare

🌟 Help us spread the word about Prisma by starring the repo or posting on X about the release. 🌟

Highlights

Happy New Year from your friends at Prisma! 🎊

In the last 4 weeks, we resolved some bugs on the ORM and made some progress on some exciting features that we’re not yet ready to announce. Stay tuned for the upcoming releases, in which we’ll be announcing new features. 😉

relationJoins improvements: Relation loading strategy per query (Preview)

In version 5.7.0, we released relationJoins into Preview. The relationJoins feature enables support for JOINs for relation queries.

This release adds support for the ability to specify the strategy used to fetch relational data per query when the Preview feature is enabled. This will enable you to choose the most efficient strategy for fetching relation data depending on your use case.

You can now load relation data using either of the following strategies:

  • join — uses JOINs to fetch relation data
  • query — uses separate queries to fetch relation data

When the relationJoins Preview feature is enabled, by default, the relation fetching strategy used is join. You can override the default behavior by using the relationLoadStrategy query option.

To get started, enable the Preview feature:

// schema.prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["relationJoins"]
}

… and specify the relation loading strategy for your query as follows:

await prisma.user.findMany({
  relationLoadStrategy: 'query',
  include: {
    posts: true,
  },
})

Try it out and share your feedback and create a bug report if you encounter any issues.

Survey: Edge functions support

We’re working on bringing Edge function support to Prisma ORM and we would appreciate your input by submitting a response to our survey. By filling out the survey, you will be considered for our Early Access cohort as soon as we have something for you to try out.

Fixes and improvements

Prisma Client

Prisma Migrate

Language tools (e.g. VS Code)

Credits

Huge thanks to @anuraaga, @onichandame, @LucianBuzzo, @RobertCraigie, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @tinola, @AikoRamalho, @luxaritas for helping!

Company news

🎉 A billion queries and counting: Prisma Accelerate

Prisma Accelerate, our global database cache has served over 1 billion queries since its General Availability launch.

We’d like to give a shoutout to our team and everyone who’s been with us on this journey. Stay tuned for some exciting products and features in the pipeline for 2024!

🔮 Prisma ORM Ecosystem

Are you building a cool tool, extension, generator, CLI tool or anything else, for Prisma ORM? Let us know.

We would like to learn about it and feature it on our Ecosystem page.

💼 We’re hiring

If you're interested in joining our growing team to help empower developers to build data-intensive applications, Prisma is the place for you. Check out our Careers page for open positions.

5.7.1

18 Dec 20:02
57c979f
Compare
Choose a tag to compare

5.7.0

06 Dec 16:22
990e591
Compare
Choose a tag to compare

🌟 Help us spread the word about Prisma by starring the repo or posting on X (formerly Twitter) about the release.

Highlights

✨ In this release, we improved the SQL queries Prisma Client generates for you with two new Preview features, the driver adapters, and support for the database drivers we currently support. 5.7.0 will be the last release of the year. Stay tuned for the next one in January! ✨

Preview support for JOINs for relation queries for PostgreSQL and CockroachDB

We’re excited to announce Preview support for JOINs in Prisma Client when querying relations. Support for JOINs has been a long-standing feature request, and this release adds support for PostgreSQL and CockroachDB. The upcoming releases will expand support for other databases Prisma supports.

To get started using JOINs, enable the Preview feature in your Prisma schema:

// schema.prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["relationJoins"]
}

Run prisma generate to regenerate Prisma Client and enable the Preview feature.

Prisma Client will use a JOIN in your query to fetch relation data for a majority of the cases.

Example queries

1-1 relation queries example

Prisma Client query

await prisma.user.findUnique({
	where: {
		id: 1
	},
	include: {
		profile: true
	}
})

SQL

SELECT
	"t1"."id",
	"t1"."name",
	"User_profile"."__prisma_data__" AS "profile"
FROM
	"public"."User" AS "t1"
	LEFT JOIN LATERAL (
		SELECT
			COALESCE(JSON_AGG("__prisma_data__"), '[]') AS "__prisma_data__"
		FROM
			(
				SELECT
					"t4"."__prisma_data__"
				FROM
					(
						SELECT
							JSON_BUILD_OBJECT(
								'id',
								"t3"."id",
								'bio',
								"t3"."bio",
								'userId',
								"t3"."userId"
							) AS "__prisma_data__"
						FROM
							(
								SELECT
									"t2".*
								FROM
									"public"."Profile" AS "t2"
								WHERE
									"t1"."id" = "t2"."userId"
							) AS "t3"
					) AS "t4"
			) AS "t5"
	) AS "User_profile" ON TRUE
WHERE "t1"."id" = $1
LIMIT $2
1-m relation queries example

Prisma Client query

await prisma.user.findUnique({
	where: {
		id: 1
	},
	include: {
		posts: true
	}
})

SQL

SELECT
	"t1"."id",
	"t1"."name",
	"User_posts"."__prisma_data__" AS "posts"
FROM
	"public"."User" AS "t1"
	LEFT JOIN LATERAL (
		SELECT
			COALESCE(JSON_AGG("__prisma_data__"), '[]') AS "__prisma_data__"
		FROM
			(
				SELECT
					"t4"."__prisma_data__"
				FROM
					(
						SELECT
							JSON_BUILD_OBJECT(
								'id',
								"t3"."id",
								'title',
								"t3"."title",
								'content',
								"t3"."content",
								'published',
								"t3"."published",
								'authorId',
								"t3"."authorId"
							) AS "__prisma_data__"
						FROM
							(
								SELECT
									"t2".*
								FROM
									"public"."Post" AS "t2"
								WHERE
									"t1"."id" = "t2"."authorId"
									/* root select */
							) AS "t3"
							/* inner select */
					) AS "t4"
					/* middle select */
			) AS "t5"
			/* outer select */
	) AS "User_posts" ON TRUE
WHERE "t1"."id" = $1
LIMIT $2
m-n relation queries example

Prisma Client query

await prisma.post.findUnique({
	where: {
		id: 1
	},
	include: {
		tags: true
	}
})

SQL

SELECT
	"t1"."id",
	"t1"."title",
	"t1"."content",
	"t1"."published",
	"t1"."authorId",
	"Post_tags_m2m"."__prisma_data__" AS "tags"
FROM
	"public"."Post" AS "t1"
	LEFT JOIN LATERAL (
		SELECT
			COALESCE(JSON_AGG("__prisma_data__"), '[]') AS "__prisma_data__"
		FROM
			(
				SELECT
					"Post_tags"."__prisma_data__"
				FROM
					"public"."_PostToTag" AS "t2"
					LEFT JOIN LATERAL (
						SELECT
							JSON_BUILD_OBJECT('id', "t4"."id", 'name', "t4"."name") AS "__prisma_data__",
							"t4"."id"
						FROM
							(
								SELECT
									"t3".*
								FROM
									"public"."Tag" AS "t3"
								WHERE
									"t2"."B" = "t3"."id"
									/* root select */
							) AS "t4"
					) AS "Post_tags" ON TRUE
				WHERE
					"t2"."A" = "t1"."id"
			) AS "Post_tags_m2m_1"
	) AS "Post_tags_m2m" ON TRUE
WHERE "t1"."id" = $1
LIMIT $2

Share your feedback and create a bug report if you encounter any issues.

Prisma’s distinct option now uses SQL queries (Preview)

From this release, Prisma Client’s distinct option now uses the native SQL DISTINCT ON for unordered queries with PostgreSQL and CockroachDB. The upcoming releases will expand support for the other databases that Prisma supports.

Prisma Client already supports querying for distinct records. However, Prisma Client took care of the post-processing for distinct records in memory.

To get started, enable the Preview feature in your Prisma schema:

// schema.prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["nativeDistinct"]
}

Regenerate your Prisma Client to get started using the Preview feature.

Given the following Prisma Client query:

await prisma.user.findMany({
    distinct: ['role'],
    select: {
      role: true,
    },
})

Before 5.7.0

Previously, Prisma Client handled the post-processing to select distinct records in-memory. Therefore, the following query was generated and executed against your database:

SELECT
	"public"."User"."id",
	"public"."User"."role"::text
FROM
	"public"."User"
WHERE
	1 = 1 OFFSET $1

After 5.7.0

SELECT DISTINCT ON ("public"."User"."role")
	"public"."User"."id",
	"public"."User"."role"::text
FROM
	"public"."User"
WHERE
	1 = 1 OFFSET $1

Share your feedback and create a bug report if you encounter any issues.

Improved support for Netlify using Node.js v20

In this release, we improved Prisma support when deploying to Netlify on Node.js v20. Previously, the Prisma Client could not resolve the location of the Query Engine after deploying to Netlify when using Node.js v20. If you run into this issue, we recommend updating to Prisma v5.7.0.

We recommend giving this comment on GitHub a read if you are not yet able to upgrade Prisma, to learn how to get around the error.

Fixes and improvements

Prisma Client

Prisma

Prisma Migrate

Credits

Huge thanks to @anuraaga, @onichandame, @LucianBuzzo, @RobertCraigie, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @AikoRamalho, @petradonka for helping!

Company news

💼 We’re hiring!

If you're interested in joining our growing team to help empower developers to build data-intensive applications, Prisma is the place for you.

We're hiring for the following roles:

5.6.0

14 Nov 14:04
bfe7bf8
Compare
Choose a tag to compare

🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟

🚀 Prisma Accelerate, our connection pool and global edge cache, is now Generally Available! Sign up to give it a try. 🚀

Highlights

Driver adapters improvements (Preview)

In version 5.4.0, we released driverAdapters into Preview. The driverAdapters feature enables Prisma Client to access your database using JavaScript or Serverless database drivers.

In this release, we fixed many bugs for the existing driver adapters. We appreciate all the community feedback that has helped us improve this feature!

PlanetScale serverless driver adapter improvements

This release also introduces a small breaking change to the @prisma/adapter-planetscale package to improve its stability and performance. The serverless driver adapter will now use a connection pool instead of a single connection from PlanetScale’s serverless driver.

In case you’re using the @prisma/adapter-planetscale, update your Prisma Client instance with the following:

-import { connect } from '@planetscale/database'
+import { Client } from '@planetscale/database'
import { PrismaPlanetScale } from '@prisma/adapter-planetscale'
import { PrismaClient } from '@prisma/client'
import { fetch as undiciFetch } from 'undici';

-const connection = connect({ url: connectionString, fetch: undiciFetch })
+const client = new Client({ url: connectionString, fetch: undiciFetch })

-const adapter = new PrismaPlanetScale(connection)
+const adapter = new PrismaPlanetScale(client)

const prisma = new PrismaClient({ adapter })

If you run into the following error: [TypeError]: PrismaPlanetScale must be initialized with an instance of Client., you can use the following snippet when defining your Prisma Client instance:

import { createRequire } from "node:module";
import { PrismaPlanetScale } from "@prisma/adapter-planetscale";
import { fetch as undiciFetch } from 'undici';

const require = createRequire(import.meta.url);
const { Client } = require("@planetscale/database");

const client = new Client({ url:  process.env.DATABASE_URL , fetch: undiciFetch })
const adapter = new PrismaPlanetScale(client);

Request for feedback

We encourage you to try out the driver adapters and share your feedback to help us move it to General Availability in either of the following GitHub discussions:

Refer to our docs to learn more about driver adapters.

New prisma debug command

This release introduces a new command: prisma debug. The command provides debugging information such as environment variables that Prisma Client, Prisma Migrate, Prisma CLI, and Prisma Studio use. The command is also useful when creating a bug report as the information complements the output of the prisma -v command.

You can learn more about the command in our docs.

Read replicas extension improvements

We also released version 0.3.0 of the @prisma/extension-read-replicas package that contains the following improvements:

  • A new $replica() method that explicitly enables you to use a replica for your query.

    For example, by default, the queryRaw and executeRaw methods are forwarded to the primary database, as they could try to write to the database. You can use the $replica() method with either of the *Raw methods to explicitly execute your query against a replica instead of your primary database.

  • Validation for when there’s an empty list of replicas.

  • Webpack bundling fixes

We want to thank you, our community members, for your contributions! 🙏

You can find additional information on the changes in the extension’s release. You can learn more about the extension in the announcement blog post.

Package provenance

npm has introduced provenance statements to improve supply-chain security and transparency of packages. This allows developers to verify where and how packages are built.

Starting with the 5.6.0 release, all npm packages for Prisma ORM will be published with provenance statements. If you maintain a Prisma Client extension or generator, we encourage you to enable provenance statements when publishing to npm.

Fixes and improvements

Prisma Migrate

Prisma Client

Prisma CLI

Credits

Huge thanks to @onichandame, @LucianBuzzo, @RobertCraigie, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @luxaritas, @Nasfame, @lukahartwig, @steebchen, @icanipa for helping!

Company news

Prisma Accelerate is now Generally Available

We're excited to share that Prisma Accelerate is now Generally Available. Prisma Accelerate is a global database cache that's available in over 280 locations and provides scalable connection pooling for serverless and edge applications.

Learn more in the announcement blog post. Sign up and try out Prisma Accelerate here.

💼 We’re hiring!

If you're interested in joining our growing team to help empower developers to build data-intensive applications, Prisma is the place for you.

We're hiring for an Engineering Manager: Prisma Data Platform.

5.5.2

25 Oct 18:15
eadd44f
Compare
Choose a tag to compare

5.5.1

25 Oct 12:52
Compare
Choose a tag to compare

Today, we are issuing the 5.5.1 patch release.

Fix in Prisma Client

5.5.0

24 Oct 14:03
94d65e3
Compare
Choose a tag to compare

🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟

Highlights

Serverless database drivers improvements and request for feedback (Preview)

In version 5.4.0, we released driverAdapters into Preview. The driverAdapter feature enables Prisma Client to access your database using other JavaScript or Serverless database drivers such as Neon, PlanetScale, and Turso.

The driver adapters allow Prisma Client to connect to your database using protocols besides TCP, such as HTTP (PlanetScale and Turso) and WebSockets (Neon). You can learn more about the Preview feature from the announcement blog post.

In this release, we focused our efforts on fixing bugs and improving the stability of the Preview feature.

We encourage you to try it out and share your feedback to help us move it to General Availability in either of the following GitHub discussions:

New flags for the prisma init command

This release introduces 3 new flags you can provide when initializing Prisma in your project using the prisma init command:

  • --generator-provider: Defines the default generator to use
  • --preview-features: Specifies the default Preview features to use in your project
  • --output: Specifies the default output location for the generated client

Fixes and improvements

Prisma CLI

Prisma Client

Credits

Huge thanks to @onichandame, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @michaelpoellath, @lukahartwig, @steebchen, @icanipa, @jiashengguo, @stephenwade for helping!

💼 We're hiring!

If you're interested in joining our growing team to help empower developers to build data-intensive applications, Prisma is the place for you.

We're currently hiring for the following roles:

5.4.2

09 Oct 18:20
Compare
Choose a tag to compare

Today, we are issuing the 5.4.2 patch release.

Fix in Prisma Client

5.4.1

04 Oct 22:37
Compare
Choose a tag to compare

Today, we are issuing the 5.4.1 patch release.

Fix in Prisma Client

Fix in @prisma/adapter-planetscale

5.4.0

04 Oct 17:07
6800c63
Compare
Choose a tag to compare

🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟

Highlights

Preview support for PlanetScale and Neon serverless database drivers

We’re excited to announce Preview support for the Neon and PlanetScale serverless database drivers. The PlanetScale and Neon serverless database drivers allow Prisma to connect to your database using protocols besides TCP — HTTP (PlanetScale) or WebSockets (Neon).

To get started with the serverless database drivers, first enable the driverAdapters Preview feature flag in your Prisma schema:

// schema.prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}

Next, to set up Prisma Client to use the serverless database drivers:

PlanetScale

Install the Prisma adapter for PlanetScale and PlanetScale serverless database driver, and undici:

npm install @prisma/adapter-planetscale @planetscale/database undici

Prisma ORM supports Node 16 and up. In Node 18 and up, undici is not needed.

Ensure you update the host value in your connection string to aws.connect.psdb.cloud. You can learn more about this here.

DATABASE_URL='mysql://johndoe:strongpassword@aws.connect.psdb.cloud/clear_nightsky?sslaccept=strict'

Update your Prisma Client instance to use the PlanetScale database driver:

// Import required dependencies
import { connect } from '@planetscale/database';
import { PrismaPlanetScale } from '@prisma/adapter-planetscale';
import { PrismaClient } from '@prisma/client';
import { fetch as undiciFetch } from 'undici';

// Initialize Prisma Client with the PlanetScale serverless database driver
const connection = connect({ url: connectionString, fetch: undiciFetch });
const adapter = new PrismaPlanetScale(connection);
const prisma = new PrismaClient({ adapter });

PlanetScale Driver in 5.7.0 and later

In Prisma 5.7.0, usage of the PlanetScale driver adapter changed to the following:

// For Prisma 5.7.0 and later
// Import required dependencies
import { Client } from '@planetscale/database';
import { PrismaPlanetScale } from '@prisma/adapter-planetscale';
import { PrismaClient } from '@prisma/client';

// Initialize Prisma Client with the PlanetScale serverless database driver
const client = new Client({ url: process.env.DATABASE_URL });
const adapter = new PrismaPlanetScale(client);
const prisma = new PrismaClient({ adapter });

Neon

Install the Prisma adapter for Neon, Neon serverless database driver and undici (WebSockets):

npm install @prisma/adapter-neon @neondatabase/serverless undici

Update your Prisma Client instance to use the Neon serverless database driver:

// Import required dependencies
import { Pool, neonConfig } from '@neondatabase/serverless';
import { PrismaNeon } from '@prisma/adapter-neon';
import { PrismaClient } from '@prisma/client';
import { WebSocket } from 'undici'

neonConfig.webSocketConstructor = WebSocket;

// Initialize Prisma Client with the Neon serverless database driver
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const adapter = new PrismaNeon(pool);
const prisma = new PrismaClient({ adapter });

Let us know your feedback about the Neon or Planetscale serverless database drivers in the linked GitHub discussions. Create a bug report if you run into any issues.

Early Access support for Turso

Turso is an edge-hosted, distributed database that's based on libSQL, an open-source and open-contribution fork of SQLite, enabling you to bring data closer to your application and minimize query latency.

Since support for Turso is in Early Access, there may be some rough edges which we’re still working on it to improve the API and overall support. Additionally, it is behind the driverAdapters Preview feature flag. Enable it to get started using Turso in your project:

// schema.prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}

Next, install the Prisma Client adapter for Turso and the libSQL database client

npm install @prisma/adapter-libsql @libsql/client

Update your Prisma Client instance:

// Import required dependencies
import { PrismaClient } from '@prisma/client'
import { PrismaLibSQL } from '@prisma/adapter-libsql'
import { createClient } from '@libsql/client'

// Create a new instance of the libSQL database client
const libsql = createClient({
  // @ts-expect-error
  url: process.env.TURSO_DATABASE_URL,
  authToken: process.env.TURSO_AUTH_TOKEN 
})

// Create a Prisma "adapter" for libSQL
const adapter = new PrismaLibSQL(libsql)
// Pass the adapter option to the Prisma Client instance
const prisma = new PrismaClient({ adapter })

You can learn more on how to use Prisma together with Turso in the announcement blog post.

Try it out! Let us know what you think and create a bug report if you run into any issues.

Query performance improvements

In our continued efforts to make Prisma Client faster, we identified and improved the performance of different types of queries.

Relation filters improvements

We made the following improvements to relation filters:

  • Removed an unnecessary INNER JOIN used in relation filter queries (Big thank you to @KhooHaoYit for helping out)
  • Use of LEFT JOIN's for to-one relations. Previously, Prisma made use of sub-queries to fetch data.

Example Prisma Client query

prisma.comment.findMany({
  where: {
    post: {
      author: {
        name: "John"
      }
    }
  }
})

Before 5.4.0

SELECT
  "Comment"."id"
FROM
  "Comment"
WHERE
  ("Comment"."id") IN (
    SELECT
      "t0"."id"
    FROM
      "Comment" AS "t0"
      INNER JOIN "Post" AS "j0" ON ("j0"."id") = ("t0"."postId")
    WHERE
      (
        ("j0"."id") IN (
          SELECT
            "t1"."id"
          FROM
            "Post" AS "t1"
            INNER JOIN "User" AS "j1" ON ("j1"."id") = ("t1"."userId")
          WHERE
            (
              "j1"."name" = $ 1
              AND "t1"."id" IS NOT NULL
            )
        )
        AND "t0"."id" IS NOT NULL
      )
  );

After 5.4.0

SELECT
  "Comment"."id"
FROM
  "Comment"
  LEFT JOIN "Post" AS "j1" ON ("j1"."id") = ("Comment"."postId")
  LEFT JOIN "User" AS "j2" ON ("j2"."id") = ("j1"."userId")
WHERE
  (
    "j2"."name" = $ 1
    AND ("j2"."id" IS NOT NULL)
    AND ("j1"."id" IS NOT NULL)
  );

If you’re interested in more details on the relation query filter improvements, you can take a look at this pull request.

Enum improvements on PostgreSQL and CockroachDB

Previously, when an enum value was used in a query, our Postgres driver would make additional queries to resolve the enum types that were used.

In this release, we’re making improvements by casting enums to TEXT to avoid the additional roundtrips when resolving the types.

This change should have the most impact if you’re using pgBouncer or if you’re running Prisma in a serverless environment, where our Postgres driver can’t cache enum types information.

Prisma schema

model User {
  id   Int  @id @default(cuid())
  role Role
}

enum Role {
  User
  Admin
}

Prisma Client query

await prisma.user.findMany({ 
  where: {
    role: "Admin"
  }
})

Before 5.4.0

-- Internal driver query
SELECT t.typname, t.typtype, t.typelem, r.rngsubtype, t.typbasetype, n.nspname, t.typrelid FROM pg_catalog.pg_type t LEFT OUTER JOIN pg_catalog.pg_range r ON r.rngtypid = t.oid INNER JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid WHERE t.oid = $1;

-- Internal driver query
SELECT enumlabel FROM pg_catalog.pg_enum WHERE enumtypid = $1 ORDER BY enumsortorder;

-- Prisma Client query
SELECT id, role FROM "User" WHERE role = $1;

After 5.4.0

-- Prisma Client query
SELECT id, role::text FROM "User" WHERE role = CAST($1::text AS "Role);

Bulk delete improvements

We optimized the deleteMany operation by:

  • Removing all SELECT queries used to fetch data that would be used as input for the DELETE operation. In some cases, this also improves index usage.
  • Removing the transaction previously used as it’s now a single atomic operation.

Prisma Client query

await prisma.post.deleteMany({
  where: {
    id: {
      gt: 1,
      lt: 10,
    }
  }
})

Before 5.4.0

BEGIN
SELECT id FROM "Post" WHERE id > 1 AND id < 10;
SELECT id FROM "Post" WHERE id > 1 AND id < 10 AND id IN (<...select ids>);
DELETE FROM "Post" WHERE id IN (<...select ids>) AND id > 1 AND ...
Read more