data icon indicating copy to clipboard operation
data copied to clipboard

Make empty array to return all the records when using `in`

Open drac94 opened this issue 3 years ago • 0 comments

Right now when passing an empty array when using in does not return anything, is there a way to make it return everything instead? this will help to use dynamic properties

Or maybe there is another way of doing it, sorry if thats the case

const idParam = req.url.searchParams.getAll('id');

db.employee.findMany({
  where: { id: { in: idParam } },
  take: size,
  skip: (page - 1) * size,
}),

Above code returns empty if idParam is null, undefined or an empty array []

Right now I'm doing this instead

const idParam = req.url.searchParams.getAll('id');

if(idParam.length > 0){
  db.employee.findMany({
    where: { id: { in: idParam } },
    take: size,
    skip: (page - 1) * size,
  }),
} else {
  db.employee.findMany({
    take: size,
    skip: (page - 1) * size,
  }),
}

Thanks!

drac94 avatar Aug 23 '22 17:08 drac94