question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transaction Isolation Level Proposal

See original GitHub issue

Issue type:

[ ] question [ ] bug report [x] feature request [ ] documentation issue

It was mentioned in #233 to create an issue defining how one would see isolation levels being used.

I believe it would be as simple as an isolationLevel parameter on the transaction methods. Alternatively an options parameter could be specified with the isolationLevel as a property of those options.

For the EntityManager an overloaded function would be needed in order to specify the options before the callback:

async transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManger: EntityManager) => Promise<T>): Promise<T>;
async transaction<T>(runInTransaction: (entityManger: EntityManager) => Promise<T>): Promise<T> {

  ...

  try {
    if (isolationLevel) {
      await queryRunner.startTransaction(isolationLevel);
    } else {
      await queryRunner.startTransaction();
    }
    const result = await runInTransaction(queryRunner.manager);
    await queryRunner.commitTransaction();
    return result;
    ...
}

For PostgresQueryRunner:

async startTransaction(isolationLevel?: IsolationLevel): Promise<void> {
  if (this.isTransactionActive)
      throw new TransactionAlreadyStartedError();

  this.isTransactionActive = true;
  await this.query("START TRANSACTION");
  if (isolationLevel) {
    await this.query("SET TRANSACTION ISOLATION LEVEL" + isolationLevel)
  }
}

Where the following are defined:

enum IsolationLevel {
  READ_UNCOMMITTED = 'READ UNCOMMITTED',
  READ_COMMITED = 'READ COMMITTED',
  REPEATABLE_READ = 'REPEATABLE READ',
  SERIALIZABLE = 'SERIALIZABLE'
}

Then to use it, it would be as simple as:

getManager().transaction(IsolationLevel.SERIALIZABLE, (manager) => {
  ...
});

References: Postgres MySQL

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
deerarescommented, Aug 28, 2018

we have blocking issue that needs to be fixed first before we can release a new version, awaiting for that.

Have any news about this version?

0reactions
Kononnablecommented, Feb 10, 2019

0.2.8 was released few months ago, so this issue should be closed for some time 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transaction Isolation Level as a Repo level property
Feature Proposal: Transaction Isolation Level as a Repo level property ... us in a place where it's very hard to use transaction isolation...
Read more >
Which SQL Transaction Isolation Level to be used?
The default isolation level is READ COMMITTED and it is ok to use the default isolation level. If you want a more pessimistic...
Read more >
SET TRANSACTION ISOLATION LEVEL (Transact-SQL)
A transaction running under SNAPSHOT isolation level can view changes made by that transaction. For example, if the transaction performs an ...
Read more >
Tips for Read/Write Locks Depending on Transaction Isolation ...
Considering tips for read/write locks depending on transaction Isolation level in MSSQL.
Read more >
Generalized Isolation Level Definitions
straints on transaction histories and graphs; we proscribe different types of cycles in a ... The original proposal for isolation levels [13] introduced....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found