-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add typeorm car rental write repo, add typeorm transaction mngr
- Loading branch information
1 parent
0523650
commit 8c81b28
Showing
8 changed files
with
46 additions
and
17 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
src/configuration/injection/containers/repositories/typeorm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/driven/repositories/typeorm/common/transactionManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import TransactionManagerInterface from "src/core/domain/common/interfaces/transactionManager"; | ||
import TransactionInterface from "src/core/domain/common/interfaces/transaction"; | ||
import {DataSource, QueryRunner} from "typeorm"; | ||
import {container, inject, singleton} from "tsyringe"; | ||
|
||
@singleton() | ||
export default class TypeORMTransactionManager implements TransactionManagerInterface { | ||
|
||
private readonly dataSource: DataSource; | ||
|
||
constructor(@inject("DataSource") dataSource: DataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
async commit(): Promise<void> { | ||
const queryRunner: QueryRunner = container.resolve("CurrentQueryRunner"); | ||
await queryRunner.commitTransaction(); | ||
await queryRunner.release(); | ||
} | ||
|
||
// @ts-ignore | ||
newTransaction(): TransactionInterface { | ||
} | ||
|
||
async startTransaction(): Promise<void> { | ||
const queryRunner = this.dataSource.createQueryRunner(); | ||
await queryRunner.connect(); | ||
await queryRunner.startTransaction(); | ||
container.register("CurrentQueryRunner", {useValue: queryRunner}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters