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

Function Store

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

Store writes the values of the fields of the target struct to the accessor. Nil slice and map fields are skipped and do not overwrite existing accessor values.

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

Source from the content-addressed store, hash-verified

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.
46func Store(target interface{}, accessor Accessor, options StoreOptions) error {
47 return forEachField(target, func(tag *fieldTag, field reflect.Value) error {
48 if !tag.matchesStore(options) {
49 return nil
50 }
51
52 var accessorValue interface{}
53
54 if tag.isPtr {
55 if field.IsNil() {
56 return nil
57 }
58
59 accessorValue = field.Elem().Interface()
60 } else {
61 if field.Kind() == reflect.Slice || field.Kind() == reflect.Map {
62 if field.IsNil() {
63 return nil
64 }
65 }
66
67 accessorValue = field.Interface()
68 }
69
70 err := accessor.Set(FieldSet{
71 Path: tag.path, Value: accessorValue, Type: tag.fType,
72 CreateKey: tag.createKey,
73 })
74
75 if err != nil {
76 return err
77 }
78
79 return nil
80 },
81 )
82}
83
84func forEachField(target interface{}, fn func(tag *fieldTag, field reflect.Value) error) error {
85 value := reflect.Indirect(

Callers 6

StoreYamlFunction · 0.85
StoreJSONFunction · 0.85
TestStore_NilMapSkipsSetFunction · 0.85

Calls 3

forEachFieldFunction · 0.85
matchesStoreMethod · 0.80
SetMethod · 0.65