如何在 typeORM 中找到最早日期的实体
How do I find the entity with the earliest date in typeORM
基本上,我有一个带有日期列的实体,我正在尝试查询具有最早创建日期的实体。我想知道如何在 typeORM 中找到最早的实体。
到目前为止我有这样的东西:
const latest_result = await getRepository(Verification).findOne({ where: {
created_date: // Change to find latest date
}});
我的模型是这样的:
export class Verification {
@Column({ nullable: false })
success!: boolean
@CreateDateColumn()
created_date!: Date
};
我会通过订购 DESC 并采用第一个来做最简单直接的方法(但未优化)。如果 table 条记录
一样多,请确保在你的日期上有一个索引
export class Verification {
@Column({ nullable: false })
success!: boolean
@Index()
@CreateDateColumn()
created_date!: Date
};
const latest_result = await getRepository(Verification).find({
skip:0,
take:1,
order: { created_date: "DESC" }
});
基本上,我有一个带有日期列的实体,我正在尝试查询具有最早创建日期的实体。我想知道如何在 typeORM 中找到最早的实体。
到目前为止我有这样的东西:
const latest_result = await getRepository(Verification).findOne({ where: {
created_date: // Change to find latest date
}});
我的模型是这样的:
export class Verification {
@Column({ nullable: false })
success!: boolean
@CreateDateColumn()
created_date!: Date
};
我会通过订购 DESC 并采用第一个来做最简单直接的方法(但未优化)。如果 table 条记录
一样多,请确保在你的日期上有一个索引export class Verification {
@Column({ nullable: false })
success!: boolean
@Index()
@CreateDateColumn()
created_date!: Date
};
const latest_result = await getRepository(Verification).find({
skip:0,
take:1,
order: { created_date: "DESC" }
});