mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/94 Reviewed By: alexsn Differential Revision: D17926186 fbshipit-source-id: b59dc418703bc4faca5230a7354edea1423b7d35
40 lines
1.2 KiB
Cheetah
40 lines
1.2 KiB
Cheetah
{{/*
|
|
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 "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 $.MultiStorage }}interface{}{{ else }}{{ (index $.Storage 0).Builder }}{{ end }})
|
|
|
|
{{ if $.MultiStorage }}
|
|
// {{ $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 }} |