aboutsummaryrefslogtreecommitdiff
path: root/db/errors.go
blob: ed5f371a73d07ca77e20c84e2ee1471df14620ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 #")
}