func WithTxn(fn func(tx *sqlx.Tx) error) error {
	ctx := context.TODO()
	tx := DB.MustBeginTx(ctx, nil)

	var err error
	defer func() {
		if p := recover(); p != nil {
			// a panic occurred, rollback and repanic
			if err := tx.Rollback(); err != nil {
				logger.Warnf("failure when performing transaction rollback: %v", err)
			}
			panic(p)
		}

		if err != nil {
			// something went wrong, rollback
			if err := tx.Rollback(); err != nil {
				logger.Warnf("failure when performing transaction rollback: %v", err)
			}
		} else {
			// all good, commit
			err = tx.Commit()
		}
	}()

	err = fn(tx)
	return err
}
// WithTxn executes the provided function within a transaction. It rolls back
// the transaction if the function returns an error, otherwise the transaction
// is committed.
WithTxn executes the provided function within a transaction. It rolls back
the transaction if the function returns an error, otherwise the transaction
is committed.
// WithTxn executes the provided function within a transaction . It rolls back // the transaction if the function returns an error otherwise the transaction // is committed .
func WithTxn(fn func(tx *sqlx.Tx) error) error {
	ctx := context.TODO()
	tx := DB.MustBeginTx(ctx, nil)
	var err error
	defer func() {
		if p := recover(); p != nil {
			if err := tx.Rollback(); err != nil {
				logger.Warnf("failure when performing transaction rollback: %v", err)
			}
			panic(p)
		}
		if err != nil {
			if err := tx.Rollback(); err != nil {
				logger.Warnf("failure when performing transaction rollback: %v", err)
			}
		} else {
			err = tx.Commit()
		}
	}()
	err = fn(tx)
	return err
}
func WithTxn ( fn func ( tx * sqlx . Tx ) error ) error { ctx := context . TODO ( ) tx := DB . MustBeginTx ( ctx , nil ) var err error defer func ( ) { if p := recover ( ) ; p != nil { if err := tx . Rollback ( ) ; err != nil { logger . Warnf ( " " , err ) } panic ( p ) } if err != nil { if err := tx . Rollback ( ) ; err != nil { logger . Warnf ( " " , err ) } } else { err = tx . Commit ( ) } } ( ) err = fn ( tx ) return err }
WithTxn executes the provided function within a transaction.
WithTxn executes the provided function within a transaction .
// a panic occurred, rollback and repanic // something went wrong, rollback // all good, commit