Repo options
This commit is contained in:
@ -9,11 +9,11 @@ import (
|
||||
)
|
||||
|
||||
type ExistsMethod[T schema.Tabler] struct {
|
||||
DbConn *gorm.DB
|
||||
repo *RepoBase[T]
|
||||
}
|
||||
|
||||
func (m *ExistsMethod[T]) Init(dbConn *gorm.DB) {
|
||||
m.DbConn = dbConn
|
||||
func (m *ExistsMethod[T]) Init(repo *RepoBase[T]) {
|
||||
m.repo = repo
|
||||
}
|
||||
|
||||
func (m ExistsMethod[T]) Exists(filter interface{}) (bool, error) {
|
||||
@ -21,14 +21,14 @@ func (m ExistsMethod[T]) Exists(filter interface{}) (bool, error) {
|
||||
model T
|
||||
)
|
||||
|
||||
query := m.DbConn.Model(model)
|
||||
query := m.repo.dbConn.Model(model)
|
||||
|
||||
query, err := smartfilter.ToQuery(model, filter, query)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result := query.Select("*").First(&model)
|
||||
result := query.Select(m.repo.IdField).Take(&model)
|
||||
|
||||
exists := !errors.Is(result.Error, gorm.ErrRecordNotFound) && result.Error == nil
|
||||
return exists, nil
|
||||
|
||||
Reference in New Issue
Block a user