MCPcopy
hub / github.com/pocketbase/pocketbase / validateRecordId

Function validateRecordId

core/db.go:473–499  ·  view source on GitHub ↗
(app App, collectionNameOrId string)

Source from the content-addressed store, hash-verified

471}
472
473func validateRecordId(app App, collectionNameOrId string) validation.RuleFunc {
474 return func(value any) error {
475 id, _ := value.(string)
476 if id == "" {
477 return nil
478 }
479
480 collection, err := app.FindCachedCollectionByNameOrId(collectionNameOrId)
481 if err != nil {
482 return validation.NewError("validation_invalid_collection", "Missing or invalid collection.")
483 }
484
485 var exists int
486
487 rowErr := app.ConcurrentDB().Select("(1)").
488 From(collection.Name).
489 AndWhere(dbx.HashExp{"id": id}).
490 Limit(1).
491 Row(&exists)
492
493 if rowErr != nil || exists == 0 {
494 return validation.NewError("validation_invalid_record", "Missing or invalid record.")
495 }
496
497 return nil
498 }
499}

Callers 1

recordRefHooksFunction · 0.85

Calls 3

SelectMethod · 0.80
ConcurrentDBMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…