wip
This commit is contained in:
parent
84bc5e48e8
commit
5d442fa681
@ -14,7 +14,7 @@ func ErrIsForeignKey(err error) bool {
|
|||||||
return ErrHasCode(err, "23503")
|
return ErrHasCode(err, "23503")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrIsSerializationFaiilure(err error) bool {
|
func ErrIsSerializationFailure(err error) bool {
|
||||||
return ErrHasCode(err, "40001")
|
return ErrHasCode(err, "40001")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func (r SerialTxRunner) WithTx(db *sql.DB, fn func(*sql.Tx) error) error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if timeout > r.MaxTimeout || !ErrIsSerializationFaiilure(err) {
|
if timeout > r.MaxTimeout || !ErrIsSerializationFailure(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sleepTimeout := timeout + time.Duration(rand.Int63n(int64(timeout/10)))
|
sleepTimeout := timeout + time.Duration(rand.Int63n(int64(timeout/10)))
|
||||||
|
8
sqliteutil/errors.go
Normal file
8
sqliteutil/errors.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package sqliteutil
|
||||||
|
|
||||||
|
import "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
|
func ErrIsDuplicate(err error) bool {
|
||||||
|
e, ok := err.(sqlite3.Error)
|
||||||
|
return ok && e.Code == 19
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user