database - 使用 typeORM 搜索早于日期的数据
问题描述
我正在对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"}"
解决方案
您可以使用 MoreThan,文档
async filesListToDelete(): Promise<any> {
return await this.fileRepository.find({
where: {
last_modified: MoreThan('2018-11-15 10:41:30.746877') },
});}
推荐阅读
- javascript - 未找到模块:React 中的“D:\Learning Programming\Javascript....”错误无法解析“persons”
- javascript - 如果加载时间很长,如何中止 XMLHttpRequest?
- rust - Rust 借用检查器阻止我从迭代器返回引用
- winforms - 如何获取xrPictureBox图像URL表达式devExpress winforms的应用路径?
- c# - 如何使用 C# 中的反射调用具有多个 in\out 参数的函数而不知道它们的顺序?
- csv - NimbleCSV:长生不老药
- nexmo - 我可以从浏览器使用 nexmo 拨打电话号码吗?
- r - 提取多边形质心的坐标
- bash - 在 ubuntu 中从 octave 调用 bash 脚本的问题
- sql - 将数据从 Kafka 导入数据库