This commit is contained in:
jdl 2024-11-17 15:18:05 +01:00
parent 84bc5e48e8
commit 5d442fa681
3 changed files with 10 additions and 2 deletions

View File

@ -14,7 +14,7 @@ func ErrIsForeignKey(err error) bool {
return ErrHasCode(err, "23503")
}
func ErrIsSerializationFaiilure(err error) bool {
func ErrIsSerializationFailure(err error) bool {
return ErrHasCode(err, "40001")
}

View File

@ -60,7 +60,7 @@ func (r SerialTxRunner) WithTx(db *sql.DB, fn func(*sql.Tx) error) error {
if err == nil {
return nil
}
if timeout > r.MaxTimeout || !ErrIsSerializationFaiilure(err) {
if timeout > r.MaxTimeout || !ErrIsSerializationFailure(err) {
return err
}
sleepTimeout := timeout + time.Duration(rand.Int63n(int64(timeout/10)))

8
sqliteutil/errors.go Normal file
View 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
}