------------------------------------------------------------------- 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)
| 480 | // |
| 481 | // Note that this method is intended to load and Scan data from a database row result. |
| 482 | func 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. |
no test coverage detected
searching dependent graphs…