반응형
    
    
    
  유형이 있는 날짜보다 오래된 데이터 검색ORM
특정 날짜보다 오래된 데이터를 가져오기 위해 Postgre DB에 대한 쿼리를 실행하고 있습니다.
여기 제 기능이 있습니다.
async filesListToDelete(): Promise<any> {
  return await this.fileRepository.find({
    where: { last_modified: { $lt: '2018-11-15 10:41:30.746877' } },
  });
}
파일 엔티티를 정의한 방법은 다음과 같습니다.
export class File {
  @PrimaryGeneratedColumn()
  id: number;
  @Column({ nullable: false })
  idFonc: number;
  @Column({ nullable: false })
  version: number;
  @Column('varchar', { length: 100, nullable: false })
  filename: string;
  @Column({ nullable: true })
  last_modified: Date;
  @Column({ nullable: false })
  device: boolean;
  @ManyToOne(type => Type, { nullable: false })
  @JoinColumn({ referencedColumnName: 'id' })
  type: Type;
  @OneToMany(type => FileDevice, filedevice => filedevice.file)
  fileDevice: FileDevice[];
}
이 오류가 발생했습니다.
QueryFailedError: invalid input syntax for type timestamp: "{"$lt":"2018-11-15 10:41:30.746877"}"
더 적게 사용할 수 있습니다.Than, 그 의사는
async filesListToDelete(): Promise<any> {
  return await this.fileRepository.find({
   where: { 
       last_modified:  LessThan('2018-11-15  10:41:30.746877') },
});}
또한 다음을 사용하여 이 작업을 수행할 수 있습니다.createQueryBuilder아래와 같이:
    public async filesListToDelete(): Promise<any> {
        let record = await this.fileRepository.createQueryBuilder('file')
            .where('file.last_modified > :start_at', { start_at: '2018-11-15  10:41:30.746877' })
            .getMany();
        return record
    }
둘 중 하나라도 가져올 것입니다.OLDER데이터.
내장된TypeORM연산자(사용자)
async filesListToDelete(): Promise<any> {
  return await this.fileRepository.find({
    where: { last_modified:  LessThan('2018-11-15  10:41:30.746877') },
  });
}
와 함께PostgreSQL연산자(사용자)
public async filesListToDelete(): Promise<any> {
    let record = await this.fileRepository.createQueryBuilder('file')
        .where('file.last_modified < :start_at', { start_at: '2018-11-15  10:41:30.746877' })
        .getMany();
    return record
}
언급URL : https://stackoverflow.com/questions/53495716/searching-data-older-than-a-date-with-typeorm
반응형
    
    
    
  'programing' 카테고리의 다른 글
| NSString을 분할하여 하나의 특정 조각에 액세스합니다. (0) | 2023.05.07 | 
|---|---|
| DockStyle 사용 방법.WPF의 표준 제어 장치를 채우시겠습니까? (0) | 2023.05.02 | 
| SQL Azure 테이블 크기 (0) | 2023.05.02 | 
| 보관 파일을 제출할 때 Xcode 6이 충돌합니다. (0) | 2023.05.02 | 
| Bash에서 명령이나 별칭에 "Y/n이 확실합니까?"를 추가하는 방법은 무엇입니까? (0) | 2023.05.02 |