Releases: prisma/prisma
5.3.1
Today, we are issuing the 5.3.1
patch release.
Fix in Prisma Client
5.3.0
🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟
Highlights
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!
Improvements and bug fixes
We made the following changes:
Prisma Client improvements
- Validation for
undefined
values in arrays inJson
fields
We added runtime validation forundefined
values in arrays inJson
fields. Prisma Client will now return an error when an array contains anundefined
value. Therefore, we encourage you to add validation that either removes the value or transforms it tonull
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
- Performance improvements for models with many unique fields: 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. - Fixed the segmentation fault error that used to occur on ARM64 Linux binary targets
- Metrics Preview feature improvements:
- We updated the counters and gauge properties
- We fixed the bug that caused the
prisma_pool_connections_open
metric to have a negative value in some cases.
Prisma Migrate improvements
- Fixed an introspection bug for MongoDB views. Previously, if a MongoDB database contained a view,
prisma db pull
would throw an error. We resolved this, and views are now ignored. - Added the
PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK
environment variable that enables you to disable advisory locking.
VS Code extension improvements
- Added support for rendering multi-line comments in tooltips when hovering on a block.
- Improved the auto-completion for composite types in other blocks.
- Added a Code Action that allows you to replace
SetDefault
withNoAction
when using MySQL and the default/foreignKeys
relation mode.
Fixes and improvements
Prisma Migrate
- Percona-XtraDB-Cluster prohibits use of GET_LOCK with pxc_strict_mode = ENFORCING
- MongoDB views should be ignored introspecting the database
- Error in Connector on MongoDB executing listIndex: "system.views"
prisma migrate deploy
:MariaDB doesn't yet support 'GET_LOCK in cluster (WSREP_ON=ON)'
Prisma Client
- Remove all special cases for Data Proxy in our tests
- Segmentation fault on ARM64 Linux
- In the metrics feature a gauge & counter are swapped
- The prisma metrics
prisma_pool_connections_open
has a bug where it goes negative - Prisma crashes with GraphQL queries of nested one-to-many relationship
- P1017 Server has closed the connection on linux_arm64
Error: socket hang up
on Linux/arm64- Panic in Query Engine with SIGABRT signal (Debian Bookworm, engineType = binary)
- Prisma 5 drops
undefined
from Arrays when using Json fields with Postgres - Suspected memory leak in Lambda function after upgrading from 4.10.1
- Error when generating - No unsupported field should reach that path
Language tools (e.g. VS Code)
- Models with multi line comments only show last line in tooltip
- Add VS Code quick fix / code action to replace
SetDefault
withNoAction
whenprovider = "mysql"
andrelationMode = "foreignKeys" | default
- Composite Types aren't offered as being auto-completable in other blocks
Credits
Huge thanks to @alencardc, @Oreilles, @christianledgard, @skyzh, @alula, @michaelpoellath, @RobertCraigie, @stephenwade for helping!
5.2.0
🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟
Highlights
Improved Prisma Client experience for Prisma Accelerate and Data Proxy
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.
Simplified connection string override in Prisma Client
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",
})
Query performance improvements
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.
Use LIMIT
in one-to-many relations on a single parent
In 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.
Further improvements for nested writes
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.
Prisma Client query
await prisma.post.update({
where: { id: 1 },
data: {
comment: {
update: {
data: {
body: "Updated comment body"
}
}
}
},
select: {
id: true,
title: true,
}
})
Before v5.2.0
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
5.2.0 and later
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
Fixes and improvements
Prisma Client
- CFW: Avoid including Query Engine when data proxy is enabled
- Local Prisma Studio does not work with Data Proxy
- Postinstall hook always generates non Data Proxy Prisma Client
limit
is gone whenfindUnique
with include relationCannot 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 children- Prisma Client Edge: environment variables are not working with the "new" Module Worker syntax for Cloudflare Workers
- Add documentation to "PrismaClient is unable to be run in the browser"
- Change how Data Proxy Client deals with unsupported preview features
- Custom Prisma Client output location breaks Prisma Data Proxy in NextJS
- GetPayload type error since 4.16.1 "Two different types with this name exist, but they are unrelated."
- Browser bundle: Unhandled Runtime Error when upgrading to 5.1.0 from 5.0.0
- Prisma Client:
disconnect: true
does not appear to delete the foreign key in the returned data - Prisma Client errors with "TypeError: Cannot create proxy with a non-object as target or handler" when using result client extension with no
needs
andcount
method - Upgrading from Prisma 5.0.0 -> 5.1.0 results in "TS2321: Excessive stack depth comparing types" error using
mockDeep<PrismaClient>()
- Unnecessary reads for to-one nested updates
- Better error message if
@prisma/client/edge
can not find environment variable - 5.1: Alias for old name for
<Model>CountOutputTypeDefaultArgs
does not exist - Incorrect pagination for nested m2m chunked reads
Prisma Migrate
- RustPanic on
prisma generate
when Unsupported field defined in a Composite type - Use PostgreSQL System Information Functions instead of manually joining fields
- Duplicate expression index comment whenever db pull is run
Credits
Huge thanks to @skyzh, @alula, @michaelpoellath, @RobertCraigie, @darthmaim, @Gerschtli, @andyjy, @mejiaej, @iurylippo, @mrazauskas, @coder246, @RDIL for helping!
5.1.1
Today, we are issuing the 5.1.1
patch release.
Fixes in Prisma Client
- Browser bundle: Unhandled Runtime Error when upgrading to 5.1.0 from 5.0.0
- Prisma Client:
disconnect: true
does not appear to delete the foreign key in the returned data - Prisma Client errors with "TypeError: Cannot create proxy with a non-object as target or handler" when using result client extension with no
needs
andcount
method
5.1.0
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.
Highlights
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.
Community contributions
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:
- Fix IPv6 not working for relational databases: prisma/prisma-engines#4051 by @alula
- Middlewares: Add to
PrismaAction
type, missingfindUniqueOrThrow
andfindFirstOrThrow
#17471 by @mejiaej and missinggroupBy
#19985 by @iurylippo - Better error message in currently non-supported runtimes like Browser or Vercel Edge Runtime #20163 by @andyjy
- Remove error messages for valid NixOS setups #20138 by @Gerschtli
Better performance: Fewer SQL queries on PostgreSQL & CockroachDB
In 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:
Simple create
query
In a simple create
query, RETURNING
makes the second query and the transaction statements obsolete:
Prisma Client query
prisma.user.create({
data: { name: "Original name" }
})
Before v5.1.0
BEGIN
INSERT INTO "User" ("name") VALUES ($1) RETURNING "User"."id"
SELECT "User"."id", "User"."name" FROM "User" WHERE "User"."id" = $1;
COMMIT
5.1.0 and later
-- Sends 1 statement (instead of 2) and omits the transaction
INSERT INTO "User" ("name") VALUES ($1) RETURNING "User"."id", "User"."name"
Simple update
query
For a simple update
query, RETURNING
makes both additional queries and the transaction statements obsolete:
Prisma Client query
prisma.user.update({
where: { id: 1 },
data: { name: "updated" }
})
Before v5.1.0
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
5.1.0 and later
-- Sends 1 statement (instead of 3) and omits the transaction
UPDATE "User" SET name = 'updated' WHERE "User".id = 1 RETURNING "User".id, "User".name;
Simple update
query, return with relation value
One SELECT
query could easily be dropped in a simple update
query that should return a relation value as well:
Prisma Client query
prisma.user.update({
where: { id: 1 },
data: { name: "updated" },
includes: { posts: true }
})
Before v5.1.0
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
5.1.0 and later
-- 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
Empty update
query
An 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 Client query
prisma.user.update({
where: { id: 1 },
data: {},
})
Before v5.1.0
BEGIN
SELECT id, name FROM "User" WHERE "User".id = 1;
SELECT id, name FROM "User" WHERE "User".id = 1;
COMMIT
5.1.0 and later
-- Sends 1 statement (instead of 2) and omits the transaction
SELECT id, name FROM "User" WHERE "User".id = 1;
Simple + relation 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 Client query
prisma.user.update({
where: { id: 1 },
data: {
name: "updated",
posts: {
update: {
where: { id: 1 },
data: {
title: "updated"
}
}
}
}
})
Before v5.1.0
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
5.1.0 and later
-- 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!
Prisma Studio now supports 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.
Prisma Client: No more type clashes
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.
Fixes and improvements
Prisma Client
- Reduce the number of generated SQL statements for Updates/Inserts
- [v2.17.0] Missing client TS types Aggregate*Args
- Reduce transactions for writes
- Incorrect Include typings when having models called
X
andXUpdate
- Model named "Check" is incorrectly typed
- Models named Query cause an internal GraphQL Parse Error
- Naming an entity "Query" leads to an error
- Type name clash when
Model
andModelUpdate
is defined in the schema - Duplicate identifier 'CheckSelect'
@prisma/internals
(previously @prisma/sdk) uses deprecated dependenciesuuid@3.4.0
viatemp-write 4.0.0
- naming a model
Datasource
breaks generated return types - Certain
model
names cause clashes in generated types - Type error on query with select field (although query runs successfully)
$extends
TS error: "Inferred type of this node exceeds the maximum length the compiler will serialize" with"declaration": true
intsconfig
- Update operation includes multiple where statements for the same fields
- Type conflict when naming a table {something} and a second table {something}Result
Type '"findUniqueOrThrow"' is not assignable to type 'PrismaAction'
- Naming a model
Promise
breaks types forPrismaPromise
- Prisma can't connect with an IPv6 host (on e.g. Fly.io)
include
not working on models ending with...Update
with unique compound index- Prisma Client: fixing type name clashes from generated client
- [Prisma Client: wrong type when using spread operator to set default values on query args](https://github.com/prisma...
5.0.0
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. 🌟
Highlights
Here’s a summary of the changes:
- Preview features moved to General Availability
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 insidewhere
clauses for queries that operate on unique records.
- General improvements and breaking changes
- Dependency version changes
- Minimum Node.js version change to 16.13.0
- Minimum TypeScript version change to 4.7
- Minimum PostgreSQL version change to 9.6
- Prisma Client embedded SQLite version upgrade to 3.41.2
- Main Changes
- Removal of
rejectOnNotFound
property - Removal of some array shortcuts
cockroachdb
provider is now required when connecting to a CockroachDB database- Removed
runtime/index.js
from the generated Prisma Client
- Removal of
- Other Changes
- Removal of deprecated flags in the Prisma CLI
- Removal of the
beforeExit
hook from the library engine - Removal of deprecated
prisma2
executable - Removal of deprecated
experimentalFeatures
generator property in the Prisma schema - Renamed
migration-engine
toschema-engine
- Dependency version changes
A JSON-based protocol that improves Prisma’s performance
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.
Removal of array shortcuts
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
andnotIn
operator shortcuts- PostgreSQL JSON
path
field shortcut - Scalar list shortcuts
- MongoDB Composite types list shortcuts
Here’s an example query using the OR
operator shortcut for a single element;
await prisma.user.findMany({
where: {
- OR: { email: 'alice@prisma.io' }
+ OR: [{ email: 'alice@prisma.io' }]
}
})
We recommend taking a look at the upgrade guide to learn how you can update your queries to work in Prisma 5.
Support for comparing multiple columns
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.
Support for filtering non-unique columns in queries for a unique record
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.
Minimum Node.js version change to 16.13.0
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.
Minimum TypeScript version change to 4.7
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.
Minimum PostgreSQL version change to 9.6
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.
Prisma Client embedded SQLite version upgrade
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.
Removal of rejectOnNotFound
property
In 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:
- Replacing your queries with the
findFirstOrThrow
orfindUniqueOrThrow
methods if enabled at a query-level - Using a Prisma Client extension to overload the
findFirstOrThrow
andfindUniqueOrThrow
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 database
Prior 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.
Removal of the generated runtime/index.js
file from Prisma Client
With 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 C...
4.16.2
Today, we are issuing the 4.16.2
patch release.
Fixes in Prisma Client
- 4.16: (MongoDB) Generated types for list composites are incorrect
- Getting wrong types with prisma client extensions
- Prisma Client fluent API does not work with extends anymore on 4.16.1
- Prisma Client Extensions:
$allModels: { $allOperations }
sets query type tonever
- Result types are incorrectly inferred when
undefined
explicitly passed toselect
/include
4.16.1
Today, we are issuing the 4.16.1
patch release.
Fixes in Prisma Client
- Field references are not available on extended clients
- 4.16.x cannot wrap
$extend
in factory function whencompilerOptions.composite
istrue
- Prisma Schema Type inside a Type not generating a right Payload
- Query in findMany in prisma extends returns a wrong type
- 4.16.0 Count query is not returning the right type when in a transaction
- FindMany returns wrong type after extending prisma client
- Can't specify $queryRawUnsafe return type after extending prisma client
4.16.0
🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟
Highlights
This release promotes the following Preview features to General Availability:
- Prisma Client extensions
- Ordering by nulls first and last
- Count by filtered relation
Prisma Client extensions are Generally Available
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:
- Result extensions components: add custom fields and methods to query result objects, for example, virtual/computed fields.
- Model extensions components: enable you to add new methods to your models alongside existing model methods such as
findMany
. - Query extensions components: let you hook into the lifecycle of a query and perform side effects, modify query arguments, or modify the results in a type-safe way. These are an alternative to middleware that provide complete type safety and can be applied in an ad-hoc manner to different extensions.
- Client extensions components: allow you to add new top-level methods to Prisma Client. You can use this to extend Prisma Client with functionality that isn’t tied to specific models.
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.
More features and changes made to Client Extensions
We also made the following improvements to Prisma Client extensions in preparation for General Availability:
-
Added a top-level
$allOperations
method forquery
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 receiveSql
instance asargs
. This instance can be used to compose a new query usingPrisma.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"
Deprecating Middleware
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.
Ordering by nulls first and last is now Generally Available
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.
Count by filtered relation is now Generally Available
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.
Introspection warnings for expression indexes
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.
Fixes and improvements
Prisma Client
- Attach comments to enum values
- Extend Prisma Client
- Triple-slash Comments should attach to Composite Types
- Nested disconnect fails on MongoDB with extendedWhereUnique
- [ClientExtensions, TypeScript] Fields of custom type aren't available when using the ClientExtensions preview-feature, unless
select
'd explicitly. - Extensions incorrect typings generated (casing)
- Misleading error message of
prisma generate
when running it directly after installingprisma
- Prisma.validator: with clientExtensions enabled, Typescript can no longer compute types
- enum docstrings do not make it to the prisma client
- VScode behavior is very slow while using clientExtensions
- Client extensions in interactive transactions are bound to the base client
$runCommandRaw
is not passing the expected data to middleware or client extension- PCE: Improve runtime types in raw query extensions
- Sequential transactions run out of order when using client extensions and middleware
- Client Extension: Make
.prismaVersion.client
available on "@prisma/client/scripts/default-index" - [Cannot create record with Prisma.DbNull when clientExtensions enabled](https://github.com/prisma/prisma/issue...
4.15.0
🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟
Highlights
For this release, we focused on fixing bugs and making smaller quality-of-life improvements.
Support for custom arguments for prisma db seed
This release adds support for defining and passing arbitrary arguments to prisma db seed
. This creates the opportunity for you to define your own arguments in your seed file that you could pass to the prisma db seed
command. A few example use-cases include, but are not limited to:
- Seeding different data in different environments
- Partially seeding data in some tables
Here is an example seed.ts
file that defines custom arguments for seeding different data in different environments:
// prisma/seed.ts
import { parseArgs } from "node:util";
const options = {
environment: { type: 'string', },
}
async function main() {
const { values: { environment } } = parseArgs({ options })
switch (environment) {
case "development":
/** do something for development */
break;
case "test":
/** do something for test environment */
break;
default:
break;
}
}
main()
You can then provide the environment
argument when executing the seed script as follows:
npx prisma db seed -- --environment development
Let us know what you think, share example usage of this feature, and create a bug report if you run into any issues.
Improved error messages when Query Engine file is not found
This release improves the error messages returned by Prisma Client when the Query Engine file is not found. A few reasons the Query Engine file might be missing from your application bundle include when:
- The downloaded Query Engine doesn’t match the runtime/ target platform your application is running on.
- The Query Engine is not copied to your final application bundle during the build step.
We hope these error messages are helpful while debugging your application.
Prisma VS Code extension improvements
In this release, we made a few improvements to our VS Code extension:
-
Updated the file system watcher that is responsible for restarting the TypeScript server when
prisma generate
is run to ensure the types are in syncNote:
- This new approach is currently only available on Windows and Linux. We plan on adding support for the new file system watcher on macOS soon.
- This requires both Prisma CLI & VS code extension version
4.15.0
or higher
-
Added Quick Fixes action for unique identifiers for MongoDB to add the
@map("_id")
attribute function when it’s missing on an identifier fieldScreen.Recording.2023-05-17.at.19.22.20.mov
-
Support for renaming symbols for composite types and views
type-symbol-rename.mov
Fixes and improvements
Prisma Client
- Prisma generate -
Error: write EPIPE
on WSL <-> Windows prisma generate
is blocked byquery-engine-rhel-openssl-1.0.x
opening in Notepad on Windows- Generated client output path hardcoded to build environment
- Issue with Yarn Workspace Monorepo: Query engine binary for current platform could not be found.
- Cloning a project with checked in
node_modules
(from another platform) leads to platform engine not being present - SvelteKit, Vite and Prisma "module not defined"
- Schema File Not Found in non monorepo with custom
output
- Deploying to Cloudflare Workers | "PrismaClient is unable to be run in the browser"
- Inline/bundle the contents of the prisma schema on generate
- Netlify:
Query engine library for current platform "rhel-openssl-1.0.x" could not be found. You incorrectly pinned it to rhel-openssl-1.0.x
- Query Engine Library Not Found
- No client schema when using PrismaClient during cached (standard) Netlify build
- Module "@prisma/client" has no exported member "PrismaClient"
- EPERM: operation not permitted
- prisma/client crashes when used with older versions of react-refresh
- Unable to run prisma cli in pnpm monorepo from workspace install
- Misleading error message when the query engine is not found
- When setting custom client output directory, generated package.json does not include "sideEffects: false"
- You already added the platform "debian-openssl-1.1.x" to the "generator" block in the "schema.prisma" file as described in https://pris.ly/d/client-generator, but something went wrong.
- Prisma seems to be looking in the wrong location for rhel-openssl-1.0.x
- Can't find prisma engine
Cannot find name '$PrismaModel'
due to featureextendedWhereUnique
with preview featurefieldReference
- Netlify build fails with PrismaClientInitializationError
- i'm getting the error while requesting the api
- Query engine library for current platform could not be found.
- Prisma unable to reconnect if initial connection fails
- GraphQL protocol encoder incorrectly turns empty array into empty object.
- GraphQL protocol: Invalid
Date
values silently turn intonulls
- @prisma/client/edge + Cloudflare Worker / wrangler = Could not resolve "os"
- Client is bricked from connecting to DB if first attempt fails.
- JSON protocol: incorrect recursive composites detection through multiple nesting levels
fieldReference
is not working with enums
Prisma Migrate
- Pass extra arguments to
prisma db seed
to the seed command - Typo in generating migration SQL to add enum.
Language tools (e.g. VS Code)
- MongoDB: Quick fix for missing
@map("_id")
annotation - Rename composite types
- Views: Support for rename
- TextDocument deprecation
- Lib name change vsce -> @vscode/vsce
Credits
Huge thanks to @RobertCraigie, @KhooHaoYit, @art049, @luxaritas, @mrazauskas, @maxmartynov, @haneenmahd for helping!
📺 Join us for another "What's new in Prisma" live stream
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, June 1 at 5 pm Berlin | 8 am San Francisco.