feat: port lab4 implementation
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
const (
|
||||
CodeUniqueViolation = "23505"
|
||||
CodeForeignKeyViolation = "23503"
|
||||
CodeCheckViolation = "23514"
|
||||
)
|
||||
|
||||
func ErrCode(err error) string {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
return pgErr.Code
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func IsNotFound(err error) bool {
|
||||
return errors.Is(err, pgx.ErrNoRows)
|
||||
}
|
||||
Reference in New Issue
Block a user