mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
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
34 lines
1017 B
Cheetah
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 }} |