feat: 0.0.1
This commit is contained in:
146 files changed
+10444
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
const (
|
||||
ForeignKeyViolation = "23503"
|
||||
UniqueViolation = "23505"
|
||||
CheckViolation = "23514"
|
||||
)
|
||||
|
||||
var ErrRecordNotFound = pgx.ErrNoRows
|
||||
|
||||
var ErrUniqueViolation = &pgconn.PgError{
|
||||
Code: UniqueViolation,
|
||||
}
|
||||
var ErrForeignKeyViolation = &pgconn.PgError{
|
||||
Code: ForeignKeyViolation,
|
||||
}
|
||||
var ErrCheckViolation = &pgconn.PgError{
|
||||
Code: CheckViolation,
|
||||
}
|
||||
|
||||
func ErrorCode(err error) string {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
return pgErr.Code
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in new issue
Block a user