MCPcopy
hub / github.com/pocketbase/pocketbase / Exec

Method Exec

tools/search/provider.go:229–359  ·  view source on GitHub ↗

Exec executes the search provider and fills/scans the provided `items` slice with the found models.

(items any)

Source from the content-addressed store, hash-verified

227// Exec executes the search provider and fills/scans
228// the provided `items` slice with the found models.
229func (s *Provider) Exec(items any) (*Result, error) {
230 if s.query == nil {
231 return nil, ErrEmptyQuery
232 }
233
234 // shallow clone the provider's query
235 modelsQuery := *s.query
236
237 // build filters
238 for _, f := range s.filter {
239 if len(f) > MaxFilterLength {
240 return nil, ErrFilterLengthLimit
241 }
242 expr, err := f.BuildExprWithLimit(s.fieldResolver, s.maxFilterExprLimit)
243 if err != nil {
244 return nil, err
245 }
246 if expr != nil {
247 modelsQuery.AndWhere(expr)
248 }
249 }
250
251 // apply sorting
252 if len(s.sort) > s.maxSortExprLimit {
253 return nil, ErrSortExprLimit
254 }
255 for _, sortField := range s.sort {
256 if len(sortField.Name) > MaxSortFieldLength {
257 return nil, ErrSortFieldLengthLimit
258 }
259 expr, err := sortField.BuildExpr(s.fieldResolver)
260 if err != nil {
261 return nil, err
262 }
263 if expr != "" {
264 // ensure that _rowid_ expressions are always prefixed with the first FROM table
265 if sortField.Name == rowidSortKey && !strings.Contains(expr, ".") {
266 queryInfo := modelsQuery.Info()
267 if len(queryInfo.From) > 0 {
268 expr = "[[" + inflector.Columnify(queryInfo.From[0]) + "]]." + expr
269 }
270 }
271
272 modelsQuery.AndOrderBy(expr)
273 }
274 }
275
276 // apply field resolver query modifications (if any)
277 if err := s.fieldResolver.UpdateQuery(&modelsQuery); err != nil {
278 return nil, err
279 }
280
281 // normalize page
282 if s.page <= 0 {
283 s.page = 1
284 }
285
286 // normalize perPage

Callers 5

ParseAndExecMethod · 0.95
execveFunction · 0.80

Calls 6

ColumnifyFunction · 0.92
AliasOrIdentifierFunction · 0.92
BuildExprWithLimitMethod · 0.80
SelectMethod · 0.80
UpdateQueryMethod · 0.65
BuildExprMethod · 0.45

Tested by 3