Prisma: 3.11.0 Release

Release date:
March 15, 2022
Previous version:
3.10.0 (released February 22, 2022)
Magnitude:
1,260 Diff Delta
Contributors:
11 total committers
Data confidence:
Commits:

66 Commits in this Release

Ordered by the degree to which they evolved the repo in this version.

Authored March 11, 2022
Authored March 11, 2022
Authored March 14, 2022

Top Contributors in 3.11.0

millsp
Jolg42
janpio
prisma-bot
aqrln
codesee-maps[bot]
renovate-bot
hayes
do4gr
maddhruv

Directory Browser for 3.11.0

We haven't yet finished calculating and confirming the files and directories changed in this release. Please check back soon.

Release Notes Published

Today, we are excited to share the 3.11.0 stable release πŸŽ‰

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

Major improvements and new features

Experimental support for Embedded Document Filters

In the previous release, we added embedded document support for creates, updates, and deletes. In version 3.11.0, we’re adding the ability to filter embedded documents.

Given the following schema:

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["mongoDb"]
}

model Product {
  id     String  @id @default(auto()) @map("_id") @db.ObjectId
  photos Photo[]
}

model Order {
  id              String   @id @default(auto()) @map("_id") @db.ObjectId
  shippingAddress Address
  billingAddress  Address?
}

type Photo {
  height Int
  width  Int
  url    String
}

type Address {
  street String
  city   String
  zip    String
}

You can now filter within an embedded document:

// find all orders with the same shipping address
const orders = await prisma.order.findMany({
  where: {
    shipping: {
      equals: {
        street: "555 Candy Cane Lane",
        city: "Wonderland",
        zip: "52337",
      },  
    },
  },
})

You can also filter on a "contains many" relationship:

// find all products that don't have photos
const product = prisma.product.findMany({
  where: {
    photos: {
      isEmpty: true
    }
  },
})

This scratches the surface of what's possible. For a complete list of available operations, have a look at our documentation. Please share your feedback in this issue.

Ordering by embedded documents is in Preview

In addition to filtering, Prisma version 3.11.0 now supports sorting by an embedded document.

Using the example schema above, you can sort orders by their zip code:

// sort orders by zip code in ascending order
const orders = await prisma.order.findMany({
  orderBy: {
    shippingAddress: {
      zip: "asc",
    },
  },
})

Learn more about this feature in our documentation and don’t hesitate to reach out in this issue.

MongoDB query logging support

In this release, we’ve added the ability to log MongoDB queries. You can enable query logging in the PrismaClient constructor:

const prisma = new PrismaClient({
  log: [
    {
      emit: 'event',
      level: 'query',
    },
  ]
})

prisma.$on('query', (e) => console.log(e.query))

After enabling query logging, you'll start to see logs that resemble this in your console:

db.User.deleteMany({ _id: ( $in: [ β€œ62261e0b18139c6099ba7097”, ], }, }) 
db.User.deleteMany({ _id: ( $in: [ β€œ6226277a96069500743edcf9”, ], }, })

The logs output by Prisma have the same format as the mongosh console, so you can pipe the queries from your logs directly into your shell.

MongoDB introspection update

We've updated the type inference behavior for MongoDB on introspection.

Prisma samples a field's data to select an appropriate type on introspection. In the past, Prisma picked the type used most often for fields with data with multiple types. However, this could cause problems when retrieving mixed data during runtime and throw exceptions, such as Prisma Studio or in Prisma Client queries.

From 3.11.0, Prisma defaults to the Json type to all fields with mixed data types instead. Additionally, Prisma will still show a warning on the console and add a comment to the introspected Prisma schema so it is clear where such cases occur and that you can do something to fix them.

Prisma Client logger revamp

In 3.11.0, we’ve rewritten our internal logger to reduce lock contention and enable future features like tracing. This is the first of many upcoming changes to improve the Prisma Client’s throughput, so if you were running into an upper limit on query performance, it’s time to update Prisma Client and give it a try!

If you're running into query performance issues, please open an issue or connect with us on Slack.

CockroachDB now supports migrations (Preview)

We're excited to announce Preview support for migrations for CockroachDB. You can now evolve your Prisma schema and propagate the changes to your database using Prisma Migrate.

Give the feature a try and let us know what you think in this issue.

Detecting state of a diff with migrate diff using exit code

Prisma version 3.11.0 includes a new --exit-code flag to the migrate diff command to detect the state of a diff in several ways.

You can use the flag as follows:

npx prisma migrate diff --preview-feature \
--exit-code \
--from-[...] \
--to-[...]

Here's a list of the default and changed behavior of the error codes: ```

Default behavior of exit codes

0: Returned when the diff is empty or non-empty 1: Returned on error

Changed behavior when --exit-code is used

0: Returned when the diff is empty 1: Returned on error 2: Returned when the diff is non-empty ```

Read about it in the reference documentation.

Fixes and improvements

Prisma

Prisma Client

Prisma Migrate

Language tools (e.g. VS Code)

Prisma Engines

Credits

Huge thanks to @hayes, @maddhruv, @jasimon 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, March 17 at 5 pm Berlin | 8 am San Francisco.