diff --git a/actions/common/comments.go b/actions/common/comments.go index 6d27be7..09d7867 100644 --- a/actions/common/comments.go +++ b/actions/common/comments.go @@ -62,9 +62,9 @@ func GetCommentByIds(ctx context.Context, ids []uint64) ([]models.WpComments, er func getCommentByIds(args ...any) (map[uint64]models.WpComments, error) { ids := args[0].([]uint64) m := make(map[uint64]models.WpComments) - r, err := models.Find[models.WpComments](models.SqlBuilder{ + r, err := models.SimpleFind[models.WpComments](models.SqlBuilder{ {"comment_ID", "in", ""}, {"comment_approved", "1"}, - }, "*", "", nil, nil, nil, 0, helper.SliceMap(ids, helper.ToAny[uint64])) + }, "*", helper.SliceMap(ids, helper.ToAny[uint64])) if err != nil { return m, err } diff --git a/actions/common/posts.go b/actions/common/posts.go index 85e3a6d..1c70b1d 100644 --- a/actions/common/posts.go +++ b/actions/common/posts.go @@ -109,7 +109,7 @@ func searchPostIds(args ...any) (ids PostIds, err error) { } func getMaxPostId(...any) ([]uint64, error) { - r, err := models.Find[models.WpPosts](models.SqlBuilder{{"post_type", "post"}, {"post_status", "publish"}}, "max(ID) ID", "", nil, nil, nil, 0) + r, err := models.SimpleFind[models.WpPosts](models.SqlBuilder{{"post_type", "post"}, {"post_status", "publish"}}, "max(ID) ID") var id uint64 if len(r) > 0 { id = r[0].Id diff --git a/actions/common/users.go b/actions/common/users.go index 288942c..a553b44 100644 --- a/actions/common/users.go +++ b/actions/common/users.go @@ -9,7 +9,7 @@ import ( func getUsers(...any) (m map[uint64]models.WpUsers, err error) { m = make(map[uint64]models.WpUsers) - r, err := models.Find[models.WpUsers](nil, "*", "", nil, nil, nil, 0) + r, err := models.SimpleFind[models.WpUsers](nil, "*") for _, user := range r { m[user.Id] = user } diff --git a/models/globalInit.go b/models/globalInit.go index 31c90d9..0e9be1f 100644 --- a/models/globalInit.go +++ b/models/globalInit.go @@ -22,14 +22,14 @@ func InitOptions() error { } func InitTerms() (err error) { - terms, err := Find[WpTerms](nil, "*", "", nil, nil, nil, 0) + terms, err := SimpleFind[WpTerms](nil, "*") if err != nil { return err } for _, wpTerms := range terms { Terms[wpTerms.TermId] = wpTerms } - termTax, err := Find[WpTermTaxonomy](nil, "*", "", nil, nil, nil, 0) + termTax, err := SimpleFind[WpTermTaxonomy](nil, "*") if err != nil { return err } diff --git a/models/model.go b/models/model.go index 5bd783e..bdc06fd 100644 --- a/models/model.go +++ b/models/model.go @@ -297,9 +297,14 @@ func LastOne[T Model](where ParseWhere, fields string, in ...[]any) (T, error) { func SimpleFind[T Model](where ParseWhere, fields string, in ...[]any) ([]T, error) { var r []T var rr T - w, args, err := where.ParseWhere(&in) - if err != nil { - return r, err + var err error + args := make([]any, 0, 0) + var w string + if where != nil { + w, args, err = where.ParseWhere(&in) + if err != nil { + return r, err + } } tp := "select %s from %s %s" sql := fmt.Sprintf(tp, fields, rr.Table(), w)