简体   繁体   English

NestJS:PostgreSQL 中不区分大小写的搜索

[英]NestJS: Case-insensitive search in PostgreSQL

Is there any way to do a case-insensitive search with NestJS in PostgreSQL?有没有办法在 PostgreSQL 中使用 NestJS 进行不区分大小写的搜索?

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.我正在尝试将其更改为不区分大小写的搜索。

The ILike option should work for that: ILike选项应该适用于:

import {ILike} from "typeorm";

const loadedPosts = await connection.getRepository(Post).find({
    title: ILike("%out #%")
});

Example from https://typeorm.io/#/find-options/advanced-options来自https://typeorm.io/#/find-options/advanced-options的示例


For ILIKE in Postgres see https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE对于 Postgres 中的ILIKE ,请参阅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.根据活动区域设置,可以使用关键字 ILIKE 代替 LIKE 以使匹配不区分大小写。 This is not in the SQL standard but is a PostgreSQL extension.这不在 SQL 标准中,而是 PostgreSQL 扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM