entc/hooks: initial work for mutations and hooks (#377)

* entc/hooks: initial work for mutations and hooks

* ent/schema: adding policy to schema

* ent: change op string to uint

* entc: move entschema to runtime and enable smooth transition

* entc/privacy: adding privacy template

* all: goimports

* intg/hooks: mutation client/tx and basic schema tests

* ent/privacy: adding more verbose decisions

* entc/gen: edge-ids getter and additional tests

* all: regen assets

* entc/gen: fix client hookd propagation

* intg: add deletion example

* intg/privacy: remove old entschema package

* typed privacy

* ent/privacy: hooks shouldn't be called on privacy deny

* entc/gen: fix schema hooks invocation order

* remove read policy from public api

* update circleci go orb

Co-authored-by: Ariel Mashraki <ariel@mashraki.co.il>
This commit is contained in:
Ariel Mashraki
2020-03-16 00:19:27 +02:00
committed by GitHub
parent 2a7183eb82
commit 7988d3084d
549 changed files with 62895 additions and 10774 deletions

View File

@@ -7,6 +7,7 @@ in the LICENSE file in the root directory of this source tree.
{{ define "dialect/sql/create" }}
{{ $builder := pascal $.Scope.Builder }}
{{ $receiver := receiver $builder }}
{{ $mutation := print $receiver ".mutation" }}
func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name }}, error) {
var (
@@ -20,23 +21,23 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name
}
)
{{- if $.ID.UserDefined }}
if value := {{ $receiver }}.{{ $.ID.BuilderField }}; value != nil {
{{ $.Receiver }}.ID = *value
_spec.ID.Value = *value
if id, ok := {{ $mutation }}.{{ $.ID.MutationGet }}(); ok {
{{ $.Receiver }}.ID = id
_spec.ID.Value = id
}
{{- end }}
{{- range $_, $f := $.Fields }}
if value := {{ $receiver }}.{{ $f.BuilderField }}; value != nil {
if value, ok := {{ $mutation }}.{{ $f.MutationGet }}(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.{{ $f.Type.ConstName }},
Value: *value,
Value: value,
Column: {{ $.Package }}.{{ $f.Constant }},
})
{{ $.Receiver }}.{{ $f.StructField }} = {{ if not $f.Nillable }}*{{ end }}value
{{ $.Receiver }}.{{ $f.StructField }} = {{ if $f.Nillable }}&{{ end }}value
}
{{- end }}
{{- range $_, $e := $.Edges }}
if nodes := {{ $receiver }}.{{ $e.BuilderField }}; len(nodes) > 0 {
if nodes := {{ $mutation }}.{{ $e.StructField }}IDs(); len(nodes) > 0 {
{{- with extend $ "Edge" $e "Nodes" true "Zero" "nil" }}
{{ template "dialect/sql/defedge" . }}{{/* defined in sql/update.tmpl */}}
{{- end }}