[typeOrm]Raw 쿼리 사용예시
1
// already there
querybuilder
.[...]
.where('LOWER(users.email) = :email', { email: email.toLowerCase() });
// unsafe via repository, since params are unescaped:
repo.findOne({
where: {
email: Raw(alias => `LOWER(${alias}) = '${email.toLowerCase()}'`).
},
});
// would be nice to have:
repo.findOne({
where: {
email: Raw(alias => 'LOWER(${alias}) = :email', { email: email.toLowerCase() }),
},
});
2
const [result, total] = await this.findAndCount(
{
where: { title: Raw(alias => `LOWER(${alias}) Like '%${value}%'`) },
take: take,
skip: skip
}
);
return {
data: result,
count: total
}
- ilike보다 소문자로 바꿔서 like로 찾는게 빠름
출처
https://github.com/typeorm/typeorm/issues/1231
https://github.com/typeorm/typeorm/blob/master/docs/find-options.md
https://github.com/typeorm/typeorm/issues/4418
https://github.com/typeorm/typeorm/issues/3329
https://github.com/typeorm/typeorm/issues/2475
Author And Source
이 문제에 관하여([typeOrm]Raw 쿼리 사용예시), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jeong3320/typeOrmRaw-쿼리-사용예시저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)