2.11.0
Today, we are excited to share the 2.11.0 stable release 🎉
🌟 Help us spread the word about Prisma by starring the repo ☝️ or tweeting about the release.
Major Improvements
Native database types in the Prisma schema (Preview)
We are super excited to share that this release brings you one of the most requested features since we released the initial version of Prisma: The representation of native database types in the Prisma schema.
Up to this release, the Prisma schema only allowed to represent a limited set of types: String, Int, Float, Boolean, DateTime, Json. Each of these types has a default mapping to an underlying database type that's specified for each connector (see the mappings for PostgreSQL and MySQL).
With this release, you can now add an attribute to a field definition in order to determine which specific database type it should be mapped to. Here is an example for a PostgreSQL database that specifies the underlying database types more specifically. Note that you also need to enable the feature via the the nativeTypes feature flag:
generator client {
provider = "prisma-client-js"
previewFeatures = ["nativeTypes"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
name String? @db.VarChar(255)
}
model Post {
id Int @id @default(autoincrement())
title String @db.VarChar(100)
createdAt DateTime @db.Timestamp(6)
wordCount Int @db.SmallInt
}In the above code snippet, all fields of the two Prisma models are annotated with attributes to diverge from the default mapping and determine the exact type that is used in the underlying database. For example, the id fields are represented as db.BigInt which maps to the BIGINT PostgreSQL type. You can find out more about which Prisma types can be annotated with which native type attributes in the docs for the PostgreSQL and MySQL connectors.
Note: Native types don't work with Prisma Migrate yet. For the time being, you still need to configure the type manually in your database and pull it into your schema via introspection.
Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue here).
📚 Documentation: Extended native type support
New types in the Prisma schema: BigInt, Bytes and Decimal (Preview)
With this release, we are further introducing three new scalar types in the Prisma schema: BigInt, Bytes and Decimal. Here is an overview for how they map to the different databases that are supported by Prisma and how they're represented when queried with Prisma Client JS:
| Prisma | PostgreSQL | MySQL | SQLite | JavaScript / TypeScript |
|---|---|---|---|---|
Bytes |
BYTEA |
LONGBLOB |
n/a | Buffer |
Decimal |
DECIMAL(65,30) |
DECIMAL(65,30) |
n/a | Decimal.js |
BigInt |
BIGINT |
BIGINT |
n/a | BigInt |
To make use of these new types, you need to enable the nativeTypes feature flag in your Prisma schema:
generator client {
provider = "prisma-client-js"
+ previewFeatures = ["nativeTypes"]
}Once you added the feature flag, be sure to run prisma generate again to update your local version of Prisma Client.
📚 Documentation: Prisma types in the nativeTypes preview
Set foreign keys directly (Preview)
We now support writing foreign keys (also known as relation scalars) directly with the uncheckedScalarInputs preview feature.
Consider this sample Prisma schema:
generator client {
provider = "prisma-client-js"
previewFeatures = ["uncheckedScalarInputs"]
}
model User {
id Int @id @default(autoincrement())
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
authorId Int
author User @relation(fields: [authorId], references: [id])
}Instead of using connect when creating a new Post record to wire up a relation with a User record, you can now directly set the authorId value:
await prisma.post.create({
data: {
// You can now set the foreign key directly...
authorId: 1,
// ... or connect the relationship...
// author: {
// connect: {
// id: 1
// }
// }
// ... but not both at the same time
},
});We'd love for you to give it a try. You can give us feedback in this issue.
The $transaction API is now stable
You can now use $transaction API without the transactionApi feature flag.
generator client {
provider = "prisma-client-js"
- previewFeatures = ["transactionApi"]
}The connectOrCreate API is now stable
The connectOrCreate API offers a convenient way to link or insert nested records.
You can now use it without the connectOrCreate feature flag.
generator client {
provider = "prisma-client-js"
- previewFeatures = ["connectOrCreate"]
}Middleware model parameter is now typed
This is a small quality-of-life improvement for developers using the Prisma middleware. The params.model parameter that's passed into a middleware function is now typed to your model so you can now reliably tie middleware to models:
prisma.$use(async (params, next) => {
switch (params.model) {
case 'user':
// ...
case 'project:
// ...
}
})If you need the old behavior you can cast params.model back to a string by wrapping it String(params.model).
📚 Documentation: Middleware
Deprecation of multi-provider array
You will now see a warning if you have multiple providers in your datasource. We recently realized that supporting an array of providers in the Prisma schema was premature, adding complexity in the process of improving the product, and causing some confusion about our intent.
You can read more about the decision and what to do about it in this issue.
Validate PrismaClient inputs at runtime
We now validate the parameters we accept in new PrismaClient(parameters). This is unlikely to affect you unless you were passing invalid parameters into PrismaClient before.
Prisma Client Go is now Early Access 🎉
We're happy to announce that Prisma Client Go has graduated from experimental to Early Access.
You can get started here. We'd love to learn more about how you use the Go Client during Early Access. You can schedule a call with us or chat with us on Slack in the #prisma-client-go channel. We're looking forward to hearing from you!
📺 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, November 12 at 5pm Berlin | 8am San Francisco.
👀 Make your online talk recordings more accessible with subtitles
We'd love to help you make your talk recordings (no matter if Meetup or conference talk) more accessible by adding subtitles to it for free! Reach out to [email protected] if you are interested in getting subtitles for your videos!
Fixes and improvements
prisma
- Can't create a record with only the foreign key to another table
- Foreign key field is not being set when using a nested create for a one-to-one relation
- Prisma Client is unable to fetch DateTime lists
- Middleware params model should be an enum or union of strings.
- vercel/pkg broken on windows
- vercel/pkg errors on windows
- Introspection fails instantly MariaDB
- DATABASE_URL verification still attempted when datasource override provided in PrismaClient constructor
- Introspection should try to preserve custom Enum names on MySQL even without @map
- Mutliple 1-n self relations break migrations
- .transaction([]) fails with Request Timeout Error on large dataset
- JSON value truncate floating numbers
- Postgresql: Large double precision float values cause panic
- Error in prisma results in unhandled promise rejection
- Consolidate Undici error handling
- Internal: update our
pnpmversion used for development and CI - Internal: Create new milestone check GitHub Action
- Prisma and Netlify, binary is not downloaded automatically since 2.8.0
- Detect and enforce Node Version in
preinstallhook so pnpm fails clearly - Package name reuse (.prisma/client) when generating multiple prisma clients causes issues with some other libraries (e.g. jest)
- Native Types: @db.BigInt should be BigInt
- Prisma generate or introspect don't work when nativeTypes preview is enabled
- Cannot update a model with composite keys through a referenced model
- RangeError: Invalid count value during create
- Prisma Client doesn't load root .env
- You are trying to load env variables which are already present in your project root .env
- Stabilize connectOrCreate
- Stabilize transactionApi
- Add integration test to trigger env var warning in Prisma Client
- Improve error when using prisma migrate --experimental with native types
prisma-client-js
language-tools
- Add Prisma icon to standard icon theme in VSCode
- Gitpod Support
- prisma.plugin.nextjs.addTypesOnSave broken
studio
- Unable to view / edit DateTime lists
- Case insensitive searching
- npx prisma studio doesn't work on WSL 1
- Cannot type "." in a float column
- Websockets fails when studio is behind a reverse proxy
- [design] Cell overflow