You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today, we are excited to share the 2.23.0 stable release 🎉
🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟
Major improvements & new features
JSON Filtering is now in Preview
Starting today, you can now filter rows by data inside a Json type. JSON filtering support is available in PostgreSQL and MySQL. You can try it today by adding the filterJson preview flag to your generator block. This has been one of our most popular feature requests, so we're very excited to be getting it into your hands!
To get an idea of how JSON filtering works, let's see how you might query application logs stored in your database. Given the following Prisma schema:
We can now filter logs by the data inside the meta field. Let's query by the request_id inside the meta field to track the journey that led up to the error.
We can write the following query:
constlogs=awaitprisma.log.findMany({where: {meta: {// path looks for the request_id key inside metapath: ["request_id"],// and we select rows whose request_id is 10equals: 10,},},orderBy: {id: "asc",},});
Giving us the entire journey of this person's request:
Please note that the path syntax varies depending on the database. We pass the path query directly to the database, so there will be syntactical differences.
For example, querying by key in Postgres is request_id, while in MySQL it would be $.request_id. Please consult your database's documentation to learn more.
If you run into any questions or have any feedback, we're available in this issue.
Improvement for prisma db seed
In previous versions, a seed file could only be executed as a script. prisma db seed was simply executing the script by either calling node ./prisma/seed.js for JavaScript or ts-node ./prisma/seed.ts for TypeScript.
Now, you can directly export a function that Prisma executes on your behalf. Here's the rules that describe the new behavior: Prisma checks if the seed file has ...
... an exported function named seed and executes it
... an exported function (via a default export) and executes it
If there's no function exported as seed or via a default export, the behaviour of prisma db seed is exactly the same as before, meaning it will simply be executed as a script file.
Breaking changes
Options in groupBy queries are now prefixed with an underscore
The options in groupBy are now prefixed with an underscore, for example:
// API
const result = await prisma.user.groupBy({
by: ['name'],
- count: true,+ _count: true,
})
Here's an overview of the exact changes of each option:
Before 2.23.0
2.23.0 and later
count
_count
max
_max
min
_min
avg
_avg
sum
_sum
Note that this also changes the names of the fields in the objects that are returned by Prisma Client. For example, in the above case you now access the returned count value like so:
We made this change to avoid clashes with user-defined fields. You can learn more about the problem in these issues.
We're sorry for the inconvenience! If you have any questions or need any help, please reach out in this discussion.
Deprecations
Deprecating options in aggregate queries
With the changes to groupBy discussed above and recent features like orderBy an aggregate, we took this opportunity to unify min, max, avg, sum and count keywords across Prisma Client queries.
Similar tpo groupBy, this is the case for all of our aggregations:
Before 2.23.0
2.23.0 and later
count
_count
max
_max
min
_min
avg
_avg
sum
_sum
This is not a breaking change. The aggregate queries you wrote prior to 2.23.0 will continue to work as expected. We ask that you make adjustments when you can to future-proof your application.
If you have any questions or need any help, please reach out in this discussion.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Today, we are excited to share the
2.23.0stable release 🎉🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟
Major improvements & new features
JSON Filtering is now in Preview
Starting today, you can now filter rows by data inside a
Jsontype. JSON filtering support is available in PostgreSQL and MySQL. You can try it today by adding thefilterJsonpreview flag to yourgeneratorblock. This has been one of our most popular feature requests, so we're very excited to be getting it into your hands!To get an idea of how JSON filtering works, let's see how you might query application logs stored in your database. Given the following Prisma schema:
And the following records in your PostgreSQL database:
INFO{"host": "bob"}INFO{"host": "alice", "request_id": 10}INFO{"host": "alice", "amount": 20, "request_id": 10}ERROR{"host": "alice", "amount": 20, "request_id": 10}INFO{"host": "bob", "request_id": 1}INFO{"host": "alice"}INFO{"host": "bob", "email": "james@gmail.com", "request_id": 1}We can now filter logs by the data inside the
metafield. Let's query by therequest_idinside themetafield to track the journey that led up to the error.We can write the following query:
Giving us the entire journey of this person's request:
Please note that the
pathsyntax varies depending on the database. We pass thepathquery directly to the database, so there will be syntactical differences.For example, querying by key in Postgres is
request_id, while in MySQL it would be$.request_id. Please consult your database's documentation to learn more.If you run into any questions or have any feedback, we're available in this issue.
Improvement for
prisma db seedIn previous versions, a seed file could only be executed as a script.
prisma db seedwas simply executing the script by either callingnode ./prisma/seed.jsfor JavaScript orts-node ./prisma/seed.tsfor TypeScript.Now, you can directly export a function that Prisma executes on your behalf. Here's the rules that describe the new behavior: Prisma checks if the seed file has ...
seedand executes itIf there's no function exported as
seedor via a default export, the behaviour ofprisma db seedis exactly the same as before, meaning it will simply be executed as a script file.Breaking changes
Options in
groupByqueries are now prefixed with an underscoreThe options in
groupByare now prefixed with an underscore, for example:// API const result = await prisma.user.groupBy({ by: ['name'], - count: true, + _count: true, })Here's an overview of the exact changes of each option:
2.23.02.23.0and latercount_countmax_maxmin_minavg_avgsum_sumNote that this also changes the names of the fields in the objects that are returned by Prisma Client. For example, in the above case you now access the returned count value like so:
We made this change to avoid clashes with user-defined fields. You can learn more about the problem in these issues.
We're sorry for the inconvenience! If you have any questions or need any help, please reach out in this discussion.
Deprecations
Deprecating options in
aggregatequeriesWith the changes to
groupBydiscussed above and recent features like orderBy an aggregate, we took this opportunity to unifymin,max,avg,sumandcountkeywords across Prisma Client queries.const result = await prisma.user.aggregate({ - avg: { + _avg: { age: true, }, }) - result.avg + result._avgSimilar tpo
groupBy, this is the case for all of our aggregations:2.23.02.23.0and latercount_countmax_maxmin_minavg_avgsum_sumThis is not a breaking change. The aggregate queries you wrote prior to
2.23.0will continue to work as expected. We ask that you make adjustments when you can to future-proof your application.If you have any questions or need any help, please reach out in this discussion.
Fixes and improvements
Prisma Migrate
dbgenerated("gen_random_uuid()::TEXT")Option::unwrap()on aNonevalueError: Invalid data source URL, see https://www.prisma.io/docs/reference/database-reference/connection-urlsin 2.22.0Prisma Client
Prisma Studio
Prisma Engines
Credits
Huge thanks to @Sytten, @schiller-manuel, @mongolyy, @paularah, @Iamshankhadeep, @meeq 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, May 20 at 5pm Berlin | 8am San Francisco.
This discussion was created from the release 2.23.0.
All reactions