Use LIKE in WHERE conditions in typeORM Typescript

Viewed 2934

I'm trying to query on a columns with SQL endswith in a Typescript app

cont tracking_code = '65432'
repo.findValidOne({ where: { tracking_code }});

I want to change it so the tracking_code value ends with the tracking value that I have available on the code

The SQL equivalent would be

SELECT * 
FROM repo 
WHERE tracking_code LIKE '%65432' 
LIMIT 1;

I have tried using a raw query, but it's not what I want.

1 Answers

You need to use Like find operator.

import {Like} from 'typeorm';

cont tracking_code = '65432';
repo.findValidOne({ where: { tracking_code: Like(`%${tracking_code}`) }});
Related