2.5.0
Today we are excited to share the 2.5.0 stable release.
馃専 Help us spread the word about Prisma by starring the repo 鈽濓笍, tweeting about the release or sharing your experience with Prisma on Reddit. 馃専
Major improvements
Middlewares, removing duplicates with distinct and aggregations are now stable
After running in preview mode for a number of releases, we are excited to promote the following features into this stable release:
middlewaresdistinctaggregateApi
This means you can omit the respective feature flags in the generator block in your Prisma schema:
generator client {
provider = "prisma-client-js"
- previewFeatures = ["middlewares", "distinct", "aggregateApi"]
}Read on to learn about each feature individually!
Middlewares
Prisma Client's middleware lets you intercept Prisma Client queries to manipulate its parameters and interrogate its result. A middleware is a function that's passed to Prisma Client's $use method.
Middlewares are convenient for a number of use cases, for example:
- Logging the time taken to perform a type of query
- Manipulating or validating query parameters
- Contacting another service upon specific queries
The following example includes two middlewares:
const prisma = new PrismaClient()
prisma.$use(async (params, next) => {
const result = next(params);
return result;
}
prisma.$use(async (params, next) => {
return next(params);
}馃摎 Documentation: Middleware
Remove duplicates from query results with distinct
Prisma Client allows you to filter duplicate rows from the response to a findMany query using the distinct option:
const distinctCities = await prisma.user.findMany({
select: {
city: true,
country: true,
},
distinct: ["city"],
});馃摎 Documentation: Distinct
Aggregations with aggregate
Prisma Client allows you to perform aggregations operations on the number fields (such as Int and Float) of a model - for example, you can get the average age of all users:
const aggregations = await prisma.user.aggregate({
avg: {
age: true,
},
});
console.log("Average age:" + aggregations.avg.age);Prisma Client supports the following aggregations:
avg(average)sum(sum)min(minimum value)max(maximum value)
馃摎 Documentation: Aggregations
Preview features
New: Case insensitive filters (PostgreSQL only)
In 2.5.0 we introduce case insensitive filters for querying capabilities to Prisma Client. It allows you to query for fields in a case insensitive way.
Note: This feature will not work if you're using database collations that do not know how to convert between upper- and lowercase letters (e.g. the
Ccollation).
馃摎 Documentation: Case sensitivity / Case-sensitive filtering
Feature flag
Insensitive filters querying needs to be enabled with the feature flag insensitiveFilters like so:
generator client {
provider = "prisma-client-js"
previewFeatures = ["insensitiveFilters"]
}Usage
The new mode option you can pass to findMany influences the corresponding filter (e.g. contains or startsWith) but doesn't change the return type of the findMany query. mode can have two possible values:
default: Uses the default filter configured on the database level. If the collation is configured as case insensitive in the database, the default mode will be case insensitive as well. In that case, there's no need to use theinsensitivemode.insensitive: Uses the case insensitive filter (if possible).
const result = await prisma.user.findMany({
where: {
email: {
equals: 'lowercase@UPPERCASE.com',
mode: 'insensitive',
},
},
})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).
Feature flags for middlewares, distinct and aggregationApi removed
As mentioned above, we were able to promote three features into this stable release. This was thanks to your help and feedback, so please keep trying the preview features if they're useful to you and help us by sharing feedback.
Already existing preview features from 2.1.0
Just a quick reminder:
- In version
2.1.0we introduced two experimental features, namelyconnectOrCreateandtransactionApi.
In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.
馃専 Help us spread the word about Prisma
To help spread the word about Prisma, we'd very much appreciate if you would star this repo 馃専 And if you're excited about the features in this week's release, then help us and share it on Twitter.
Fixes and improvements
prisma
- @default(autoincrement()) not working on non id integer fields
- thread 'main' panicked at 'called
Option::unwrap()on aNonevalue', libs/datamodel/core/src/validator/validate.rs:178:29 - Improve update notifier message
- Introspect not creating unique relation names
- EPIC: Provide binaries for FreeBSD 12
- Internal: trigger e2e tests for patch branches
npx prisma introspecterrors with[libs/sql-schema-describer/src/mysql.rs:353:27] column_nameon indexes using expressions (MySQL 8.0.13+)- Switch Client to use Unix Domain Sockets
- Add a few sanity tests for Studio in the CLI pipeline
- Output Studio package version in
prisma -v - Suggested CLI commands are missing
npxprefix when being triggered vianpx prismaitself - Internal: Move
Studiocommand intoclipackage Transactionis still a reserved word in 2.4.1- Fluent API chaining seems to be broken as of 2.3.0
- Error: [libs\datamodel\core\src\dml\datamodel.rs:166:9] Every RelationInfo should have a complementary RelationInfo on the opposite relation field.
- Implement deprecation notice of removed preview feature flags in Client
prisma-client-js
migrate
- migrate save and up always recreate the db
- Migration fails after changing ENUM
- On failure _new tables/types are left
- Error: Failure during a migration command: Connector error. (error: Error querying the database: Error querying the database: db error: ERROR: type "MembershipRole" already exists
- Error while using prisma migrate init: The above error occurred in the component:
- Invalid connection string not handled gracefully
- Getting error in prisma migrate save --experimental command
language-tools
- Add lint support for no env vars in provider field
- vscodium marketplace availability
- Publish to open-vsx.org
- 2.4.0 breaks extension
- Renaming prisma.schema model
studio
- [feature] Group action button with other buttons
- Cache error
- Column titles overflow on the next column when too long
- Bring back row selection checkboxes
- Improvements to relation pills
- Field level filters for the relation accordion
- Prisma Client errors are not propagated correctly
prisma-engines
- Create CONTRIBUTING.MD
- Validate that there is only one @default(autoincrement()) per table, on an indexed column on MySQL
- Implement missing unexecutable migration warnings
- Validation: default values on enum fields should be valid for the enum
- Switch GH Actions trigger from
repository_dispatchtoworkflow_dispatchto enable running branches - Add error code for invalid schema.prisma for reintrospection