@@ -31,20 +31,13 @@ func (r *RetryExecutor) Do(
3131 fn func (ctx context.Context , drv dialect.Driver ) error ,
3232 opts ... any ,
3333) error {
34- retryOpts := make ([]retry.Option , 0 , len (opts ))
35- for _ , opt := range opts {
36- if ro , ok := opt .(retry.Option ); ok {
37- retryOpts = append (retryOpts , ro )
38- }
39- }
40-
4134 return retry .Do (
4235 ctx ,
4336 r .db ,
4437 func (ctx context.Context , conn * sql.Conn ) error {
4538 return fn (ctx , NewRetryDriver (conn ))
4639 },
47- retry .WithDoRetryOptions (retryOpts ... ),
40+ retry .WithDoRetryOptions (toRetryOptions ( opts ) ... ),
4841 )
4942}
5043
@@ -56,23 +49,27 @@ func (r *RetryExecutor) DoTx(
5649 fn func (ctx context.Context , drv dialect.Driver ) error ,
5750 opts ... any ,
5851) error {
59- retryOpts := make ([]retry.Option , 0 , len (opts ))
60- for _ , opt := range opts {
61- if ro , ok := opt .(retry.Option ); ok {
62- retryOpts = append (retryOpts , ro )
63- }
64- }
65-
6652 return retry .DoTx (
6753 ctx ,
6854 r .db ,
6955 func (ctx context.Context , tx * sql.Tx ) error {
7056 return fn (ctx , NewTxRetryDriver (tx ))
7157 },
72- retry .WithDoTxRetryOptions (retryOpts ... ),
58+ retry .WithDoTxRetryOptions (toRetryOptions ( opts ) ... ),
7359 )
7460}
7561
62+ // toRetryOptions converts a slice of any options to retry.Option slice
63+ func toRetryOptions (opts []any ) []retry.Option {
64+ retryOpts := make ([]retry.Option , 0 , len (opts ))
65+ for _ , opt := range opts {
66+ if ro , ok := opt .(retry.Option ); ok {
67+ retryOpts = append (retryOpts , ro )
68+ }
69+ }
70+ return retryOpts
71+ }
72+
7673// RetryDriver is designed for use only in sqlgraph,
7774// specifically - in retry.DoTx callbacks
7875type RetryDriver struct {
0 commit comments