Only option
This commit is contained in:
@ -7,6 +7,10 @@ import (
|
||||
"gorm.io/gorm/schema"
|
||||
)
|
||||
|
||||
type GetOptions struct {
|
||||
Only *[]string
|
||||
}
|
||||
|
||||
type GetMethod[T schema.Tabler] struct {
|
||||
DbConn *gorm.DB
|
||||
}
|
||||
@ -15,7 +19,7 @@ func (m *GetMethod[T]) Init(dbConn *gorm.DB) {
|
||||
m.DbConn = dbConn
|
||||
}
|
||||
|
||||
func (m GetMethod[T]) Get(filter interface{}) (*T, error) {
|
||||
func (m GetMethod[T]) Get(filter interface{}, options *GetOptions) (*T, error) {
|
||||
var (
|
||||
model T
|
||||
)
|
||||
@ -25,6 +29,10 @@ func (m GetMethod[T]) Get(filter interface{}) (*T, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
query = applyOptionOnly(query, options.Only)
|
||||
}
|
||||
|
||||
result := query.First(&model)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
|
||||
Reference in New Issue
Block a user