如果我启动提交事务但不释放它会发生什么?
示例:
const connection = getConnection()
const runner = connection.createQueryRunner()
await runner.connect()
await runner.startTransaction()
try {
const repository = connection.getRepository(PostgresUserEntity)
const instance = repository.create({ username: 'john doe' })
await runner.manager.save(instance)
// imagine others operations...
await runner.commitTransaction()
} catch () {
await runner.rollbackTransaction()
}
文档没有解释有关此的详细信息
这是一些文档: https://orkhan.gitbook.io/typeorm/docs/query-runner
Release是用来将连接归还到数据库连接池的,所以如果不这样做的话,就会出现性能问题。这是一篇关于它的帖子: NestJs 和 TypeOrm 事务管理