Add IsRecordNotFoundError method

This commit is contained in:
Jinzhu 2018-02-12 09:38:16 +08:00
parent 0cc4d47ce5
commit c54d23473c
2 changed files with 14 additions and 2 deletions

View File

@ -24,11 +24,11 @@ The fantastic ORM library for Golang, aims to be developer friendly.
## Getting Started
* GORM Guides [jinzhu.github.com/gorm](http://jinzhu.github.io/gorm)
* GORM Guides [jinzhu.github.com/gorm](https://jinzhu.github.io/gorm)
## Upgrading To V1.0
* [CHANGELOG](http://jinzhu.github.io/gorm/changelog.html)
* [CHANGELOG](https://jinzhu.github.io/gorm/changelog.html)
## Supporting the project

View File

@ -21,6 +21,18 @@ var (
// Errors contains all happened errors
type Errors []error
// IsRecordNotFoundError returns current error has record not found error or not
func IsRecordNotFoundError(err error) bool {
if errs, ok := err.(Errors); ok {
for _, err := range errs {
if err == ErrRecordNotFound {
return true
}
}
}
return err == ErrRecordNotFound
}
// GetErrors gets all happened errors
func (errs Errors) GetErrors() []error {
return errs