diff --git a/pgutil/errors.go b/pgutil/errors.go index ec26f75..fce709d 100644 --- a/pgutil/errors.go +++ b/pgutil/errors.go @@ -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") } diff --git a/pgutil/tx.go b/pgutil/tx.go index 9d7156f..ceb7985 100644 --- a/pgutil/tx.go +++ b/pgutil/tx.go @@ -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))) diff --git a/sqliteutil/errors.go b/sqliteutil/errors.go new file mode 100644 index 0000000..b0db407 --- /dev/null +++ b/sqliteutil/errors.go @@ -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 +}