1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
{{/*
Copyright 2019-present Facebook Inc. All rights reserved.
This source code is licensed under the Apache 2.0 license found
in the LICENSE file in the root directory of this source tree.
*/}}
{{ define "dialect/sql/predicate/id" -}}
func(s *sql.Selector) {
s.Where(sql.EQ(s.C({{ $.ID.Constant }}), id))
}
{{- end }}
{{ define "dialect/sql/predicate/id/ops" -}}
{{- $op := $.Scope.Op -}}
{{- $arg := $.Scope.Arg -}}
{{- $storage := $.Scope.Storage -}}
func(s *sql.Selector) {
{{- if $op.Variadic }}
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len({{ $arg }}) == 0 {
s.Where(sql.False())
return
}
v := make([]interface{}, len({{ $arg }}))
for i := range v {
v[i] = {{ $arg }}[i]
}
{{- end }}
s.Where(sql.{{ call $storage.OpCode $op }}(s.C({{ $.ID.Constant }}){{ if not $op.Niladic }},{{ if $op.Variadic }}v...{{ else }}id{{ end }}{{ end }}))
}
{{- end }}
{{ define "dialect/sql/predicate/field" -}}
{{- $f := $.Scope.Field -}}
{{- $arg := $.Scope.Arg -}}
func(s *sql.Selector) {
s.Where(sql.EQ(s.C({{ $f.Constant }}), {{ $arg }}))
}
{{- end }}
{{ define "dialect/sql/predicate/field/ops" -}}
{{- $f := $.Scope.Field -}}
{{- $op := $.Scope.Op -}}
{{- $arg := $.Scope.Arg -}}
{{- $storage := $.Scope.Storage -}}
func(s *sql.Selector) {
{{- if $op.Variadic }}
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len({{ $arg }}) == 0 {
s.Where(sql.False())
return
}
{{- end }}
s.Where(sql.{{ call $storage.OpCode $op }}(s.C({{ $f.Constant }}){{ if not $op.Niladic }}, {{ $arg }}{{ if $op.Variadic }}...{{ end }}{{ end }}))
}
{{- end }}
{{ define "dialect/sql/predicate/edge/has" -}}
{{- $e := $.Scope.Edge -}}
{{- $refid := $.ID.Constant }}{{ if ne $e.Type.ID.StorageKey $.ID.StorageKey }}{{ $refid = print $e.Type.Name "FieldID" }}{{ end -}}
func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, {{ $.ID.Constant }}),
sqlgraph.To({{ $e.TableConstant }}, {{ $refid }}),
sqlgraph.Edge(sqlgraph.{{ $e.Rel.Type }}, {{ $e.IsInverse }}, {{ $e.TableConstant }},
{{- if $e.M2M -}}
{{ $e.PKConstant }}...
{{- else -}}
{{ $e.ColumnConstant }}
{{- end -}}
),
)
sqlgraph.HasNeighbors(s, step)
}
{{- end }}
{{ define "dialect/sql/predicate/edge/haswith" -}}
{{- $e := $.Scope.Edge -}}
{{- $refid := $.ID.Constant }}{{ if ne $e.Type.ID.StorageKey $.ID.StorageKey }}{{ $refid = print $e.Type.Name "FieldID" }}{{ end -}}
func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, {{ $.ID.Constant }}),
sqlgraph.To({{ if ne $.Table $e.Type.Table }}{{ $e.InverseTableConstant }}{{ else }}Table{{ end }}, {{ $refid }}),
sqlgraph.Edge(sqlgraph.{{ $e.Rel.Type }}, {{ $e.IsInverse }}, {{ $e.TableConstant }},
{{- if $e.M2M -}}
{{ $e.PKConstant }}...
{{- else -}}
{{ $e.ColumnConstant }}
{{- end -}}
),
)
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
}
{{- end }}
{{ define "dialect/sql/predicate/and" -}}
func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
}
{{- end }}
{{ define "dialect/sql/predicate/or" -}}
func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
p(s1)
}
s.Where(s1.P())
}
{{- end }}
{{ define "dialect/sql/predicate/not" -}}
func(s *sql.Selector) {
p(s.Not())
}
{{- end }}
|