Alex Ruheni
3.10.0
prisma rainbow
We are working towards a stable release of MongoDB and are shipping lots of improvements. All the major features and breaking changes in this release therefore only apply to the MongoDB connector. Take a closer look if you are using the Preview of MongoDB as some of the changes are breaking.
๐ Embedded documents support is now in preview
Weโre super excited to announce that Prisma version 3.10.0
supports reading and modifying embedded documents. Embedded documents will provide access to a new type
keyword in your Prisma schema that you can use to define composite types.
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
name String
photos Photo[]
}
type Photo {
height Int
width Int
url String
}
Given the schema above, you can now read and write to the embedded photos
array:
// Create a new product with an embedded list of photos
const product = await prisma.product.create({
data: {
name: "Forest Runners",
price: 59.99,
// Create an embedded list of photos in the product
photos: [
{ height: 100, width: 200, url: "1.jpg" },
{ height: 300, width: 400, url: "2.jpg" },
],
},
})
You can read further in our documentation. Feel free to open an issue if you run into anything, and weโll give you a hand!
๐ Introspection of embedded documents is now enabled by default
We added Preview support for embedded documents in version 3.4.0
and are now activating it for all users. Running prisma db pull
against your MongoDB database will generate type
definitions within your Prisma schema. When introspecting your database, you can switch off the depth with -composite-type-depth=0
, or limit it with, for example, --composite-type-depth=2
.
Feel free to drop your feedback on the feature on GitHub.
๐จ @default(dbgenerated())
is now replaced with @default(auto())
The original purpose of dbgenerated
is to support SQL expressions Prisma doesnโt understand yet. However, MongoDB doesnโt have a concept of default value expressions like SQL does. We took this opportunity to simplify handling the default values in MongoDB.
๐จ Many-to-Many relations now require a references
argument
Prisma version 3.10.0
now enforces all arguments in a MongoDB many-to-many relation. This means a @relation
attribute must define fields
and references
arguments on both sides. The fields
argument must point to a scalar field in the same model, and this scalar field must be an array. The references
arguments must point to a scalar field in the opposite model, and it must be a singular type of the same base type as the referencing array on the other side.
model Post {
id String @id @map("_id") @default(auto()) @db.ObjectId
category_ids String[] @db.ObjectId
categories Category[] @relation(fields: [category_ids], references: [id])
}
model Category {
id String @id @map("_id") @default(auto()) @db.ObjectId
post_ids String[] @db.ObjectId
posts Post[] @relation(fields: [post_ids], references: [id])
}
๐จ db.Array(ObjectId)
is now updated to @db.ObjectId
The original purpose of dbgenerated
is to support SQL expressions Prisma doesnโt understand yet. However, MongoDB doesnโt have a concept of default value expressions like SQL does. We took this opportunity to simplify how we handle the default values in MongoDB.
๐ Learn more in the release notes
For more info and links to documentation, you can read the release notes.
๐ Help us spread the word about Prisma ๐
To help spread the word about Prisma, weโd very much appreciate it if you would star the repo ๐ And if youโre excited about the features in this weekโs release, then help us and share your excitement on Twitter.
๐ฐ Join us on Thursday for the โWhatโs new in Prismaโ livestream
This week, @Austin and I will discuss the latest release and other news from the Prisma ecosystem in a this Thursday at 5 pm Berlin | 8 am San Francisco.