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
- Command to export SQL schema
- Waiting "too long" to input migration name leads to error message
db push
with emptyschema.prisma
:Error: TypeError: Cannot read properties of undefined (reading 'url')
- migrate diff: --{from,to}-schema-datamodel should not error on missing env vars in datasource blocks
- migrate diff: Provide a reliable way to detect empty diffs / migrations
db execute
cannot resolve SQLite file path from schema- [MDB] Implement version and describe RPC calls for the error reporting backend
- [MDB] Create fields referenced in index definitions as Json to enable display of indexes in datamodel
- MongoDB many to many:
PANIC: called Option::unwrap() on a None
Prisma Client
- PANIC in query-engine/connectors/mongodb-query-connector/src/value.rs:185:24not yet implemented: (Json, Json("[]"))
- Prisma Mongo Panic called
Option::unwrap()
on aNone
value - Better error message for MongoDB replica sets
- MongoDB: Using
tlsCAFile
fails - no such file or directory, open '/path/schema.prisma' since 3.1.1
- PANIC: called
Option::unwrap()
on aNone
value in query-engine/connectors/mongodb-query-connector/src/root_queries/write.rs:301:74 contains
string filter not working with mongoDB- Referential integrity is not preserved when updating foreign key (in "prisma" mode)
- PANIC: called
Option::unwrap()
on aNone
value in query-engine\connectors\mongodb-query-connector\src\root_queries\read.rs:112:74 - HasReject not evaluating correctly for per operation handlers
- Support MongoDB "query" logging
- CONTRIBUTING: document Prisma Client workflow of using local link
- MongoDB findRaw filter problem with ObjectId field.
- MongoDB: Better error message for when document does not match the defined schema
- Integrate orderBy for composite types
- Attempting to do a query in the Prisma Client on a model with a foreign key that has
@map
panics on 3.10.0 - Use embedded documents attributes in where clause
'then' in PrimsaPromise
returns false
Prisma Migrate
Language tools (e.g. VS Code)
- MongoDB M:N relations get referential actions auto completion suggestions, then does not validate
- Auto Completion:
map
does not exist for M:N in MongoDB - Autocomplete shows invalid suggestions for composite types
- Suggest auto() in VSCode autocomplete
- Clicking on a MongoDB composite type does not jump to definition
Prisma Engines
- Implement order by composites
- [Composites] Implement
equals
read operation - [Composites] Implement
is
read operation - [Composites] Implement
isNot
read operation - [Composites] Implement
isEmpty
read operation - [Composites] Implement
every
read operation - [Composites] Implement
some
read operation - [Composites] Implement
none
read operation
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.