使用 typeorm 插入 select

Insert into select using typeom

我尝试在 nestjs 项目中使用 typeorm 执行“INSERT INTO SELECT”。 我已经正确地设置了订阅者部分,但是当我想执行我的功能时,我有一个错误

(node:4592) UnhandledPromiseRejectionWarning: TypeError: statement.replace is not a function (node:4592) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().

这是我的函数

async insertIntoSelect(id) {
    const qb = this.MyOperationRepository.createQueryBuilder();
    return await qb
      .createQueryBuilder()
      .insert()
      .into(EntityA, ['FieldA', 'FieldB'])
      .select(id, 'FieldB')
      .from(EntityB, 'EntityB')
      .where('EntityB.id= ' + id)
      .printSql()
      .execute();
  }

不知道是我功能不对还是流程不对。 如果有人有示例或发现我的代码有问题,请告诉我。

似乎 INSERT INTO ... SELECTnot currently supported in TypeOrm。您需要使用原始查询、子查询或执行多个查询。

更多可能的解决方案