작성
·
281
·
수정됨
0
useSWR을 이용한 커뮤니티 리스트 가져오기 강의에서
routes/subs.ts의 topSubs 함수를
const topSubs = async (req: Request, res: Response) => {
try {
const imageUrlExp = `COALESCE('s."imageUrn",'https://www.gravatar.com/avatar?d=mp&f=y')`;
const subs = await AppDataSource.createQueryBuilder()
.select(
`s.title, s.name, ${imageUrlExp} as "imageUrl", count(p.id) as "postCount"`
)
.from(Sub, "s")
.leftJoin(Post, "p", `s.name = p."subName"`)
.groupBy('s.title, s.name, "imageUrl"')
.orderBy(`"postCount"`, "DESC")
.limit(5)
.execute();
return res.json(subs);
} catch (error) {
console.log(error);
return res.status(500).json({ error: "문제가 발생했습니다." });
}
};
으로 강사님이 작성해주셨는데, 저는 아래와 같이 해야 동작하더라구요.
const topSubs = async (req: Request, res: Response) => {
try {
const imageUrlExp = `COALESCE(s.imageUrn, 'https://www.gravatar.com/avatar?d=mp&f=y')`;
const subs = await AppDataSource.createQueryBuilder()
.select(`s.name, s.title, ${imageUrlExp} as "imageUrl", count(p.id) as "postCount"`)
.from(Sub, 's')
.leftJoin(Post, 'p', `s.name = p.subName`)
.groupBy('s.name, s.title, "imageUrl"')
.orderBy(`"postCount"`, 'DESC')
.limit(5)
.execute();
return res.json(subs);
} catch (error) {
console.log(error);
return res.status(500).json({ error: '문제가 발생했습니다.' });
}
};
제가 postgresql이 아닌 mariadb를 사용하고 있는데, db가 달라서 생기는 차이가 맞나요? 아니면 다른 이유가 있는지 궁급합니다!
공식문서까지 찾아주시고,, 친절한 답변 감사합니다!