func NewForeignKeyMapping(c string, t1 string, t2 string) errors.MapFunc {
	return errors.NewMapping(
		errors.CondAnd(
			CondCodeEq("23503"),
			CondConstraintEq(c),
		),
		errors.NewContainer(codes.InvalidArgument, msgForeignKeyViolation, t1, t2),
	)
}
NewForeignKeyMapping function returns a mapping function that performs
mapping of a constraint name (c) to specific foreign key message with
user-friendly referencing (t1) and referenced (t2) table names provided.
package pqerrors
import (
	"context"
	"github.com/lib/pq"
	"google.golang.org/grpc/codes"
	"github.com/infobloxopen/atlas-app-toolkit/errors"
)
const (
	msgForeignKeyViolation = "Cannot insert object '%s' as it does not refer to a valid '%s' object."
	msgRestrictViolation   = "Cannot update or delete an object '%s' as it is referenced by a '%s' object."
	msgNotNullViolation    = "The '%s' field for the '%s' object cannot be empty."
	msgUniqueViolation     = "There is already an existing '%s' object with the same '%s'."
)
func ToMapFunc(f func(context.Context, *pq.Error) (error, bool)) errors.MapFunc {
	return func(ctx context.Context, err error) (error, bool) {
		if pqErr, ok := err.(*pq.Error); ok {
			return f(ctx, pqErr)
		}
		return err, false
	}
}
func CondPQ() errors.MapCond {
	return func(err error) bool {
		_, ok := err.(*pq.Error)
		return ok
	}
}
func CondConstraintEq(c string) errors.MapCond {
	return func(err error) bool {
		if pqErr, ok := err.(*pq.Error); ok {
			if pqErr.Constraint == c {
				return true
			}
		}
		return false
	}
}
func CondCodeEq(code string) errors.MapCond {
	return func(err error) bool {
		if pqErr, ok := err.(*pq.Error); ok {
			if string(pqErr.Code) == code {
				return true
			}
		}
		return false
	}
}