Title

Question

Is there a way to filter by null in Prisma1?

Answer

To filter by not null, you can wrap the field in `not: {}` like `{ where: { not: { endedAt: null } }`. To filter by null specifically, you can use `{ where: { endedAt: null } }`. If you are using `prisma-binding`, you can call `db.post.findMany({where:{category: {not: null}}})`.

s

Shehab

04/28/2020, 12:46 AM
Is there a way to query my db where a field is not null? like db.post.findMany({where:{category: !null}}) or something?
a

Alex Vilchis

04/28/2020, 1:17 AM
Wrap it in
not: {}
o

Oliver Evans

04/28/2020, 1:21 AM
i.e.
db.post.findMany({where:{category: {not: null}}})
s

Shehab

04/28/2020, 1:37 AM
Great thanks!
j

Joseph

04/28/2020, 5:59 AM
Lol, just asked the same question. Where is the
findMany
function coming from?
const existingMatches = await prisma.query.matches(
  {
    where: { endedAt: { not: null } },
  },
  info,
)
This throws an error:
GraphQL error: Variable '$_v0_where' expected value of type 'MatchWhereInput' but got: {"endedAt":{"not":null}}. Reason: 'endedAt' Date value expected
a

Anton Pokhylenko

04/28/2020, 6:09 AM
try
{ where: { not: { endedAt: null } }
j

Joseph

04/28/2020, 6:14 AM
Same issue, I'm guessing I need to do something like
NOT: []
if I needed where it's not null. My issue is I can't filter by
null
at all
I'm using
prisma
from
prisma-binding
, passed in through the context in the resolver. Perhaps the issue is that I'm not using
db
, but i'm also not sure where that's coming from
r

Ryan

04/28/2020, 11:11 AM
Hey @Joseph 👋 Are you using Prisma1?
j

Joseph

04/28/2020, 3:49 PM
Hey @Ryan, sure am 🙂
@Ryan Is there a way to filter by null in Prisma1?