aboutsummaryrefslogblamecommitdiff
path: root/db/errors.go
blob: ed5f371a73d07ca77e20c84e2ee1471df14620ca (plain) (tree)






















                                                        
package db

import (
	"strings"

	"github.com/go-pg/pg"
)

func PGCode(err error) string {
	if _, ok := err.(pg.Error); !ok {
		return ""
	}

	return err.(pg.Error).Field('C')
}

func IsDup(err error) bool {
	return PGCode(err) == "23505"
}

func IsSQLError(err error) bool {
	return strings.HasPrefix(err.Error(), "ERROR #")
}