Document database error helpers
This commit is contained in:
parent
63b1cf1c3f
commit
ac5f74988f
1 changed files with 6 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue