Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typeorm transaction without release

What happens if I start a commit transaction but don't release it?

Example:

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()
}

Docs don't explain details about this

https://typeorm.io/#/transactions/using-queryrunner-to-create-and-control-state-of-single-database-connection

like image 399
Max Rogério Avatar asked Jan 01 '26 11:01

Max Rogério


1 Answers

Here is some documentation: https://orkhan.gitbook.io/typeorm/docs/query-runner

Release is used to return the connection to the database connection pool, so if you don't do it, you will have performance issues. Here is a post about it: NestJs & TypeOrm transaction management

like image 185
Julián Rojas Avatar answered Jan 03 '26 10:01

Julián Rojas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!