Files
ent/entc/gen/template/predicate.tmpl
Ariel Mashraki e0e754717e ent: change ent package name (#1338)
Summary:
Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1338

Pull Request resolved: https://github.com/facebookincubator/ent/pull/14

Reviewed By: alexsn

Differential Revision: D16890825

fbshipit-source-id: 656baaa73f5debab08c849b6b9639caeec2a8ef1
2019-08-19 09:32:14 -07:00

34 lines
1017 B
Cheetah

{{ define "predicate" }}
{{- with extend $ "Package" "predicate" -}}
{{ template "header" . }}
{{ end }}
import (
"fmt"
"github.com/facebookincubator/ent/dialect/gremlin/graph/dsl"
"github.com/facebookincubator/ent/dialect/sql"
)
{{ range $_, $n := $.Nodes -}}
// {{ $n.Name }} is the predicate function for {{ $n.Package }} builders.
type {{ $n.Name }} func({{ if gt (len $.Storage) 1 }}interface{}{{ else }}{{ (index $.Storage 0).Builder }}{{ end }})
{{ if gt (len $.Storage) 1 }}
// {{ $n.Name }}PerDialect construct a predicate for graph traversals based on dialect type.
func {{ $n.Name }}PerDialect({{ range $i, $storage := $.Storage }}{{ if $i }},{{ end }}f{{ $i }} func({{ $storage.Builder }}){{ end }}) {{ $n.Name }} {
return {{ $n.Name }}(func (v interface{}) {
switch v := v.(type) {
{{- range $i, $storage := $.Storage }}
case {{ $storage.Builder }}:
f{{ $i }}(v)
{{- end }}
default:
panic(fmt.Sprintf("unknown type for predicate: %T", v))
}
})
}
{{ end }}
{{ end }}
{{ end }}