programing

유형이 있는 날짜보다 오래된 데이터 검색ORM

starjava 2023. 5. 2. 22:15
반응형

유형이 있는 날짜보다 오래된 데이터 검색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

반응형