@@ -12,7 +12,6 @@ import (
1212
1313 "github.com/Rican7/retry/backoff"
1414 "github.com/Rican7/retry/strategy"
15-
1615 "github.com/sirupsen/logrus"
1716)
1817
@@ -63,6 +62,7 @@ func (s Stripped) String() string {
6362}
6463
6564type ErrRetry func (error ) bool
65+ type TranslateErr func (error ) error
6666
6767type Generic struct {
6868 sync.Mutex
@@ -83,6 +83,7 @@ type Generic struct {
8383 FillSQL string
8484 InsertLastInsertIDSQL string
8585 Retry ErrRetry
86+ TranslateErr TranslateErr
8687}
8788
8889func q (sql , param string , numbered bool ) string {
@@ -308,6 +309,14 @@ func (d *Generic) IsFill(key string) bool {
308309}
309310
310311func (d * Generic ) Insert (ctx context.Context , key string , create , delete bool , createRevision , previousRevision int64 , ttl int64 , value , prevValue []byte ) (id int64 , err error ) {
312+ if d .TranslateErr != nil {
313+ defer func () {
314+ if err != nil {
315+ err = d .TranslateErr (err )
316+ }
317+ }()
318+ }
319+
311320 cVal := 0
312321 dVal := 0
313322 if create {
@@ -320,7 +329,7 @@ func (d *Generic) Insert(ctx context.Context, key string, create, delete bool, c
320329 if d .LastInsertID {
321330 row , err := d .execute (ctx , d .InsertLastInsertIDSQL , key , cVal , dVal , createRevision , previousRevision , ttl , value , prevValue )
322331 if err != nil {
323- return 00 , err
332+ return 0 , err
324333 }
325334 return row .LastInsertId ()
326335 }
0 commit comments