PrismaPostgresIntermediate
count, aggregate, groupBy
পরিসংখ্যান client-API-তেই — ড্যাশবোর্ড বানানো।
4টি অংশবাংলা ভাষায়
const total = await prisma.product.count({
where: { active: true },
});
const stats = await prisma.order.aggregate({
where: { status: "paid" },
_count: true,
_sum: { total: true },
_avg: { total: true },
_max: { created_at: true },
});groupBy — category-wisets
ts
const byCategory = await prisma.product.groupBy({
by: ["categoryId"],
_sum: { price: true },
_count: true,
orderBy: { _count: { categoryId: "desc" } },
});groupBy-এ by বাধ্যতামূলক — তারপর _sum/_avg ইত্যাদি। orderBy/having ঘুরে-ফিরে যায় post-aggregation।
HAVING-equivalent
Prisma-তে groupBy-এর having: { _sum: { total: { gte: ... } } } — SQL HAVING-এর সাথে মেলে।
শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।