This commit is contained in:
Eden Kirin
2024-06-25 00:49:13 +02:00
parent ff51420b71
commit c2bcbea5d2
3 changed files with 75 additions and 4 deletions

View File

@ -8,7 +8,8 @@ import (
)
type GetOptions struct {
Only *[]string
Only *[]string
RaiseError *bool
}
type GetMethod[T schema.Tabler] struct {
@ -34,9 +35,12 @@ func (m GetMethod[T]) Get(filter interface{}, options *GetOptions) (*T, error) {
}
result := query.First(&model)
if result.Error != nil {
return nil, result.Error
if result.Error == nil {
return &model, nil
}
return &model, nil
if options != nil && options.RaiseError != nil && *options.RaiseError {
return nil, result.Error
}
return nil, nil
}