import { PrismaClient } from "@prisma/client"; import { PrismaMariaDb } from "@prisma/adapter-mariadb"; import "dotenv/config"; const base = process.env.DATABASE_URL.replace("mysql://", "mariadb://"); const cs = base + (base.includes("?") ? "&" : "?") + "connection_limit=5"; const prisma = new PrismaClient({ adapter: new PrismaMariaDb(cs) }); // 看industry板块 const ind = await prisma.forumCategory.findUnique({ where: { slug: "industry" } }); console.log('industry板块:', ind ? `id=${ind.id}, name=${ind.name}, parentId=${ind.parentId}` : 'NULL'); // 用page.tsx同样的查询 const children = await prisma.forumCategory.findMany({ where: { parentId: ind?.id ?? undefined }, include: { children: { orderBy: [{ sortOrder: "asc" }] } }, orderBy: [{ sortOrder: "asc" }, { createdAt: "desc" }], }); console.log(`\n父板块数: ${children.length}`); let total = 0; for (const c of children) { console.log(` [${c.slug}] ${c.name} (子板块: ${c.children.length})`); total += c.children.length; } console.log(`\n子板块总数: ${total}`); console.log(`page.tsx期待: categories.length + totalSubCategories = ${children.length} + ${total} = ${children.length + total}`); await prisma.$disconnect();