【问题标题】:typeorm - InsertQueryBuilderCls is not a constructortypeorm - InsertQueryBuilderCls 不是构造函数
【发布时间】:2022-12-18 16:33:51
【问题描述】:

我使用实体管理器进行事务,确保在我这样调用的过程中没有嵌套提交,我设置了search_pathsince my proc calls unprefixed entities internally

async savetournamentTransaction(tournament: any, matchId: string) {
    await this.connection.manager.transaction(async (tournamentEntityManager) => {
      const tournamentRepository = tournamentEntityManager.getRepository(tournament);
      await tournamentRepository.query(`SET LOCAL search_path to ${matchId}`);
      await tournamentRepository.save(tournament);
      await tournamentRepository.query(
        `CALL fillOrganizationScheduleTable($1,${tournament.tournament_id});`,
        [matchId],
      );
    });
  }
}

但是,typeorm 给了我这个我无法真正理解的错误:

[Nest] 790  - 09/16/2022, 4:40:43 PM   ERROR [ExceptionsHandler] InsertQueryBuilderCls is not a constructor
TypeError: InsertQueryBuilderCls is not a constructor
    at SelectQueryBuilder.insert (/mypath/desktop/prj/volleyball-organization/src/query-builder/QueryBuilder.ts:200:16)
    at SubjectExecutor.executeInsertOperations (/mypath/desktop/prj/volleyball-organization/src/persistence/SubjectExecutor.ts:430:26)
    at SubjectExecutor.execute (/mypath/desktop/prj/volleyball-organization/src/persistence/SubjectExecutor.ts:137:20)
    at EntityPersistExecutor.execute (/mypath/desktop/prj/volleyball-organization/src/persistence/EntityPersistExecutor.ts:194:36)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at /mypath/desktop/prj/volleyball-organization/src/tournaments/tournaments.service.ts:155:13
    at EntityManager.transaction (/mypath/desktop/prj/volleyball-organization/src/entity-manager/EntityManager.ts:151:28)
    at tournamentsService.savetournamentTransaction (/mypath/desktop/prj/volleyball-organization/src/tournaments/tournaments.service.ts:152:9)
    at tournamentsService.createtournament (/mypath/desktop/prj/volleyball-organization/src/tournaments/tournaments.service.ts:113:9)
    at /mypath/desktop/prj/volleyball-organization/node_modules/@nestjs/core/router/router-execution-context.js:46:28  
  

我真的找不到与此错误类似的任何问题,可能是什么问题,我该如何解决?

【问题讨论】:

    标签: nestjs node.js-typeorm


    【解决方案1】:

    这并不是上述问题的真正答案,但是,使用 typeorm 一段时间后,我想建议遇到此问题的人使用 queryRunner 而不是查询构建器。它还具有编写准备好的查询以防止 sql 注入的方法。

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 2013-12-25
      • 2021-01-11
      • 2015-12-04
      • 2018-11-29
      • 2016-12-04
      • 2020-12-27
      • 2021-04-05
      • 2021-06-21
      相关资源
      最近更新 更多