MCPcopy
hub / github.com/pocketbase/pocketbase / FindFirstRecordByData

Method FindFirstRecordByData

core/record_query.go:316–338  ·  view source on GitHub ↗

FindFirstRecordByData returns the first found record matching the provided key-value pair.

(collectionModelOrIdentifier any, key string, value any)

Source from the content-addressed store, hash-verified

314// FindFirstRecordByData returns the first found record matching
315// the provided key-value pair.
316func (app *BaseApp) FindFirstRecordByData(collectionModelOrIdentifier any, key string, value any) (*Record, error) {
317 collection, err := getCollectionByModelOrIdentifier(app, collectionModelOrIdentifier)
318 if err != nil {
319 return nil, err
320 }
321
322 field := collection.Fields.GetByName(key)
323 if field == nil {
324 return nil, errors.New("invalid or missing field " + key)
325 }
326
327 record := &Record{}
328
329 err = app.RecordQuery(collection).
330 AndWhere(dbx.HashExp{inflector.Columnify(key): value}).
331 Limit(1).
332 One(record)
333 if err != nil {
334 return nil, err
335 }
336
337 return record, nil
338}
339
340// FindRecordsByFilter returns limit number of records matching the
341// provided string filter.

Callers

nothing calls this directly

Calls 4

RecordQueryMethod · 0.95
ColumnifyFunction · 0.92
GetByNameMethod · 0.80

Tested by

no test coverage detected