MCPcopy Index your code
hub / github.com/pocketbase/pocketbase / newRecordFromNullStringMap

Function newRecordFromNullStringMap

core/record_model.go:482–516  ·  view source on GitHub ↗

------------------------------------------------------------------- newRecordFromNullStringMap initializes a single new Record model with data loaded from the provided NullStringMap. Note that this method is intended to load and Scan data from a database row result.

(collection *Collection, data dbx.NullStringMap)

Source from the content-addressed store, hash-verified

480//
481// Note that this method is intended to load and Scan data from a database row result.
482func newRecordFromNullStringMap(collection *Collection, data dbx.NullStringMap) (*Record, error) {
483 record := NewRecord(collection)
484
485 var fieldName string
486 for _, field := range collection.Fields {
487 fieldName = field.GetName()
488
489 nullString, ok := data[fieldName]
490
491 var value any
492 var err error
493
494 if ok && nullString.Valid {
495 value, err = field.PrepareValue(record, nullString.String)
496 } else {
497 value, err = field.PrepareValue(record, nil)
498 }
499
500 if err != nil {
501 return nil, err
502 }
503
504 // we load only the original data to avoid unnecessary copying the same data into the record.data store
505 // (it is also the reason why we don't invoke PostScan on the record itself)
506 record.originalData[fieldName] = value
507
508 if fieldName == FieldNameId {
509 record.Id = cast.ToString(value)
510 }
511 }
512
513 record.BaseModel.PostScan()
514
515 return record, nil
516}
517
518// newRecordsFromNullStringMaps initializes a new Record model for
519// each row in the provided NullStringMap slice.

Callers 2

resolveRecordOneHookFunction · 0.85

Calls 4

NewRecordFunction · 0.85
GetNameMethod · 0.65
PrepareValueMethod · 0.65
PostScanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…