我如何使用一个查询在2个不同的存储库中搜索列中的单词(MySQL和TYPEORM和nestjs) &



我正在使用MySQLTypeormnestjs它们的最新版本,我有这些实体:

shop.entity.ts:

@Entity()
export class Shop {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column({ unique: true, nullable: false })
name: string;
@Column({ nullable: true })
description: string;
@Column({ default: "" })
image_url: string;
@Column({ default: true })
is_active: boolean;
@Column({ default: false })
is_special: boolean;
@Column({ nullable: false, default: () => "CURRENT_TIMESTAMP" })
created_at: Date;
}

offer.entity.ts

@Entity()
export class Offer {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column({ nullable: false })
name: string;
@Column({ nullable: false })
fabric: string;
@Column({ nullable: false })
code: string;
@Column({ nullable: false })
start_date: Date;
@Column({ nullable: false })
end_date: Date;
@Column({ default: "" })
description: string;
@Column({ nullable: false, default: () => "CURRENT_TIMESTAMP" })
created_at: Date;
}

shop.service.ts过滤查询

async filter(filter: FilterShopDto) {
const queryBuilder = this.shopRepository
.createQueryBuilder("shop")
.where(
`shop.description LIKE :description`,
{
description: filter.description ? `%${filter.description}%` : "%",
},
)
.orderBy("shop.created_at", "DESC")
.skip(filter.skip)
.take(filter.take)
}

offer.service.ts提供过滤

async filter(filter: FilterOfferDto) {
const queryBuilder = this.offerRepository
.createQueryBuilder("offer")
.where(
" offer.description LIKE :description",
{
description: filter.description ? `%${filter.description}%` : "%", 
},
)
.orderBy(
"offer.created_at",
"DESC",
)
.skip(filter.skip)
.take(filter.take)
}

每一个查询都工作得很好,但是我想做的是将这两个查询合并为一个查询,使我从商店和报价获得搜索结果,并订购记录,并应用跳过并接受它们。有什么办法可以做到吗?

TypeORM使您能够使用任何查询,以您的心的内容。使用entityManager.query ()这是文档

相关内容

  • 没有找到相关文章

最新更新