MCPcopy Create free account
hub / github.com/postgres-ai/database-lab-engine / Load

Function Load

engine/pkg/util/projection/operations.go:12–42  ·  view source on GitHub ↗

Load reads the values of the fields of the target struct from the accessor.

(target interface{}, accessor Accessor, options LoadOptions)

Source from the content-addressed store, hash-verified

10
11// Load reads the values of the fields of the target struct from the accessor.
12func Load(target interface{}, accessor Accessor, options LoadOptions) error {
13 return forEachField(target, func(tag *fieldTag, field reflect.Value) error {
14 if !tag.matchesLoad(options) {
15 return nil
16 }
17
18 accessorValue, err := accessor.Get(FieldGet{
19 Path: tag.path, Type: tag.fType,
20 })
21 if err != nil {
22 return err
23 }
24
25 if accessorValue == nil {
26 field.Set(reflect.Zero(field.Type()))
27 return nil
28 }
29
30 if tag.isPtr {
31 setValue := ptypes.NewPtr(accessorValue)
32 if setValue.IsValid() {
33 field.Set(setValue)
34 }
35 } else {
36 field.Set(reflect.ValueOf(accessorValue))
37 }
38
39 return nil
40 },
41 )
42}
43
44// Store writes the values of the fields of the target struct to the accessor.
45// Nil slice and map fields are skipped and do not overwrite existing accessor values.

Callers 2

LoadYamlFunction · 0.70
LoadJSONFunction · 0.70

Calls 4

forEachFieldFunction · 0.85
matchesLoadMethod · 0.80
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected