Typeorm/Nestjs 原始查询用法强制小写为列名

Typeorm/Nestjs Raw query usage forcing lowercase to column name

我需要有关使用 nest/typeorm;

执行查询的帮助

我正在使用 Typeorm“InjectConnection”在我的 Postgres 数据库中构建一个原始查询,给我错误的字段是 user_roles_role.userId 列(请注意,我来自 userId 是大写的)
代码如下:

const queryText = `SELECT * FROM user_roles_role WHERE user_roles_role.userId = ${id}`

try {
  const rawData = await this.connection.query(queryText);
  return rawData;
} catch (err) {
  console.log(err);
  return err;
}

我在执行此查询时遇到错误,因为 Typeorm 以某种方式强制在列名称上使用小写字母,如下所示的 typeorm 错误(来自 catch(Err))

query: 'SELECT * FROM user_roles_role WHERE user_roles_role.userId = 1', parameters: undefined, driverError: error: column user_roles_role.userid does not exist

我试过:

使用单引号和双引号(没用)

完整错误:

"query": "SELECT * FROM user_roles_role WHERE user_roles_role.userId = 1", "driverError": { "length": 189, "name": "error", "severity": "ERROR", "code": "42703", "hint": "Perhaps you meant to reference the column >"user_roles_role.userId".", "position": "37", "file": "parse_relation.c", "line": "3599", "routine": "errorMissingColumn" }

作为 PostgreSQL 敏感的大小写,你应该像这样在双引号上创建列:

 `SELECT * FROM user_roles_role WHERE user_roles_role."userId" = ${id}`