1 Star 1 Fork 0

bigbase/pg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
error.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
Vladimir Mihailenco 提交于 2016-04-08 15:37 . Retry SelectOrCreate.
package pg
import (
"io"
"net"
"gopkg.in/pg.v4/internal"
)
var (
ErrNoRows = internal.ErrNoRows
ErrMultiRows = internal.ErrMultiRows
errSSLNotSupported = internal.Errorf("pg: SSL is not enabled on the server")
errClosed = internal.Errorf("pg: database is closed")
errTxDone = internal.Errorf("pg: transaction has already been committed or rolled back")
errStmtClosed = internal.Errorf("pg: statement is closed")
errListenerClosed = internal.Errorf("pg: listener is closed")
)
type Error interface {
Field(byte) string
IntegrityViolation() bool
}
var _ Error = (*internal.PGError)(nil)
func isBadConn(err error, allowTimeout bool) bool {
if err == nil {
return false
}
if _, ok := err.(internal.Error); ok {
return false
}
if pgErr, ok := err.(Error); ok && pgErr.Field('S') != "FATAL" {
return false
}
if allowTimeout {
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
return false
}
}
return true
}
func isNetworkError(err error) bool {
if err == io.EOF {
return true
}
_, ok := err.(net.Error)
return ok
}
func shouldRetry(err error) bool {
if err == nil {
return false
}
// 40001 - serialization_failure
if pgerr, ok := err.(Error); ok && pgerr.Field('C') == "40001" {
return true
}
return isNetworkError(err)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bigbase/pg.git
git@gitee.com:bigbase/pg.git
bigbase
pg
pg
v4.7.10

搜索帮助