github.com/mailru/activerecord@v1.12.2/internal/pkg/generator/tmpl/fixture_meta.tmpl (about) 1 package {{ .FixturePkg }} 2 3 import ( 4 "context" 5 "fmt" 6 ) 7 8 type FixtureMeta struct { 9 StoreIterator func(it func(any) error) error 10 Unpacker func(ctx context.Context, source []byte) (res []any, err error) 11 PrimaryKeyFields []string 12 } 13 14 // NSFixtures Репозиторий сторов фикстур 15 type NSFixtures map[string]FixtureMeta 16 17 {{ $nss := .Namespaces }} 18 var NamespaceFixtures = NSFixtures{ 19 {{ range $_, $ns := $nss -}} 20 {{- if $ns.Fields }} 21 "{{ $ns.Namespace.ObjectName }}": FixtureMeta{ 22 StoreIterator:{{ $ns.Namespace.PublicName }}StoreIterator(), 23 Unpacker: func(ctx context.Context, source []byte) (res []any, err error) { 24 fxts, err := {{ $ns.Namespace.PackageName }}.UnmarshalFixtures(source) 25 if err != nil { 26 return nil, fmt.Errorf("can't decode tuple: %s", err) 27 } 28 29 for _, v := range fxts { 30 res = append(res, v) 31 } 32 33 return 34 }, 35 PrimaryKeyFields: []string{ 36 {{- if $ns.Indexes }} 37 {{- $pk := index $ns.Indexes 0 }} 38 {{- range $_, $fieldNum := $pk.Fields }} 39 {{- $ifield := index $ns.Fields $fieldNum }} 40 "{{$ifield.Name}}", 41 {{- end }} 42 {{ end -}} 43 }, 44 }, 45 {{ end }} 46 {{ end }} 47 }