Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
12 replies
deforestor

Confused on Prisma's where clause: OR and AND

I'm trying to write a query that queries the repositories that aren't hidden for everyone, but for the logged user, it also queries the hidden ones. I think the SQL for that would be something like:
SELECT * FROM Repository r
WHERE r.hidden = false
OR (r.hidden = true AND r.userId = ctx.session.user.id)

which is very simple, but for some reason, I can't get this to work on my procedure at all:
getAllBumpedRepos: publicProcedure.query(({ ctx }) => {
    return ctx.prisma.repository.findMany({
      include: { techs: true },
      where: {
        hidden: false,
        OR: {
          hidden: false,
          AND: { hidden: true, userId: ctx.session?.user.id },
        },
      },
    });
  }),
Was this page helpful?