entc/gen: fix entql generation for ID types of Bytes, etc. (#2157)

* Fix entql generation for ID types of Bytes, etc.

I was running into an issue trying to use a Bytes fieldas the ID field in a Schema, and it appears there is an currently an issue with using a Bytes field as the ID field in the entql codegen (it was outputing a function . I belive this should fix it (I tested this by adding the entql flag to the custom id integration test). I wasn't sure if the other cases I added (e.g. an ID field that is json type / time type / etc.) are actually sane ID field types, but if those don't make any sense I can remove some of those from the added conditionals.

* remove redundant line
This commit is contained in:
Andy Day
2021-11-24 03:53:45 -08:00
committed by GitHub
parent 1ef79a2d78
commit b1e76d1a05
3 changed files with 1106 additions and 2 deletions

View File

@@ -111,7 +111,10 @@ type predicateAdder interface {
{{ $type := $n.ID.Type.Type.String }}
{{ $iface := print (pascal $type) "P" }}
{{ if $n.ID.IsUUID }}{{ $iface = "ValueP" }}{{ end }}
{{- if $n.ID.IsTime }}{{ $iface = "TimeP" }}
{{- else if or $n.ID.IsBytes $n.ID.IsJSON }}{{ $iface = "BytesP" }}
{{- else if $n.ID.IsUUID }}{{ $iface = "ValueP" }}
{{- end }}
// WhereID applies the entql {{ $type }} predicate on the id field.
func (f *{{ $filter }}) WhereID(p entql.{{ $iface }}) {
f.Where(p.Field({{ $n.Package }}.{{ $n.ID.Constant }}))

File diff suppressed because it is too large Load Diff

View File

@@ -4,4 +4,4 @@
package ent
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert --header "// Copyright 2019-present Facebook Inc. All rights reserved.\n// This source code is licensed under the Apache 2.0 license found\n// in the LICENSE file in the root directory of this source tree.\n\n// Code generated by entc, DO NOT EDIT." ./schema
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert --feature entql --header "// Copyright 2019-present Facebook Inc. All rights reserved.\n// This source code is licensed under the Apache 2.0 license found\n// in the LICENSE file in the root directory of this source tree.\n\n// Code generated by entc, DO NOT EDIT." ./schema