vendor dependencies with dep
This commit is contained in:
parent
93d8310491
commit
1384296a47
2712 changed files with 965742 additions and 0 deletions
62
vendor/github.com/go-pg/pg/internal/error.go
generated
vendored
Normal file
62
vendor/github.com/go-pg/pg/internal/error.go
generated
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var ErrNoRows = errors.New("pg: no rows in result set")
|
||||
var ErrMultiRows = errors.New("pg: multiple rows in result set")
|
||||
|
||||
type Error struct {
|
||||
s string
|
||||
}
|
||||
|
||||
func Errorf(s string, args ...interface{}) Error {
|
||||
return Error{s: fmt.Sprintf(s, args...)}
|
||||
}
|
||||
|
||||
func (err Error) Error() string {
|
||||
return err.s
|
||||
}
|
||||
|
||||
type PGError struct {
|
||||
m map[byte]string
|
||||
}
|
||||
|
||||
func NewPGError(m map[byte]string) PGError {
|
||||
return PGError{
|
||||
m: m,
|
||||
}
|
||||
}
|
||||
|
||||
func (err PGError) Field(k byte) string {
|
||||
return err.m[k]
|
||||
}
|
||||
|
||||
func (err PGError) IntegrityViolation() bool {
|
||||
switch err.Field('C') {
|
||||
case "23000", "23001", "23502", "23503", "23505", "23514", "23P01":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (err PGError) Error() string {
|
||||
return fmt.Sprintf(
|
||||
"%s #%s %s (addr=%q)",
|
||||
err.Field('S'), err.Field('C'), err.Field('M'), err.Field('a'),
|
||||
)
|
||||
}
|
||||
|
||||
func AssertOneRow(l int) error {
|
||||
switch {
|
||||
case l == 0:
|
||||
return ErrNoRows
|
||||
case l > 1:
|
||||
return ErrMultiRows
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue