Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
APACHE-2.0 License
Bot releases are hidden (Show)
Published by SevInf 9 months ago
Today, we are issuing the 5.8.1
patch release.
Published by ruheni 10 months ago
š Help us spread the word about Prisma by starring the repo or posting on X about the release. š
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 JOIN
s 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 JOIN
s to fetch relation dataquery
ā uses sub-queries to fetch relation dataWhen 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.
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.
target
and timestamp
are undefined in info
events in Data Proxy clienttimestamp
and duration
in query events with Data Proxycitext
fields with neon database driver causes conversion errorError validating field 'id' in model 'Post': MongoDB '@default(auto())' fields must have 'ObjectId' native type.
Huge thanks to @anuraaga, @onichandame, @LucianBuzzo, @RobertCraigie, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @tinola, @AikoRamalho, @luxaritas for helping!
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!
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.
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.
Published by millsp 10 months ago
Today, we are issuing the 5.7.1
patch release.
This patch fixes multiple small problems in our relationJoins
preview feature. If you ran into problems when testing relationJoins
before, please give it another go with 5.7.1 and share your feedback or create a bug report if you encounter any issues.
relationJoins
: Int[] return as nullrelationJoins
: fails when filtering includes by isNot: nullrelationJoins
: "The table (not available) does not exist in the current database."relationJoins
: PostgresError { code: "54023", message: "cannot pass more than 100 arguments to a function", severity: "ERROR", detail: None, column: None, hint: None }relationJoins
: Inconsistent column data: Unexpected conversion failure from String to datetime. Reason: $trailing inputPublished by ruheni 11 months ago
š Help us spread the word about Prisma by starring the repo or posting on X (formerly Twitter) about the release.
āØ 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! āØ
JOIN
s for relation queries for PostgreSQL and CockroachDBWeāre excited to announceĀ PreviewĀ support for JOIN
s in Prisma Client when querying relations. Support for JOIN
s 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 JOIN
s, 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
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
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
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.
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.
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.
InterpretationError("Unable to convert expression result into a set of selection results", None)
(starting with 5.2.0)TRUNCATE
ing the table on CockroachDB: placeholder $1 already has type string, cannot assign Color
Prisma Client could not locate the Query Engine for runtime "rhel-openssl-3.0.x"
)Huge thanks to @anuraaga, @onichandame, @LucianBuzzo, @RobertCraigie, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @AikoRamalho, @petradonka for helping!
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:
Published by ruheni 11 months ago
š 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. š
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!
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);
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.
prisma debug
commandThis 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.
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.
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.
db push
with invalid connection string: Connection string redacted, weird grammardb pull --url=...
logs full connection string on P4001 The introspected database was empty
prisma_pool_connections_idle
reports misleading number@prisma/adapter-planetscale
PrismaPlanetScale
adapter to the constructorError: sha256 checksum of https://binaries.prisma.sh/all_commits/475c616176945d72f4330c92801f0c5e6398dc0f/windows/query_en gine.dll.node.gz (zipped) should be 748d039badd0919d022fff7d554b66b6937b79035861a6ae9a80c5a95eee76f5 but is b867ad335ee6f58c6a38f665dd641c95e6adff3061f92b7613c62cae1c3362bb
Huge thanks to @onichandame, @LucianBuzzo, @RobertCraigie, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @luxaritas, @Nasfame, @lukahartwig, @steebchen, @icanipa for helping!
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.
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.
Published by Jolg42 12 months ago
Today, we are issuing the 5.5.2
patch release.
Published by Jolg42 12 months ago
Today, we are issuing the 5.5.1
patch release.
Published by ruheni 12 months ago
š Help us spread the word about Prisma by starring the repo or tweeting about the release. š
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:
prisma init
commandThis 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 clientprisma.model.count
does not type distinct
correctlyā¦.findMany()
invocation: The column j1.id
does not exist in the current database.Huge thanks to @onichandame, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @michaelpoellath, @lukahartwig, @steebchen, @icanipa, @jiashengguo, @stephenwade for helping!
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:
Published by Jolg42 about 1 year ago
Today, we are issuing the 5.4.2
patch release.
Published by millsp about 1 year ago
Today, we are issuing the 5.4.1
patch release.
@prisma/adapter-planetscale
Published by ruheni about 1 year ago
š Help us spread the word about Prisma by starring the repo or tweeting about the release. š
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:
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:[email protected]/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 });
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.
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.
In our continued efforts to make Prisma Client faster, we identified and improved the performance of different types of queries.
We made the following improvements to relation filters:
INNER JOIN
used in relation filter queries (Big thank you to @KhooHaoYit for helping out)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.
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);
We optimized the deleteMany
operation by:
SELECT
queries used to fetch data that would be used as input for the DELETE
operation. In some cases, this also improves index usage.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 id < 10;
COMMIT
After 5.4.0
DELETE FROM "Post" WHERE id > 1 AND id < 10;
We improved the upsert
operation (non-native database upsert) by removing a redundant SELECT
query:
Prisma Client query
await prisma.user.upsert({
where: { email: "[email protected]" },
create: { email: "[email protected]", firstName: "John" },
update: { firstName: "Johnny" },
})
Before 5.4.0
SELECT `User`.`id` FROM `User` WHERE `User`.`email` = ?;
SELECT `User`.`id` FROM `User` WHERE `User`.`email` = ?;
UPDATE `prisma`.`User` SET `firstName` = ? WHERE `prisma`.`User`.`id` IN (?) AND `prisma`.`User`.`email` = ?;
SELECT `User`.`id` FROM `User` WHERE `User`.`id` = ?;
After 5.4.0
SELECT `User`.`id` FROM `User` WHERE `User`.`email` = ?;
UPDATE `prisma`.`User` SET `firstName` = ? WHERE `prisma`.`User`.`id` IN (?) AND `prisma`.`User`.`email` = ?;
SELECT `User`.`id` FROM `User` WHERE `User`.`id` = ?;
SELECT
may be generated by upsert()
deleteMany
optimisationUPDATE
, slowing down transaction.deleteMany
seems to send 2 identical read queries first before triggering the actual deleteRustPanic: RuntimeError: panicked at 'internal error: entered unreachable code', query-engine/prisma-models/src/field/scalar.rs:93:50
metrics
propertiesjest-mock-extended
or vitest-mock-extended
expects never
input @@schema
is defined in a block without the schemas
attributeHuge thanks to @onichandame, @fqazi, @KhooHaoYit, @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @michaelpoellath, @RobertCraigie, @icanipa, @jiashengguo, @stephenwade, @darthmaim, @ludralph, @Gerschtli, @andyjy for helping!
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:
Feel free to read the job descriptions and apply using the links provided.
Published by Jolg42 about 1 year ago
Today, we are issuing the 5.3.1
patch release.
Published by ruheni about 1 year ago
š Help us spread the word about Prisma by starring the repo or tweeting about the release. š
In this sprint, weāve made bug fixes and overall improvements to Prisma Client. Weāve been working on a few projects that will be announced soon. Stay tuned for the upcoming releases for updates!
We made the following changes:
undefined
values in arrays in Json
fieldsundefined
values in arrays in Json
fields. Prisma Client will now return an error when an array contains an undefined
value. Therefore, we encourage you to add validation that either removes the value or transforms it to null
if you stumble on the runtime validation:// Query
await prisma.user.findMany({
where: {
// JSON field
preferences: [undefined, '"theme": "dark"', null, ]
}
})
// Example error message on running the query
Can not use `undefined` value within array. Use `null` or filter out `undefined` values
This release improves Prisma Clientās memory consumption for models with many @unique
constraints. This was a regression from version 4.10.1, where in some cases, if a model had many unique constraints, Prisma Client would use up a lot of available memory.
prisma_pool_connections_open
metric to have a negative value in some cases.prisma db pull
would throw an error. We resolved this, and views are now ignored.PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK
environment variable that enables you to disable advisory locking.SetDefault
with NoAction
when using MySQL and the default/foreignKeys
relation mode.prisma migrate deploy
: MariaDB doesn't yet support 'GET_LOCK in cluster (WSREP_ON=ON)'
prisma_pool_connections_open
has a bug where it goes negativeError: socket hang up
on Linux/arm64undefined
from Arrays when using Json fields with PostgresSetDefault
with NoAction
when provider = "mysql"
and relationMode = "foreignKeys" | default
Huge thanks to @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @michaelpoellath, @RobertCraigie, @stephenwade for helping!
Published by ruheni about 1 year ago
š Help us spread the word about Prisma by starring the repo or tweeting about the release. š
In this release, weāve made the following improvements to Prisma Client when using Prisma Accelerate or Prisma Data Proxy:
Prisma Client will now automatically determine how it should connect to the database depending on the protocol in the connection string. If the connection string starts with prisma://
, Prisma Client will try to connect to your database using Prisma Accelerate or Prisma Data Proxy.
Prisma Studio now works with Prisma Data Proxy and Prisma Accelerate.
Weāve introduced a new --no-engine
flag which will prevent a Query Engine file from being included in the generated Prisma Client. This flag will also help ensure the bundle size of your application remains small by excluding the Query Engine files from the generated Prisma Client.
prisma generate --no-engine
The --data-proxy
and --accelerate
flags have not been removed but are now aliases for the new --no-engine
flag.
We recommend using the --no-engine
flag when generating Prisma Client that uses either Accelerate or Data Proxy.
This release simplifies the API used when programmatically overriding the connection string by introducing the datasourceUrl
property in Prisma Clientās constructor. This means you do not have to use the datasource name defined in your Prisma schema.
const prisma = new PrismaClient({
datasourceUrl: "postgresql://johndoe:randompassword@localhost:5432/mydb",
})
Continuing our work from 5.1.0 we made further performance improvements around the queries Prisma executes, targeting one-to-many relation fields and nested updates.
LIMIT
in one-to-many relations on a single parentIn cases where there is a single parent with a one-to-many relation included (findFirst
, findUnique
, findMany({ take: 1 })
), we now utilize LIMIT
at the database level to restrict the number of related items returned instead of retrieving all related items into memory and performing a take
in memory.
For situations where you have many related objects but only need a few, you should see a dramatic improvement in speed and memory usage.
Note: we are still working on bringing this improvement to other parts of Prisma Client in upcoming releases. If multiple parent records are returned, the previous behavior is used.
Thanks to our introduction of using RETURNING
in some cases in 5.1.0, we could now improve performance in nested writes by removing reload nodes. This will now result in one less query per relation traversed in a nested write. For more info, check out the pull request.
await prisma.post.update({
where: { id: 1 },
data: {
comment: {
update: {
data: {
body: "Updated comment body"
}
}
}
},
select: {
id: true,
title: true,
}
})
SELECT "Post"."id", "Post"."title" FROM "Post" WHERE ("Post"."id" = $1 AND 1=1) LIMIT $2 OFFSET $3
SELECT "Post"."id", "Post"."userId" FROM "Post" WHERE "Post"."id" = $1 OFFSET $2
SELECT "User"."id" FROM "User" WHERE (1=1 AND "User"."id" IN ($1)) OFFSET $2
SELECT "User"."id" FROM "User" WHERE ("User"."id" = $1 AND 1=1) LIMIT $2 OFFSET $3
SELECT "User"."id", "User"."commentId" FROM "User" WHERE "User"."id" = $1 OFFSET $2
SELECT "Comment"."id" FROM "Comment" WHERE (1=1 AND "Comment"."id" IN ($1)) OFFSET $2
UPDATE "Comment" SET "body" = $1 WHERE ("Comment"."id" = $2 AND 1=1) RETURNING "Comment"."id"
SELECT "Post"."id", "Post"."title" FROM "Post" WHERE "Post"."id" = $1 LIMIT $2 OFFSET $3
SELECT "Post"."id", "Post"."title", "Post"."userId" FROM "Post" WHERE ("Post"."id" = $1 AND 1=1) LIMIT $2 OFFSET $3
SELECT "User"."id" FROM "User" WHERE (1=1 AND "User"."id" IN ($1)) OFFSET $2
SELECT "User"."id", "User"."commentId" FROM "User" WHERE ("User"."id" = $1 AND 1=1) LIMIT $2 OFFSET $3
SELECT "Comment"."id" FROM "Comment" WHERE (1=1 AND "Comment"."id" IN ($1)) OFFSET $2
UPDATE "Comment" SET "body" = $1 WHERE ("Comment"."id" = $2 AND 1=1) RETURNING "Comment"."id"
SELECT "Post"."id", "Post"."title" FROM "Post" WHERE "Post"."id" = $1 LIMIT $2 OFFSET $3
limit
is gone when findUnique
with include relation Cannot fetch data from service: include is not a function
Error while using Next.js with Data Proxytake
key doesn't work correctly for nested query that returns one item with its nested childrendisconnect: true
does not appear to delete the foreign key in the returned dataneeds
and count
methodmockDeep<PrismaClient>()
@prisma/client/edge
can not find environment variable<Model>CountOutputTypeDefaultArgs
does not existprisma generate
when Unsupported field defined in a Composite typeHuge thanks to @skyzh, @alula, @michaelpoellath, @RobertCraigie, @darthmaim, @Gerschtli, @andyjy, @mejiaej, @iurylippo, @mrazauskas, @coder246, @RDIL for helping!
Published by SevInf about 1 year ago
Today, we are issuing the 5.1.1
patch release.
disconnect: true
does not appear to delete the foreign key in the returned dataneeds
and count
methodPublished by nikolasburk about 1 year ago
Today, we are excited to share theĀ 5.1.0
Ā stable releaseĀ š
šĀ Help us spread the word about Prisma by starring the repoĀ āļøĀ orĀ tweetingĀ about the release.
After two big releases where we released Client extensions for production usage (4.16.0
) and made Prisma faster by default (5.0.0
), we have focused on some smaller issues to make the experience with these new features even better.
Our community has been on the roll! We appreciate everyone who helps us by opening a GitHub issue or proposing a fix via Pull Requests. In this release, we're excited to highlight multiple community contributions:
PrismaAction
type, missing findUniqueOrThrow
Ā andĀ findFirstOrThrow
https://github.com/prisma/prisma/pull/17471 by @mejiaej and missing groupBy
https://github.com/prisma/prisma/pull/19985 by @iurylippoIn our continued and ongoing work to make Prisma faster, we identified some Prisma Client queries that led to multiple SQL statements being executed ā although in specific databases, that was not necessary.
Hence we optimized our internal SQL generation for PostgreSQL and CockroachDB to generate more efficient SQL queries:
create
queryIn a simple create
query, RETURNING
makes the second query and the transaction statements obsolete:
prisma.user.create({
data: { name: "Original name" }
})
BEGIN
INSERT INTO "User" ("name") VALUES ($1) RETURNING "User"."id"
SELECT "User"."id", "User"."name" FROM "User" WHERE "User"."id" = $1;
COMMIT
-- Sends 1 statement (instead of 2) and omits the transaction
INSERT INTO "User" ("name") VALUES ($1) RETURNING "User"."id", "User"."name"
update
queryFor a simple update
query, RETURNING
makes both additional queries and the transaction statements obsolete:
prisma.user.update({
where: { id: 1 },
data: { name: "updated" }
})
BEGIN
SELECT id FROM "User" WHERE "User".id = 1;
UPDATE "User" SET name = 'updated' WHERE "User".id = 1;
SELECT id, name FROM "User" WHERE "User".id = 1;
COMMIT
-- Sends 1 statement (instead of 3) and omits the transaction
UPDATE "User" SET name = 'updated' WHERE "User".id = 1 RETURNING "User".id, "User".name;
update
query, return with relation valueOne SELECT
query could easily be dropped in a simple update
query that should return a relation value as well:
prisma.user.update({
where: { id: 1 },
data: { name: "updated" },
includes: { posts: true }
})
BEGIN
SELECT id FROM "User" WHERE "User".id = 1;
UPDATE "User" SET name = 'updated' WHERE "User".id = 1;
SELECT id, name FROM "User" WHERE "User".id = 1;
SELECT id, title FROM "Post" WHERE "Post"."userId" = 1;
COMMIT
-- Sends 3 statements (instead of 4)
BEGIN
UPDATE "User" SET name = 'updated' WHERE "User".id = 1 RETURNING "User".id;
SELECT id, name FROM "User" WHERE "User".id = 1;
SELECT id, title FROM "Post" WHERE "Post"."userId" = 1;
COMMIT
update
queryAn empty update
query can be optimized to skip the transaction and the second identical query by creating specific handling for this edge case in our code:
prisma.user.update({
where: { id: 1 },
data: {},
})
BEGIN
SELECT id, name FROM "User" WHERE "User".id = 1;
SELECT id, name FROM "User" WHERE "User".id = 1;
COMMIT
-- Sends 1 statement (instead of 2) and omits the transaction
SELECT id, name FROM "User" WHERE "User".id = 1;
update
query (but do not return relation value)An update of both the model and its relation, we could drop 2 SELECT
queries that we did before without ever using their return values:
prisma.user.update({
where: { id: 1 },
data: {
name: "updated",
posts: {
update: {
where: { id: 1 },
data: {
title: "updated"
}
}
}
}
})
BEGIN
SELECT id, name FROM "User" WHERE "User".id = 1;
UPDATE "User" SET name = 'updated' WHERE "User".id = 1 RETURNING "User".id;
SELECT "id", "postId" FROM "Post" WHERE "Post".id = 1;
UPDATE "Post" SET title = 'updated' WHERE "Post"."userId" = 1 AND "Post".id = 1;
SELECT id, name FROM "User" WHERE "User".id = 1;
COMMIT
-- Sends 3 statements (instead of 5)
BEGIN
UPDATE "User" SET name = 'updated' WHERE "User".id = 1 RETURNING "User".id, "User".name;
SELECT "id", "postId" FROM "Post" WHERE "Post".id = 1;
UPDATE "Post" SET title = 'updated' WHERE "Post"."userId" = 1 AND "Post".id = 1;
COMMIT
In the next releases, we will continue optimizing Prisma Client queries to only run the minimal amount of SQL queries necessary.
If you notice any Prisma Client queries that are affected right now, please check the issues under our performance/queries
label. If you didnāt find one for what youāre seeing, please create a new issue. This will be super useful for us to understand all (edge) cases. Thank you!
directUrl
Our CLI command prisma studio
that opens Prisma Studio now also can use the directUrl
property of the datasource
block so you can make it talk to a different database than defined in url
. This makes it easier to use Studio alongside the Prisma Data Proxy and Accelerate.
We fixed (almost) all cases where using a specific term as a model name in your Prisma Schema would lead to a type clash due to Prismaās generated typings. As a result of a type clash, it was not possible to use that model in your code (this was e.g. the case if you named a model Model
or ModelUpdate
).
We also deprecated the <ModelName>Args
type as part of that fix. Going forward, <ModelName>DefaultArgs
should be used instead.
X
and XUpdate
Model
and ModelUpdate
is defined in the schema @prisma/internals
(previously @prisma/sdk) uses deprecated dependencies [email protected]
via temp-write 4.0.0
Datasource
breaks generated return typesmodel
names cause clashes in generated types$extends
TS error: "Inferred type of this node exceeds the maximum length the compiler will serialize" with "declaration": true
in tsconfig
Type '"findUniqueOrThrow"' is not assignable to type 'PrismaAction'
Promise
breaks types for PrismaPromise
include
not working on models ending with ...Update
with unique compound indexLogLevel
enum conflicts with built-in Prisma typePrisma.XyzFindManyArgs
breaks findMany
typing in v4.16.0+this.$on("beforeExit")
doesn't work anymore on 5.0.0Error: Unknown value type
on nested createfindUnique
on @unique
columns that are enums<Tablename>UpsertArgs
select field does not match type for db.<tablename>.upsert(item)
by
in groupBy
in 5.0.0TypeError [ERR_INVALID_URL]: Invalid URL
when HTTP(S)_PROXY
en var has is set to a URL without a protocoltsc --watch
fails with JavaScript heap out of memory
errorGetResult
Huge thanks to @skyzh, @alula, @michaelpoellath, @RobertCraigie, @Gerschtli, @andyjy, @mejiaej, @iurylippo, @mrazauskas for helping!
Published by ruheni over 1 year ago
Weāre excited to share the 5.0.0
release todayĀ š
Prisma 5.0.0
contains a lot of changes that improve Prismaās performance, especially in serverless environments. If you want to learn more about the performance improvements, we wrote a blog post that sums up all the changes we made: Prisma 5: Faster by Default.
As this is a major release, it includes a few breaking changes that might affect a small group of our users. Before upgrading, we recommend that you check out our upgrade guide to understand the impact on your application.
š Help us spread the word about Prisma by starring the repo or tweeting about the release. š
Hereās a summary of the changes:
jsonProtocol
: improves communication between Prisma Client and the query engine, makes Prisma faster by default.fieldReference
: adds support for comparing columns of the same table.extendedWhereUnique
: adds support for non-unique columns inside where
clauses for queries that operate on unique records.rejectOnNotFound
propertycockroachdb
provider is now required when connecting to a CockroachDB databaseruntime/index.js
from the generated Prisma ClientbeforeExit
hook from the library engineprisma2
executableexperimentalFeatures
generator property in the Prisma schemamigration-engine
to schema-engine
Weāre thrilled to announce that the jsonProtocol
Preview feature is now Generally Available. You can now remove the Preview feature flag from your schema after upgrading. We made the JSON-based wire protocol the default protocol used for communication between Prisma Client and the query engine.
We introduced this feature in version 4.11.0 to improve Prismaās performance. Previously, Prisma used a GraphQL-like protocol to communicate between Prisma Client and the query engine. Applications with larger schemas had higher CPU and memory consumption compared to smaller schemas which created a performance bottleneck.
The JSON-based wire protocol improves efficiency when Prisma Client is communicating with the query engine.
We took the opportunity to remove some array shortcuts to make our typings more consistent and logical. These shortcuts were a way to add a single element as a value to an array-based operator instead of wrapping a single element in an array. We will now require array values for the following:
OR
operator shortcutsin
and notIn
operator shortcutspath
field shortcutHereās an example query using the OR
operator shortcut for a single element;
await prisma.user.findMany({
where: {
- OR: { email: '[email protected]' }
+ OR: [{ email: '[email protected]' }]
}
})
We recommend taking a look at the upgrade guide to learn how you can update your queries to work in Prisma 5.
Weāre excited to announce that the fieldReference
Preview feature is now stable and Generally Available. This means you can use this feature without the Preview feature flag in your Prisma schema.
We first introduced this feature in 4.5.0 to add the ability to compare columns on the same table. For example, the following query returns records where the quantity
value is less than the warnQuantity
of a product:
await prisma.product.findMany({
where: {
quantity: { lte: prisma.product.fields.warnQuantity }
},
})
To learn more about this feature, refer to our documentation.
Weāre excited to announce the extendedWhereUnique
Preview feature is now Generally Available. This means you can use the feature without the Preview feature flag in the Prisma schema.
We first introduced this feature in version 4.5.0 to add support for non-unique columns inside where
clauses for queries that operate on unique records, such as findUnique
, update
, and delete
, which was previously not possible.
For example, consider the following model:
model Article {
id Int @id @default(autoincrement())
content String
version Int
}
You can filter on non-unique columns such as the version
field as follows:
await prisma.article.findUnique({
where: {
id: 5,
version: 1 // filter on the `version` field was not available before Prisma 4.5.0
},
});
To learn more about this feature, refer to our documentation.
The minimum version of Node.js Prisma supports isĀ 16.13.0
. If you're using an earlier version of Node.js, you will need to upgrade your Node.js version.
Refer to ourĀ system requirementsĀ for the minimum versions Prisma requires.
The minimum version of TypeScript Prisma supports is 4.7. If your project is using an earlier version of TypeScript, you will need to upgrade your TypeScript version.
Refer to ourĀ system requirementsĀ for the minimum versions Prisma requires.
The minimum version of PostgreSQL Prisma supports is version 9.6. If youāre either using 9.4 or 9.5, you will need to update your PostgreSQL version to at least 9.6.
Refer to our system requirements for the minimum database versions Prisma requires.
We upgraded the embedded version of SQLite from 3.35.4 to 3.41.2. We do not anticipate any breaking changes or changes needed in projects using SQLite. However, if youāre using SQLite, especially with raw queries that might go beyond Prisma's functionality, make sure to checkĀ the SQLite changelog.
rejectOnNotFound
propertyIn version 5.0.0, we removed the rejectOnNotFound
parameter from Prisma Client that was deprecated in version 4.0.0. We removed this feature to provide better type-safety using the findUniqueOrThrow
and findFirstOrThrow
methods as well have a consistent API.
If you are using the rejectOnNotFound
parameter we recommend either:
findFirstOrThrow
or findUniqueOrThrow
methods if enabled at a query-level
findFirstOrThrow
and findUniqueOrThrow
model methods with your custom error handling if enabled at the client-level
We recommend taking a look at the upgrade guide for more information on how to adapt your application if youāre using rejectOnNotFound
.
cockroachdb
provider is now required when connecting to a CockroachDB databasePrior to adding explicit support for CockroachDB with the cockroachdb
provider in 3.9.0, it was possible to use the PostgreSQL provider when working with CockroachDB databases.
Weāre now making it mandatory to use the CockroachDB connector when working with CockroachDB databases. CockroachDB and PostgreSQL have a few differences such as the available native types which impact the generated migrations.
If you were using the PostgreSQL connector to work with CockroachDB, take a look at the upgrade guide to learn how you can update your connector.
runtime/index.js
file from Prisma ClientWith Prisma 5, we removed the runtime/index.js
file from Prisma Client. If you were using APIs from runtime/index.js
, such as Decimal
, PrismaClientKnownRequestError
, Ā NotFoundError
, Ā PrismaClientUnknownRequestError
, we recommend updating your imports:
- import { Decimal } from '@prisma/client/runtime'
+ import { Prisma } from '@prisma/client'
// Usage update of Prisma Client's utilities
- Decimal
+ Prisma.Decimal
We recommend taking a look at the upgrade guide to learn how you can migrate to Prisma 5
beforeExit
hook from the library
query engineWe removed the beforeExit
hook from the default library
Query Engine. We recommend using the built-in Node.js exit events.
-prisma.$on('beforeExit', () => { /* your code */ })
// Replacements
process.on('beforeExit', () => { /* your code */ })
process.on('exit', exitHandler)
process.on('SIGINT', exitHandler)
process.on('SIGTERM', exitHandler)
process.on('SIGUSR2', exitHandler)
We recommend taking a look at the upgrade guide to learn how you can migrate to Prisma 5.
prisma2
executableWhen we released Prisma 2, the prisma2
executable was used to differentiate it from Prisma 1. In a later release, the prisma2
CLI took over the prisma
executable name.
The prisma2
executable has been deprecated for a while and will now be removed. If youāre using prisma2
in your scripts, replace it with prisma
.
We removed the following deprecated flags in the Prisma CLI:
--preview-feature
: used in the prisma db execute
, prisma db seed
, and prisma migrate diff
commands--experimental
and --early-access-feature
: used in the prisma migrate
commands such as prisma migrate dev
--force
: for prisma db push
. The --force
flag was replaced by --accept-data-loss
in version 2.17.0--experimental-reintrospection
and --clean
: for prisma db pull
In the event youāre using one of these flags, we recommend removing the flags.
experimentalFeatures
generator propertyIn this release, we removed the experimentalFeatures
property that used to be in the generator property in the Prisma schema but has been renamed to previewFeatures
for a long time now. If youāre still using this property, you can either manually rename it to previewFeatures
or use the VS Code action to rename it if youāre using the latest version of the Prisma VS Code extension.
migration-engine
to schema-engine
In this release, we renamed the migration-engine
, responsible for running introspection and migration commands, to schema-engine
. For the majority of our users, no changes will be required. However, if you explicitly include or exclude the engine files you will need to update your code references. Refer to the upgrade guide for more information.
create
call<Model>RelationFilterInput
does not take nullability into accountOR
broke after opting in to jsonProtocol
feature.jsonProtocol
)jsonProtocol
GA binaries.prisma.sh/all_commits/
rejectOnNotFound
runtime/index.js
bundle from clientprisma dev
commandphotonResolver
and provider=photonjs
handlingfieldReference
GAextendedWhereUnique
GAprisma2
"executable"$extend
in factory function when compilerOptions.composite
is true
query
type to never
The package "path" wasn't found on the file system but is built into node
undefined
explicitly passed to select
/include
provider = "postgresql"
an errorexperimentalFeatures
generator propertydb pull
: Remove the version checker from introspectiondoctor
commandexperimentalFeatures
generator propertyexperimentalFeatures
Huge thanks to @michaelpoellath, @RobertCraigie, @Coder246, @RDIL, @oohwooh, @rqres, @zhiyan114, @spudly, @hayes, @boennemann, @DongGunYoon for helping!
Learn about the latest release and other news from the Prisma community by joining us for another "What's new in Prisma" live stream.
The stream takes place on YouTube on Thursday, July 13 at 5 pm Berlin | 8 am San Francisco.
Published by Jolg42 over 1 year ago
Today, we are issuing the 4.16.2
patch release.
$allModels: { $allOperations }
sets query type to never
undefined
explicitly passed to select
/include
Published by Jolg42 over 1 year ago
Today, we are issuing the 4.16.1
patch release.
$extend
in factory function when compilerOptions.composite
is true
Published by ruheni over 1 year ago
š Help us spread the word about Prisma by starring the repo or tweeting about the release. š
This release promotes the following Preview features to General Availability:
Today, weāre very excited to announce that Prisma Client extensions are Generally Available and production-ready! This means you can use the feature without the clientExtensions
Preview feature flag.š
Prisma Client extensions are a powerful new feature for adding functionality on top of your Prisma Client in a type-safe manner. With this feature, you can create simple, but flexible solutions.
Prisma Client extensions have 4 different types of components that can be included in an extension:
findMany
.const prisma = new PrismaClient().$extends({
name: "extension-name",
result: { /* ... */ },
model: { /* ... */ },
query: { /* ... */ },
client: { /* ... */ },
});
You can also create and publish extensions for others to use. Learn more about how to share extensions in our documentation.
We also made the following improvements to Prisma Client extensions in preparation for General Availability:
Added a top-level $allOperations
method for query
component that captures all model operations as well as top-level raw queries. Refer to our documentation for more information.
const prisma = new PrismaClient().$extends({
query: {
$allOperations({ args, query, operation, model }) {
/* your extension's logic here */
}
}
})
Prisma.validator
can now also be used for extended types:
const prisma = new PrismaClient().$extends({/* ... */})
const data = Prisma.validator(prisma, 'user', 'findFirst', 'select')({
id: true,
})
query
callbacks for $queryRaw
and $executeRaw
will always receive Sql
instance as args
. This instance can be used to compose a new query using Prisma.sql
:
const prisma = new PrismaClient().$extends({
query: {
$queryRaw({ args, query }) {
return query(Prisma.sql`START TRANSACTION; ${args}; COMMIT;`)
}
}
})
$on
cannot be called after extending Prisma Client. Therefore, if you want to use event handlers together with extensions, we recommend using the $on
method before $extends
.
const prisma = new PrismaClient()
.$on(/* ... */)
.$extends({/* ... */})
We updated the import path for utilities used for authoring extension to @prisma/client/extension
rather than @prisma/client
+ import { Prisma } from "@prisma/client/extension"
- import { Prisma } from "@prisma/client"
We also took this opportunity to deprecate Prisma Clientās middleware. We recommend using to using Prisma Client query
extension components which can be used to achieve the same functionality and with better type safety.
š§ Middleware will still be available in Prisma Clientās API. However, we recommend using Prisma Client extensions over middleware.
Starting with this release, weāre excited to announce that orderByNulls
is now Generally Available! This means you can use the feature without the orderByNulls
Preview feature flag.š
We introduced this feature in 4.1.0 to enable you to sort records with null fields to either appear at the beginning or end of the result.
The following example query sorts posts by updatedAt
, with records having a null value at the end of the list:
await prisma.post.findMany({
orderBy: {
updatedAt: { sort: 'asc', nulls: 'last' },
},
})
To learn more about this feature, refer to our documentation.
Weāre excited to see what you will build! Feel free to share with us what you build on Twitter, Slack, or Discord.
This release moves the filteredRelationCount
Preview feature to General Availability! This means you can use the feature without the filteredRelationCount
Preview feature flag.
We first introduced this feature in 4.3.0 to add the ability to count by filtered relations.
The following query, for example, counts all posts with the title āHello!ā:
await prisma.user.findMany({
select: {
_count: {
select: {
posts: { where: { title: 'Hello!' } },
},
},
},
})
To learn more about this feature, refer to our documentation.
In the last two releases, 4.13.0 and 4.14.0, we added 9 introspection warnings. These warnings surface features in use in your database that cannot currently be represented in the Prisma schema.
In this release, weāre adding one more introspection warning to the list: expression indexes.
On database introspection, the Prisma CLI will surface the feature with a warning, and a comment in your Prisma schema for sections for each feature in use. The warnings will also contain instructions for workarounds on how to use the feature.
select
'd explicitly. prisma generate
when running it directly after installing prisma
$runCommandRaw
is not passing the expected data to middleware or client extension.prismaVersion.client
available on "@prisma/client/scripts/default-index"distinct
fieldPrisma.validator
clientExtensions
GA $queryRawUnsafe
also triggers $allModels.$allOperations
$on
applied to an extended client is also bound to the parent client$queryRaw*
is broken in interactive transactions together with clientExtensions
in 4.16.0-dev.17
type
sprisma db pull
gets rid of @default(uuid())
on re-introspectionLearn about the latest release and other news from the Prisma community by joining us for another "What's new in Prisma" live stream.
The stream takes place on YouTube on Thursday, June 22 at 5 pm Berlin | 8 am San Francisco.