Hey folks, I have User model with nullable “name” ...
# orm-help
p
Hey folks, I have User model with nullable “name” How to query for Users that defined their names?
Copy code
const users = await prisma.users.findMany({
    where: {
      name: // not null
    }
  })
r
@Patrick 👋 This should work:
Copy code
await prisma.user.findMany({ where: { name: { not: null } } })
Using
ctrl+space
inside the
name
block should give you all the supported operators 🙂
p
Hey Ryan, I tried that, however TypeScript says that name can be still string or null, despite
{ not: null }
Is this expected?
r
I didn’t quite get your point. Using
{ not: null }
will execute the SQL query
is not null
, which is exactly what you require.
p
I thought that prisma will be smart enough, so I don’t need to have this additional if statement here:
r
The types are generated based on the model. I would be impossible to generate types based on wha was passed in
where
.
I can’t think of any ORM that would do this as
where
could be highly dynamic.
p
Gotcha. That makes sense. Thanks
👍 1