mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-04-11 10:23:53 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2afee9d238 |
@@ -211,10 +211,14 @@ func (b *BunAdapter) Query(ctx context.Context, dest interface{}, query string,
|
|||||||
|
|
||||||
func (b *BunAdapter) BeginTx(ctx context.Context) (common.Database, error) {
|
func (b *BunAdapter) BeginTx(ctx context.Context) (common.Database, error) {
|
||||||
tx, err := b.getDB().BeginTx(ctx, &sql.TxOptions{})
|
tx, err := b.getDB().BeginTx(ctx, &sql.TxOptions{})
|
||||||
|
if isDBClosed(err) {
|
||||||
|
if reconnErr := b.reconnectDB(); reconnErr == nil {
|
||||||
|
tx, err = b.getDB().BeginTx(ctx, &sql.TxOptions{})
|
||||||
|
}
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// For Bun, we'll return a special wrapper that holds the transaction
|
|
||||||
return &BunTxAdapter{tx: tx, driverName: b.driverName}, nil
|
return &BunTxAdapter{tx: tx, driverName: b.driverName}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,11 +240,19 @@ func (b *BunAdapter) RunInTransaction(ctx context.Context, fn func(common.Databa
|
|||||||
err = logger.HandlePanic("BunAdapter.RunInTransaction", r)
|
err = logger.HandlePanic("BunAdapter.RunInTransaction", r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return b.getDB().RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
run := func() error {
|
||||||
// Create adapter with transaction
|
return b.getDB().RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||||
adapter := &BunTxAdapter{tx: tx, driverName: b.driverName}
|
adapter := &BunTxAdapter{tx: tx, driverName: b.driverName}
|
||||||
return fn(adapter)
|
return fn(adapter)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
err = run()
|
||||||
|
if isDBClosed(err) {
|
||||||
|
if reconnErr := b.reconnectDB(); reconnErr == nil {
|
||||||
|
err = run()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BunAdapter) GetUnderlyingDB() interface{} {
|
func (b *BunAdapter) GetUnderlyingDB() interface{} {
|
||||||
|
|||||||
Reference in New Issue
Block a user