How to perform a like query Typeorm

后端 未结 5 646
北海茫月
北海茫月 2020-12-30 22:40

Hello guys I\'m trying to find all the results that have a in them. I have tried a couple of ways but the problem is nothing works. It just returns an empty array

5条回答
  •  长情又很酷
    2020-12-30 23:28

    If you have already used .find methods to support your repository needs you might not want to switch to QueryBuilder.

    There is an easy way to implement LIKE filter using findConditions:

    this.displayRepository.find({ where: "Display.name LIKE '%someString%'" });
    

    OR for case insensitive (in postgres):

    this.displayRepository.find({ where: "Display.name ILIKE '%someString%'" });
    

    Keep in mind this is susceptible to Injection attacks, so you must protect the dynamic value explicitly.

提交回复
热议问题