👓 IN array
import { In } from 'typeorm';
repository.find({where: { id : In(idArr)}});
https://github.com/typeorm/typeorm/issues/1239#issuecomment-367207538
👓 LIKE
repository.find({
where : { name : Like(`%${name}%`)}
});
repository.find({
where : { name : Like(`%${escapeLikeString(htmlentities(name))}%`)}
});
// 특수 문자 처리
export const htmlentities = (value: string) =>
value.replace(/[\u00A0-\u9999<>\&]/g, function (i) {
return '&#' + i.charCodeAt(0) + ';';
});
// % _ 처리
export const escapeLikeString = (raw: string, escapeChar = '\\') => {
return raw.replace(/[\\%_]/g, (match) => escapeChar + match);
};
👓 > , >= , < , <=
repository.find({
where : { date1 : MoreThan('2022-01-01')}
});
repository.find({
where : { date1 : MoreThanOrEqual('2022-01-01')}
});
repository.find({
where : { date1 : LessThan('2022-01-01')}
});
repository.find({
where : { date1 : LessThanOrEqual('2022-01-01')}
});
👓 offset
repository.find({
skip: 5,
})
👓 limit
repository.find({
take: 10,
})
https://github.com/typeorm/typeorm/blob/master/docs/find-options.md
반응형
'nodejs' 카테고리의 다른 글
또 사용할것 같은 custom 함수들 (0) | 2022.12.07 |
---|---|
redis connect (0) | 2022.06.09 |
typescript 꿀팁 (0) | 2022.03.03 |
aws s3 endpoint 적용기 (0) | 2022.02.04 |
typeorm multiple database (0) | 2021.08.03 |