尝试按 Postgresql 上的文本值对枚举字段(大陆)进行排序。这很好用;
order by
"Country"."continent"::TEXT DESC
当我设置 orderBy 时,需要在 TypeORM 上创建相同的结果;
orderBy = { ...orderBy, continent: value.sort };
如何在TypeOrm中使用它?
我知道通过该属性订购的两种方法。
第一个是使用常规方式:
const countries = await CountryEntity.find({
order: {
continent: "DESC"
}
})
另一种方式(如果您发现显式转换有用)是这样的:
const orderBy: OrderByCondition = {
continent: `CAST("Country"."continent" AS TEXT) ${value.sort}`,
};
const countries = await Country.find({
order: orderBy,
});