Reputation: 63
Is there any way to do a case-insensitive search with NestJS in PostgreSQL?
I've succeeded in doing a case-sensitive search:
let result = await myRepository.findOne({firstName: fName, lastName: lName});
I'm trying to change it to a case-insensitive search.
Upvotes: 5
Views: 3640
Reputation: 4544
The ILike
option should work for that:
import {ILike} from "typeorm";
const loadedPosts = await connection.getRepository(Post).find({
title: ILike("%out #%")
});
Example from https://typeorm.io/#/find-options/advanced-options
For ILIKE
in Postgres see https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE
The key word ILIKE can be used instead of LIKE to make the match case-insensitive according to the active locale. This is not in the SQL standard but is a PostgreSQL extension.
Upvotes: 9