mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc: support schema/blob annotation
This commit is contained in:
@@ -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 }}
|
||||
|
||||
Reference in New Issue
Block a user