Skip to content

Commit

Permalink
move-txn-current-check-up
Browse files Browse the repository at this point in the history
  • Loading branch information
brucecurcio committed Jan 13, 2025
1 parent d104685 commit fc0ae59
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions gorm/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func (t *Transaction) AddAfterCommitHook(hooks ...func(context.Context)) {

// getReadOnlyDBInstance returns the read only db txn if RO DB available otherwise it returns read/write db txn
func getReadOnlyDBTxn(ctx context.Context, opts *databaseOptions, txn *Transaction) (*gorm.DB, error) {
if txn.current != nil {
return txn.current, nil
}
var db *gorm.DB
switch {
case txn.parentRO == nil:
Expand All @@ -121,9 +124,6 @@ func getReadOnlyDBTxn(ctx context.Context, opts *databaseOptions, txn *Transacti
txnOpts := *opts.txOpts
txn.currentOpts.txOpts = &txnOpts
}
if txn.current != nil {
return txn.current, nil
}
db = txn.beginReadOnlyWithContextAndOptions(ctx, txn.currentOpts.txOpts)
if db.Error != nil {
return nil, db.Error
Expand All @@ -136,6 +136,9 @@ func getReadOnlyDBTxn(ctx context.Context, opts *databaseOptions, txn *Transacti

// getReadWriteDBTxn returns the read/write db txn
func getReadWriteDBTxn(ctx context.Context, opts *databaseOptions, txn *Transaction) (*gorm.DB, error) {
if txn.current != nil {
return txn.current, nil
}
var db *gorm.DB
switch {
case txn.parent == nil:
Expand All @@ -152,9 +155,6 @@ func getReadWriteDBTxn(ctx context.Context, opts *databaseOptions, txn *Transact
txnOpts := *opts.txOpts
txn.currentOpts.txOpts = &txnOpts
}
if txn.current != nil {
return txn.current, nil
}
db = txn.beginWithContextAndOptions(ctx, txn.currentOpts.txOpts)
if db.Error != nil {
return nil, db.Error
Expand Down

0 comments on commit fc0ae59

Please sign in to comment.