advanced filters
// filter operation
{
where: {
name: 'abbas',
name: { equals: 'abbas' },
name: { not: 'abbas' },
name: { in: ['abbas'. 'ali'] },
name: { notIn: ['abbas'. 'ali'] },
name: { contains: '@test.com' },
name: { startWith: '@test.com' },
name: { endWith: '@test.com' },
age: { lt: 20 },
age: { gt: 20 },
age: { lte: 20 },
age: { gte: 20 },
}
}
// condation filtring
{
where: {
AND: [
{ name: { startWith: '@test.com' } },
{ name: { endWith: '@test.com' } }
],
OR: [
{ name: { startWith: '@test.com' } },
{ age: { gt: 20 } }
],
NOT: { name: { startWith: '@test.com' } },
}
}
filter depend on fields of relation
// One-to-Many
// Many-to-many
const users = await prisma.user.findMany({
where: {
// find users where userPrefs.reciveEmails equal true
userPrefs: {
reciveEmails: true
}
// or like this which mean, find useres with every userPrefs match
userPrefs: {
// every, some, none
every: {
// AND, OR, NOT apply here
title: 'call prefs'
}
}
}
})
// Many-to-One
// One-to-One
const posts = await prisma.post.findMany({
where: {
// find posts which thier authors age is 27
author: {
// is, isNot
is: { age: 27 }
}
}
})