Hey all, I just had an interesting JS type problem...
# orm-help
f
Hey all, I just had an interesting JS type problem removing nulls from Prisma queries which might be useful to someone: I'm using this function to remove nulls from my Prisma get queries:
Copy code
export function removeNull(obj: any): any {
  if (!obj) return obj;
  if (obj instanceof Date) return obj;
  else {
    return Object.fromEntries(
      Object.entries(obj)
        .filter(([_, v]) => v != null)
        .map(([k, v]) => [k, v === Object(v) ? removeNull(v) : v])
    );
  }
}
And before I added the instanceof check it was removing all Date types from the response because JS types Date as an object 🤪 The result was returning objects with {insertedAt: {} ... } Maybe I'm missing a native Prisma method to remove nulls from queries??