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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With