@jihyunlab/typeorm-repository는 TypeORM 사용의 편의성을 높이기 위해 개발되었습니다.
프로젝트 폴더에서 @jihyunlab/typeorm-repository를 설치합니다.
npm i @jihyunlab/typeorm-repository
간단한 방식으로 NestJS에서 사용할 수 있습니다.
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { TypeOrmRepository } from '@jihyunlab/typeorm-repository';
@Injectable()
export class TypeOrmService {
private readonly userTypeOrmRepository: TypeOrmRepository;
constructor(
@InjectRepository(User)
private readonly userRepository: Repository<User>
) {
this.userTypeOrmRepository = new TypeOrmRepository(this.userRepository);
}
}
엔티티 삽입을 위한 기능을 제공합니다.
const result = await this.userTypeOrmRepository.insert({
name: 'JihyunLab',
email: 'info@jihyunlab.com',
});
단일 엔티티 검색을 위한 기능을 제공합니다.
const result = await this.userTypeOrmRepository.findOne({
name: 'JihyunLab',
email: 'info@jihyunlab.com',
});
{
"id": 1,
"name": "JihyunLab",
"email": "info@jihyunlab.com",
"created_at": "2025-11-19T03:33:03.231Z"
}
대소문자 구분 검색 기능을 간단한 방식으로 제공합니다.
const result = await this.userTypeOrmRepository.findOne(
{
name: 'jihyunlab',
},
{ ignoreCase: false }
);
null
부분 문자열 검색 기능을 간단한 방식으로 제공합니다.
const result = await this.userTypeOrmRepository.findOne(
{
name: 'Jihyun',
email: 'INFO@JIHYUNLAB.COM',
},
{ contains: true }
);
{
"id": 1,
"name": "JihyunLab",
"email": "info@jihyunlab.com",
"created_at": "2025-11-19T03:33:03.231Z"
}
IN 기반의 검색 및 정렬 기능을 제공합니다.
IN 연산자 사용시 ignoreCase와 contains 설정이 적용되지 않습니다.
const result = await this.userTypeOrmRepository.find(
{
name: ['JihyunLab'],
},
{ limit: 1, offset: 0, sort: 'created_at', order: ORDER.DESC }
);
[
{
"id": 1,
"name": "JihyunLab",
"email": "info@jihyunlab.com",
"created_at": "2025-11-19T03:33:03.231Z"
}
]
$ne와 같은 부정 조건 검색 기능을 지원합니다.
const result = await this.userTypeOrmRepository.find(
{
name: { $ne: 'JihyunLab' },
},
{ limit: 1, offset: 0, sort: 'created_at', order: ORDER.DESC }
);
[]
$regex와 같은 정규식 기반 검색 기능을 지원합니다.
const result = await this.userTypeOrmRepository.find(
{
name: { $regex: '^JIHYUNLAB$', $options: 'i' },
},
{ limit: 1, offset: 0, sort: 'created_at', order: ORDER.DESC }
);
[
{
"id": 1,
"name": "JihyunLab",
"email": "info@jihyunlab.com",
"created_at": "2025-11-19T03:33:03.231Z"
}
]
$gt, $gte, $lt, $lte와 같은 비교 연산 검색을 지원합니다.
const result = await this.userTypeOrmRepository.find({
created_at: { $lte: new Date() },
});
[
{
"id": 1,
"name": "JihyunLab",
"email": "info@jihyunlab.com",
"created_at": "2025-11-19T03:33:03.231Z"
}
]
OR 기반의 검색 기능을 제공합니다.
const result = await this.userTypeOrmRepository.find([
{
name: 'JihyunLab',
},
{
email: { $regex: '^info@jihyunlab.com$', $options: 'i' },
},
]);
[
{
"id": 1,
"name": "JihyunLab",
"email": "info@jihyunlab.com",
"created_at": "2025-11-19T03:33:03.231Z"
}
]
검색과 동일한 조건을 기반으로 하는 엔티티 업데이트 기능을 제공합니다.
const result = await this.userTypeOrmRepository.update(
{
name: 'Jihyun',
email: 'INFO@JIHYUNLAB.COM',
},
{ name: 'JihyunLab', email: 'info@jihyunlab.com' },
{ contains: true }
);
{
"generatedMaps": [],
"raw": [],
"affected": 1
}
검색과 동일한 조건을 기반으로 하는 엔티티 삭제 기능을 제공합니다.
const result = await this.userTypeOrmRepository.delete(
{
name: 'Jihyun',
email: 'INFO@JIHYUNLAB.COM',
},
{ contains: true }
);
{
"raw": [],
"affected": 1
}

info@jihyunlab.com