검색하는 TypeORM 코드
async search(searchPostingDto: SearchPostingDto) {
const postings = await this.postingsRepository
.createQueryBuilder('posting')
.select([
'posting.id',
'posting.title',
'posting.writer',
'posting.thumbnail',
])
.where('posting.title LIKE :keyword', {
keyword: `%${searchPostingDto.keyword || ''}%`,
})
.getMany();
return postings;
}
http://localhost:3000/postings?keyword=안녕
뭐라 길게 나오지만 결론은 한글이라서 문제 발생~
sqlMessage: "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_unicode_ci,COERCIBLE) for operation 'like'",
sql: "SELECT `posting`.`id` AS `posting_id`, `posting`.`writer` AS `posting_writer`, `posting`.`title` AS `posting_title`, `posting`.`thumbnail` AS `posting_thumbnail` FROM `posting` `posting` WHERE `posting`.`title` LIKE '%안녕%'"
http://localhost:3000/postings?keyword=as