Does TypeORM supports raw SQL queries for input and output?

偶尔善良 提交于 2020-12-08 05:23:46

问题


I would like to know if there is a feature of TypeORM that supports raw sql queries for Insert Update Delete Select etc..


回答1:


According to this issue comment, TypeORM enables you to use any queries to your heart's content. using entityManager.query() Here is the documentation.

UPDATE

Link above is outdated, try this instead entity-manager-api.

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



回答2:


2020 UPDATE, entityManager.query() basing the entityManager off the EntityManager class, was not working for me so had to do this:

  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



来源:https://stackoverflow.com/questions/44493554/does-typeorm-supports-raw-sql-queries-for-input-and-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!