Answer the question
In order to leave comments, you need to log in
How to make a search query on multiple TypeOrm parameters?
Conditions is the essence of the order
in it the fields status, name, description, the main text
is the code
queryBuilder
.where("orders.status = :status", {
status: query.status,
})
.orWhere("orders.title LIKE :title", {
title: `%${query.name}%`,
})
.orWhere("orders.description LIKE :description", {
description: `%${query.name}%`,
});
Answer the question
In order to leave comments, you need to log in
You can use the callback in where:
queryBuilder.where("orders.status = :status", {
status: query.status,
}).andWhere(
new Brackets((qb) => {
qb.orWhere("orders.title LIKE :title", {
title: `%${query.name}%`,
}).orWhere("orders.description LIKE :description", {
description: `%${query.name}%`,
});
})
);
queryBuilder.where(
"orders.status = :status AND (orders.title LIKE :title OR orders.description LIKE :description)",
{
status: query.status,
title: `%${query.name}%`,
description: `%${query.name}%`,
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question