mle*_*eko 7 nestjs node.js-typeorm
我使用实体管理器进行事务,确保我像这样调用的过程中没有嵌套提交,我设置了 ,search_path
因为我的过程在内部调用无前缀实体
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],
);
});
}
}
Run Code Online (Sandbox Code Playgroud)
然而,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
Run Code Online (Sandbox Code Playgroud)
我确实找不到与此错误类似的任何内容,可能是什么问题,我该如何解决它?
小智 5
我在 Jest 套件中调试一些数据库测试时目睹了此错误。问题的根源是当我单步执行代码时测试超时。
Jest 会拦截require
s 和import
s,因此在测试运行程序处于超时状态后,拦截的 require()(位于 TypeORM 查询运行程序代码深处)不会执行任何操作。这意味着InsertQueryBuilderCls
是未定义的。
mle*_*eko -2
这并不是上述问题的真正答案,但是,在使用 typeorm 一段时间后,我想建议遇到此问题的人们使用 queryRunner 而不是查询构建器。它还具有编写准备好的查询以防止 SQL 注入的方法。
归档时间: |
|
查看次数: |
1102 次 |
最近记录: |