问题
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