It might just be my setup, but if this can help someone else I’ll post it anyway ![]()
In “Building a Review Summerizer“ 3.1 I could not get the PrismaClient to work like Mosh.
I needed to create an adapter for it to work, and add the values to the .env file as described here: Quickstart: Prisma ORM with MySQL (10 min) | Prisma Documentation
Furthermore the “url” parameter should/could not be added to the schema.prisma, but is added automatically in prisma.config.ts
EDIT: Forgot that I also needed to run “bunx prisma generate“
At the top of routes.ts I imported the mysql/mariaDB adapter as described in the article above:
import { PrismaClient } from "./generated/prisma/client";
import { PrismaMariaDb } from "@prisma/adapter-mariadb";
Then this seems to work:
router.get("/api/products/:id/reviews", async (req: Request, res: Response) => {
const adapter = new PrismaMariaDb({
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME,
connectionLimit: 5,
});
const prisma = new PrismaClient({ adapter });
const productId = Number(req.params.id);
const reviews = await prisma.review.findMany({
where: { productId },
orderBy: { createdAt: "desc" },
});
res.json(reviews);
});