nikolasburk
_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: '<mailto:alice@prisma.io|alice@prisma.io>',
  name: 'Alice',
  _count: { posts: 2 }
}
You can enable this feature 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.
⚡️ Reducing the communication overhead between the Node.js and Rust layers with N-API (Preview)
N-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 N-API will not affect your workflows in any way, the experience of using Prisma will remain exactly the same. The N-API has different runtime characteristics than the current communication layer between Node.js and Rust. These are likely (but not certain) to result in a positive effect on the performance of your application. 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"] // can be removed now
 }
🦦 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)