Transaction Isolation Level Proposal
See original GitHub issueIssue 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) => {
...
});
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have any news about this version?
0.2.8 was released few months ago, so this issue should be closed for some time 😃