entc/gen: add EqualFold and ContainsFold to string IDs (#3382)

This commit is contained in:
Ariel Mashraki
2023-03-12 11:42:13 +02:00
committed by GitHub
parent 81eb431081
commit bbbedf53af
4 changed files with 31 additions and 1 deletions

View File

@@ -1723,7 +1723,7 @@ func (f Field) enums(lf *load.Field) ([]Enum, error) {
// Ops returns all predicate operations of the field. // Ops returns all predicate operations of the field.
func (f *Field) Ops() []Op { func (f *Field) Ops() []Op {
ops := fieldOps(f) 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)...) ops = append(ops, f.cfg.Storage.Ops(f)...)
} }
return ops return ops

View File

@@ -57,6 +57,16 @@ func IDLTE(id string) predicate.Pet {
return predicate.Pet(sql.FieldLTE(FieldID, id)) 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. // HasOwner applies the HasEdge predicate on the "owner" edge.
func HasOwner() predicate.Pet { func HasOwner() predicate.Pet {
return predicate.Pet(func(s *sql.Selector) { return predicate.Pet(func(s *sql.Selector) {

View File

@@ -56,6 +56,16 @@ func IDLTE(id string) predicate.Revision {
return predicate.Revision(sql.FieldLTE(FieldID, id)) 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. // And groups predicates with the AND operator between them.
func And(predicates ...predicate.Revision) predicate.Revision { func And(predicates ...predicate.Revision) predicate.Revision {
return predicate.Revision(func(s *sql.Selector) { return predicate.Revision(func(s *sql.Selector) {

View File

@@ -56,6 +56,16 @@ func IDLTE(id string) predicate.Item {
return predicate.Item(sql.FieldLTE(FieldID, id)) 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. // Text applies equality check predicate on the "text" field. It's identical to TextEQ.
func Text(v string) predicate.Item { func Text(v string) predicate.Item {
return predicate.Item(sql.FieldEQ(FieldText, v)) return predicate.Item(sql.FieldEQ(FieldText, v))