Home > Net >  Multiple where condition in typeorm
Multiple where condition in typeorm

Time:11-28

FROM customers
WHERE favorite_website = 'techonthenet.com'
AND customer_id > 6000;

How to implement this in typeorm querybuilder?

CodePudding user response:

See queryBuilder & where documentation for more information.

Without parameters:

const customers = await customerRepository
    .createQueryBuilder("customer")
    .where(`customer.favorite_website = 'techonthenet.com'`)
    .andWhere(`customer.customer_id > 6000`)
    .getMany();

With parameters:

const customers = await customerRepository
    .createQueryBuilder("customer")
    .where(`customer.favorite_website = :website`, { website: "techonthenet.com")
    .andWhere(`customer.customer_id > :id`, { id: 6000 })
    .getMany();
  • Related