2.20.0
Today, we are excited to share the 2.20.0 stable release 🎉
🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟
Major improvements & new features
Count on relations (Preview)
This highly requested feature is now in Preview. You can now count the number of related records by passing _count to the select or include options and then specifying which relation counts should be included in the resulting objects via another select.
For example, counting the number of posts that an user has written:
const users = await prisma.user.findMany({
include: {
_count: {
select: { posts: true },
},
},
})The structure of the returned User objects is as follows:
{
id: 1,
email: 'alice@prisma.io',
name: 'Alice',
_count: { posts: 2 }
}You can enable this featrues with the selectRelationCount feature flag:
generator client {
provider = "prisma-client-js"
previewFeatures = ["selectRelationCount"]
}There may be some rough edges during the Preview period. If you run into any problems, you can reach us in this issue.
Node-API is now in Preview
Node-API is a new technique for binding Prisma's Rust-based query engine directly to Prisma Client. This reduces the communication overhead between the Node.js and Rust layers when resolving Prisma Client's database queries.
You can enable this feature with the napi feature flag:
generator client {
provider = "prisma-client-js"
previewFeatures = ["napi"]
}Enabling the Node-API will not affect your workflows in any way, the experience of using Prisma will remain exactly the same.
The Node-API has different runtime characteristics than the current communication layer between Node.js and Rust.
There may be some rough edges during the Preview period. If you run into any problems, you can reach us in this issue.
New push operation available for arrays on PostgreSQL
PostgreSQL supports array data structures (sometimes also called scalar lists). As an example, consider the permissions field on the following User model:
model User {
id Int @id @default(autoincrement())
permissions String[]
}As of this release, you can append a new item to existing lists atomically with the push command:
await prisma.user.update({
where: { id: 42 },
data: {
permission: {
push: "chat:read",
},
},
})Learn more in this issue.
groupBy and createMany are now Generally Available
For the pioneers among you, you can now remove the groupBy and createMany from your Preview features:
generator client {
provider = "prisma-client-js"
- previewFeatures = ["groupBy", "createMany"]
}Learn more in our documentation about groupBy and createMany.
Prisma Client Go now supports BigInt, Decimal and Bytes
Prisma Client Go continues to get more powerful every release. With this release, we've added support for more native database types: BigInt, Decimal and Bytes:
var views db.BigInt = 1
bytes := []byte("abc")
dec := decimal.NewFromFloat(1.23456789)
created, err := client.User.CreateOne(
db.User.Picture.Set(bytes),
db.User.Balance.Set(dec),
db.User.Views.Set(views),
).Exec(ctx)Breaking changes
The @prisma/cli package has reached its end of life
For all you holdovers, you've seen warnings like this for a couple months now:
warn @prisma/cli has been renamed to prisma.
Please uninstall @prisma/cli: npm remove @prisma/cli
And install prisma: npm i prisma
It's now time to upgrade. Follow the instructions and switch over to the new prisma package today:
npm
npm remove @prisma/cli
npm install -D prisma
Thanks to this change, running npx prisma will now always invoke the right Prisma CLI, no matter what your local setup looks like.
Yarn
yarn remove @prisma/cli
yarn add -D prisma
Upcoming breaking changes in the next version (2.21.0)
.aggregate will change to return null in 2.21.0
Subscribe to this issue for updates on how to prepare your code.
Fixes and improvements
Prisma Migrate
- Unclear Introspection error message: Error parsing attribute "@id": Fields that are marked as id must be required.
- [Introspection] Defaults set as expressions (as required in MySQL on some column types) not picked up
- Introspection: More information in
Schema is inconsistenterror message - prisma introspect overrides generator fields
- Tests: add tests for
prisma formatcli command - prisma migrate gives: Error querying the database: db error: ERROR: syntax error at or near "NOT"
- Introspection does not recognize Default Expressions
- Failing describer on MySQL with empty view definition
- Introspection failed: Getting definition from Resultrow ResultRow { columns: ["name", "definition"], values: [Text(Some("sp_helpdiagrams")), Text(None)] } as String failed
prisma migrateset field as unique automatically
Prisma Client
- Add a
pushmethod to scalar list update input in addition to set - $transaction doesn't roll back in NestJS when we pass method from external service
- when case-insensitive mode enabled in where clause, unnecessarily LOWER() function and ILIKE operator is used at the same time
- Invalid response data: the query result was required, but an empty Object((Weak)) was returned instead.
- regression: Running multiple findUnique's in parallel causes both to return null
- PANIC in query-engine/core/src/interpreter/query_interpreters/inmemory_record_processor.rs:111:80called
Result::unwrap()on anErrvalue: FieldNotFound { name: "origin", model: "Field not found in record Record { values: [Int(1011), String("https://woman.mynavi.jp/article/190924-7/")], parent_id: None }. Field names are: ["id", "link"], looking for: "origin"" } - Internal: Setup Renovate for https://github.com/prisma/engines-wrapper
- Rename
SKIP_GENERATEfrom Client postinstall script toPRISMA_SKIP_POSTINSTALL_GENERATE
Language tools (e.g. VS Code)
Security Fixes
We fixed two security issues:
- Command injection vulnerability in @prisma/sdk in getPackedPackage function
This is a low-severity issue and no users have been affected - Visual Studio Code Prisma Extension Remote Code Execution Vulnerability
This is a high-severity issue and we recommend all Prisma VS Code extension users verify that they have automatically been upgraded to the latest version. There is no evidence that this vulnerability has been exploited.
Big thanks to @erik-krogh (Erik Krogh Kristensen) and @Ry0taK for reporting these issues.
Credits
Huge thanks to @endor, @iBluemind, @matthewmueller, @paularah, @Iamshankhadeep for helping!
📺 Join us for another "What's new in Prisma" livestream
Learn about the latest release and other news from the Prisma community by joining us for another "What's new in Prisma" livestream.
The stream takes place on Youtube on Thursday, April 01 at 5pm Berlin | 8am San Francisco.