typeorm

Does typeorm support SQL IN clauses


Does typeorm support SQL IN clauses? I'm trying to query a repository where a field matches 1 of multiple values.

myRepository.find({
  where: {
    SomeID: // IN [1, 2, 3, 4]
    }
  });

Solution

  • You can use QueryBuilder for this purpose:

    const users = await userRepository.createQueryBuilder("user")
         .where("user.id IN (:...ids)", { ids: [1, 2, 3, 4] })
         .getMany();