generated from defi-wonderland/ts-turborepo-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: transaction manager w/callback pattern
- Loading branch information
Showing
17 changed files
with
193 additions
and
106 deletions.
There are no files selected for viewing
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
11 changes: 9 additions & 2 deletions
11
packages/repository/src/interfaces/applicationPayoutRepository.interface.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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { NewApplicationPayout } from "../types/applicationPayout.types.js"; | ||
import { TransactionConnection } from "../types/transaction.types.js"; | ||
|
||
export interface IApplicationPayoutRepository { | ||
export interface IApplicationPayoutRepository< | ||
TxConnection extends TransactionConnection = TransactionConnection, | ||
> { | ||
/** | ||
* Inserts a new application payout into the database. | ||
* @param applicationPayout - The new application payout to insert. | ||
* @param tx Optional transaction connection | ||
* @returns A promise that resolves when the application payout is inserted. | ||
*/ | ||
insertApplicationPayout(applicationPayout: NewApplicationPayout): Promise<void>; | ||
insertApplicationPayout( | ||
applicationPayout: NewApplicationPayout, | ||
tx?: TxConnection, | ||
): Promise<void>; | ||
} |
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
11 changes: 8 additions & 3 deletions
11
packages/repository/src/interfaces/donationRepository.interface.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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
import { NewDonation } from "../internal.js"; | ||
import { TransactionConnection } from "../types/transaction.types.js"; | ||
|
||
export interface IDonationRepository { | ||
export interface IDonationRepository< | ||
TxConnection extends TransactionConnection = TransactionConnection, | ||
> { | ||
/** | ||
* Insert a single donation | ||
* @param donation The donation to insert | ||
* @param tx Optional transaction connection | ||
* @returns A promise that resolves when the donation is inserted | ||
*/ | ||
insertDonation(donation: NewDonation): Promise<void>; | ||
insertDonation(donation: NewDonation, tx?: TxConnection): Promise<void>; | ||
|
||
/** | ||
* Insert many donations | ||
* @param donations The donations to insert | ||
* @param tx Optional transaction connection | ||
* @returns A promise that resolves when the donations are inserted | ||
*/ | ||
insertManyDonations(donations: NewDonation[]): Promise<void>; | ||
insertManyDonations(donations: NewDonation[], tx?: TxConnection): Promise<void>; | ||
} |
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
20 changes: 20 additions & 0 deletions
20
packages/repository/src/interfaces/transactionManager.interface.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,20 @@ | ||
import { TransactionConnection } from "../internal.js"; | ||
|
||
/** | ||
* The ITransactionManager interface provides a generic transaction management solution using a callback pattern. | ||
* | ||
* The generic type parameter TxConnection extends TransactionConnection to allow for different transaction | ||
* connection implementations while maintaining type safety. | ||
*/ | ||
export interface ITransactionManager< | ||
TxConnection extends TransactionConnection = TransactionConnection, | ||
> { | ||
/* | ||
* Provides a transaction connection to the given function. | ||
* If the function throws an error, the transaction will be rolled back. | ||
* If the function returns a promise, the transaction will be committed after the promise is resolved. | ||
* | ||
* Note: only DB calls that use the provided transaction connection will be executed in the transaction. | ||
*/ | ||
runInTransaction<T>(fn: (tx: TxConnection) => Promise<T>): Promise<T>; | ||
} |
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
Oops, something went wrong.