TypeORM是否支持输入和输出的原始SQL查询?

时间:2017-06-12 07:23:54

标签: orm typeorm

我想知道TypeORM是否支持插入更新删除选择等原始SQL查询的功能。

2 个答案:

答案 0 :(得分:8)

根据此问题comment,TypeORM可让您对心脏内容使用任何查询。使用entityManager.query()这是documentation

<强>更新

上面的链接已过时,请尝试使用entity-manager-api

const rawData = await manager.query(`SELECT * FROM USERS`);

答案 1 :(得分:1)

2020更新,entityManager.query()基于EntityManager类的entityManager,对我不起作用,因此必须这样做:

  import { getManager } from 'typeorm';

  const entityManager = getManager();
  const someQuery = entityManager.query(`
  SELECT 
    fw."X",
    fw."Y",
    ew.*
  FROM "table1" as fw
  JOIN "table2" as ew
    ON fw."X" = $1 AND ew.id = fw."Y";
  `, [param1]);

https://orkhan.gitbook.io/typeorm/docs/working-with-entity-manager

相关问题