diff --git a/internal/database/db.go b/internal/database/db.go index 7786e09..789d2af 100644 --- a/internal/database/db.go +++ b/internal/database/db.go @@ -18,10 +18,14 @@ func New(dsn string) (*sqlx.DB, error) { return conn, err } +// IsErrNoRows returns true if the error indicates that no rows were +// returned from the database. func IsErrNoRows(err error) bool { return err == sql.ErrNoRows } +// IsErrUniqueViolation returns true if the error indicates that a UNIQUE +// constraint violation has occured. func IsErrUniqueViolation(err error) bool { // see if we can cast the error to a Database error type pqErr, ok := err.(*pq.Error) @@ -38,6 +42,8 @@ func IsErrUniqueViolation(err error) bool { return true } +// IsErrForeignKeyViolation returns true if the error indicates that a +// FOREIGN KEY constraint has been violated due to the requested changes. func IsErrForeignKeyViolation(err error) bool { // see if we can cast the error to a Database error type pqErr, ok := err.(*pq.Error)