entc: support schema/blob annotation

This commit is contained in:
Giau. Tran Minh
2026-05-03 18:00:38 +00:00
parent 665007afec
commit 7a21ec2e29
37 changed files with 1611 additions and 417 deletions

View File

@@ -187,6 +187,30 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (_node {{ if
return {{ $zero }}, err
}
{{ $mutation }}.done = true
{{- if and $one $.HasBlobFields }}
{{- range $f := $.BlobFields }}
if data, ok := {{ $mutation }}.{{ $f.StructField }}(); ok {
b, err := {{ $mutation }}.blobOpeners.{{ $.Name }}(ctx, {{ $.Package }}.{{ $f.Constant }})
if err != nil {
return nil, fmt.Errorf("{{ $pkg }}: opening blob bucket for {{ $f.Name }}: %w", err)
}
key, err := _node.{{ $f.StructField }}Key(ctx)
if err != nil {
return nil, errors.Join(fmt.Errorf("{{ $pkg }}: blob key for {{ $f.Name }}: %w", err), b.Close())
}
w, err := b.NewWriter(ctx, key)
if err != nil {
return nil, errors.Join(fmt.Errorf("{{ $pkg }}: creating writer for {{ $f.Name }}: %w", err), b.Close())
}
if _, err := w.Write(data); err != nil {
return nil, errors.Join(fmt.Errorf("{{ $pkg }}: writing blob for {{ $f.Name }}: %w", err), w.Close(), b.Close())
}
if err := errors.Join(w.Close(), b.Close()); err != nil {
return nil, fmt.Errorf("{{ $pkg }}: closing blob for {{ $f.Name }}: %w", err)
}
}
{{- end }}
{{- end }}
return _node, nil
}
{{ end }}