Is there a tool that translates raw SQL queries in...
# orm-help
t
Is there a tool that translates raw SQL queries into prisma javascript queries? In particular I’m struggling with sorting nested data. I have got a food with many nutrient values that I want to sort by a specific nutrient value. Not every food has a certain nutrient value. If a food doesn’t have a certain value it should not be included in the result. This is my query:
Copy code
SELECT f.id, jsonb_agg(to_jsonb(n)) FROM (
    SELECT f.id AS id, n.amount FROM "Food" AS f
    JOIN "NutrientValue" AS n ON f.id = n."foodId"
    WHERE n."nutrientId" = 1
    ORDER BY n.amount
) AS f
JOIN "NutrientValue" AS n ON f.id = n."foodId"
GROUP BY f.id, f.amount ORDER BY f.amount;