nikolasburk
findFirst
to query a single item with the same filters from findMany
While the findMany
API gives you a powerful API to query your database with various filters, it's not ideal if you just want to query a single item. On the other hand, the findOne
API returns single items, but it only allows for filtering by unique fields.
In version 2.8.0
, we're introducing findFirst
- giving you the full power of findMany
filters while only returning the first item that matches the filter criteria.
So instead of this:
const usersCalledAlice = await prisma.user.findMany({
name: "Alice"
})
const firstUserCalledAlice = usersCalledAlice[0]
You can now do this:
const firstUserCalledAlice = await prisma.user.findFirst({
name: "Alice"
})
🔎 Case insensitive filters for PostgreSQL promoted to stable
In 2.5.0
we introduced case insensitive filters for PostgreSQL, in today's release we're promoting this feature to stable. This means you don't need to include the insensitiveFilters
feature flag in the previewFeatures
field of the Prisma Client generator any more.
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 the insensitive
mode.
• `insensitive`: Uses the case insensitive filter (if possible).
const result = await prisma.user.findMany({
where: {
email: {
equals: '<mailto:lowercase@UPPERCASE.com|lowercase@UPPERCASE.com>',
mode: 'insensitive',
},
},
})
You can learn more about this feature in the docs.
❓ Are you using Prisma at work?
We'd love to know if you're using Prisma at work. Answer with a quick yes or no in our poll, it won't take longer than a few seconds!
📚 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 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.