From bbbedf53af2fc54e31eee9cfaebbc577c750e8bc Mon Sep 17 00:00:00 2001 From: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Date: Sun, 12 Mar 2023 11:42:13 +0200 Subject: [PATCH] entc/gen: add EqualFold and ContainsFold to string IDs (#3382) --- entc/gen/type.go | 2 +- entc/integration/customid/ent/pet/where.go | 10 ++++++++++ entc/integration/customid/ent/revision/where.go | 10 ++++++++++ entc/integration/ent/item/where.go | 10 ++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/entc/gen/type.go b/entc/gen/type.go index 04488d76c..2bbe12164 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -1723,7 +1723,7 @@ func (f Field) enums(lf *load.Field) ([]Enum, error) { // Ops returns all predicate operations of the field. func (f *Field) Ops() []Op { ops := fieldOps(f) - if f.Name != "id" && f.cfg != nil && f.cfg.Storage.Ops != nil { + if (f.Name != "id" || !f.HasGoType()) && f.cfg != nil && f.cfg.Storage.Ops != nil { ops = append(ops, f.cfg.Storage.Ops(f)...) } return ops diff --git a/entc/integration/customid/ent/pet/where.go b/entc/integration/customid/ent/pet/where.go index e4af9e75a..98605b420 100644 --- a/entc/integration/customid/ent/pet/where.go +++ b/entc/integration/customid/ent/pet/where.go @@ -57,6 +57,16 @@ func IDLTE(id string) predicate.Pet { return predicate.Pet(sql.FieldLTE(FieldID, id)) } +// IDEqualFold applies the EqualFold predicate on the ID field. +func IDEqualFold(id string) predicate.Pet { + return predicate.Pet(sql.FieldEqualFold(FieldID, id)) +} + +// IDContainsFold applies the ContainsFold predicate on the ID field. +func IDContainsFold(id string) predicate.Pet { + return predicate.Pet(sql.FieldContainsFold(FieldID, id)) +} + // HasOwner applies the HasEdge predicate on the "owner" edge. func HasOwner() predicate.Pet { return predicate.Pet(func(s *sql.Selector) { diff --git a/entc/integration/customid/ent/revision/where.go b/entc/integration/customid/ent/revision/where.go index f884b55da..d61a86fe6 100644 --- a/entc/integration/customid/ent/revision/where.go +++ b/entc/integration/customid/ent/revision/where.go @@ -56,6 +56,16 @@ func IDLTE(id string) predicate.Revision { return predicate.Revision(sql.FieldLTE(FieldID, id)) } +// IDEqualFold applies the EqualFold predicate on the ID field. +func IDEqualFold(id string) predicate.Revision { + return predicate.Revision(sql.FieldEqualFold(FieldID, id)) +} + +// IDContainsFold applies the ContainsFold predicate on the ID field. +func IDContainsFold(id string) predicate.Revision { + return predicate.Revision(sql.FieldContainsFold(FieldID, id)) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.Revision) predicate.Revision { return predicate.Revision(func(s *sql.Selector) { diff --git a/entc/integration/ent/item/where.go b/entc/integration/ent/item/where.go index d55acdfd0..2242f3bf0 100644 --- a/entc/integration/ent/item/where.go +++ b/entc/integration/ent/item/where.go @@ -56,6 +56,16 @@ func IDLTE(id string) predicate.Item { return predicate.Item(sql.FieldLTE(FieldID, id)) } +// IDEqualFold applies the EqualFold predicate on the ID field. +func IDEqualFold(id string) predicate.Item { + return predicate.Item(sql.FieldEqualFold(FieldID, id)) +} + +// IDContainsFold applies the ContainsFold predicate on the ID field. +func IDContainsFold(id string) predicate.Item { + return predicate.Item(sql.FieldContainsFold(FieldID, id)) +} + // Text applies equality check predicate on the "text" field. It's identical to TextEQ. func Text(v string) predicate.Item { return predicate.Item(sql.FieldEQ(FieldText, v))