Answer a question

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.

Answers

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.

Logo

PostgreSQL社区为您提供最前沿的新闻资讯和知识内容

更多推荐