diff --git a/entc/gen/type.go b/entc/gen/type.go index 3aa473af0..3480f1c0f 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -1033,11 +1033,11 @@ func (f Field) EntSQL() *entsql.Annotation { } // mutMethods returns the method names of mutation interface. -var mutMethods = func() map[string]struct{} { +var mutMethods = func() map[string]bool { + names := map[string]bool{"Client": true, "Tx": true, "Where": true} t := reflect.TypeOf(new(ent.Mutation)).Elem() - names := make(map[string]struct{}) for i := 0; i < t.NumMethod(); i++ { - names[t.Method(i).Name] = struct{}{} + names[t.Method(i).Name] = true } return names }() @@ -1047,7 +1047,7 @@ var mutMethods = func() map[string]struct{} { // with the mutation methods, prefix the method with "Get". func (f Field) MutationGet() string { name := pascal(f.Name) - if _, ok := mutMethods[name]; ok { + if mutMethods[name] { name = "Get" + name } return name @@ -1056,7 +1056,7 @@ func (f Field) MutationGet() string { // MutationGetOld returns the method name for getting the old value of a field. func (f Field) MutationGetOld() string { name := "Old" + pascal(f.Name) - if _, ok := mutMethods[name]; ok { + if mutMethods[name] { name = "Get" + name } return name @@ -1067,7 +1067,7 @@ func (f Field) MutationGetOld() string { // with the mutation methods, suffix the method with "Field". func (f Field) MutationReset() string { name := "Reset" + pascal(f.Name) - if _, ok := mutMethods[name]; ok { + if mutMethods[name] { name += "Field" } return name @@ -1078,7 +1078,7 @@ func (f Field) MutationReset() string { // with the mutation methods, suffix the method with "Field". func (f Field) MutationSet() string { name := "Set" + f.StructField() - if _, ok := mutMethods[name]; ok { + if mutMethods[name] { name += "Field" } return name diff --git a/entc/integration/ent/comment.go b/entc/integration/ent/comment.go index 7aa7b3038..dad336a38 100644 --- a/entc/integration/ent/comment.go +++ b/entc/integration/ent/comment.go @@ -31,6 +31,8 @@ type Comment struct { Table string `json:"table,omitempty"` // Dir holds the value of the "dir" field. Dir schemadir.Dir `json:"dir,omitempty"` + // Client holds the value of the "client" field. + Client string `json:"client,omitempty"` } // scanValues returns the types for scanning values from sql.Rows. @@ -44,7 +46,7 @@ func (*Comment) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullFloat64) case comment.FieldID, comment.FieldUniqueInt, comment.FieldNillableInt: values[i] = new(sql.NullInt64) - case comment.FieldTable: + case comment.FieldTable, comment.FieldClient: values[i] = new(sql.NullString) default: return nil, fmt.Errorf("unexpected column %q for type Comment", columns[i]) @@ -100,6 +102,12 @@ func (c *Comment) assignValues(columns []string, values []any) error { return fmt.Errorf("unmarshal field dir: %w", err) } } + case comment.FieldClient: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field client", values[i]) + } else if value.Valid { + c.Client = value.String + } } } return nil @@ -144,6 +152,9 @@ func (c *Comment) String() string { builder.WriteString(", ") builder.WriteString("dir=") builder.WriteString(fmt.Sprintf("%v", c.Dir)) + builder.WriteString(", ") + builder.WriteString("client=") + builder.WriteString(c.Client) builder.WriteByte(')') return builder.String() } diff --git a/entc/integration/ent/comment/comment.go b/entc/integration/ent/comment/comment.go index 95628c333..4d9712657 100644 --- a/entc/integration/ent/comment/comment.go +++ b/entc/integration/ent/comment/comment.go @@ -21,6 +21,8 @@ const ( FieldTable = "table" // FieldDir holds the string denoting the dir field in the database. FieldDir = "dir" + // FieldClient holds the string denoting the client field in the database. + FieldClient = "client" // Table holds the table name of the comment in the database. Table = "comments" ) @@ -33,6 +35,7 @@ var Columns = []string{ FieldNillableInt, FieldTable, FieldDir, + FieldClient, } // ValidColumn reports if the column name is valid (part of the table columns). diff --git a/entc/integration/ent/comment/where.go b/entc/integration/ent/comment/where.go index 6b0c8e774..d738db14f 100644 --- a/entc/integration/ent/comment/where.go +++ b/entc/integration/ent/comment/where.go @@ -103,6 +103,13 @@ func NillableInt(v int) predicate.Comment { }) } +// Client applies equality check predicate on the "client" field. It's identical to ClientEQ. +func Client(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldClient), v)) + }) +} + // UniqueIntEQ applies the EQ predicate on the "unique_int" field. func UniqueIntEQ(v int) predicate.Comment { return predicate.Comment(func(s *sql.Selector) { @@ -436,6 +443,119 @@ func DirNotNil() predicate.Comment { }) } +// ClientEQ applies the EQ predicate on the "client" field. +func ClientEQ(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldClient), v)) + }) +} + +// ClientNEQ applies the NEQ predicate on the "client" field. +func ClientNEQ(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldClient), v)) + }) +} + +// ClientIn applies the In predicate on the "client" field. +func ClientIn(vs ...string) predicate.Comment { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.In(s.C(FieldClient), v...)) + }) +} + +// ClientNotIn applies the NotIn predicate on the "client" field. +func ClientNotIn(vs ...string) predicate.Comment { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.NotIn(s.C(FieldClient), v...)) + }) +} + +// ClientGT applies the GT predicate on the "client" field. +func ClientGT(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldClient), v)) + }) +} + +// ClientGTE applies the GTE predicate on the "client" field. +func ClientGTE(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldClient), v)) + }) +} + +// ClientLT applies the LT predicate on the "client" field. +func ClientLT(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldClient), v)) + }) +} + +// ClientLTE applies the LTE predicate on the "client" field. +func ClientLTE(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldClient), v)) + }) +} + +// ClientContains applies the Contains predicate on the "client" field. +func ClientContains(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldClient), v)) + }) +} + +// ClientHasPrefix applies the HasPrefix predicate on the "client" field. +func ClientHasPrefix(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldClient), v)) + }) +} + +// ClientHasSuffix applies the HasSuffix predicate on the "client" field. +func ClientHasSuffix(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldClient), v)) + }) +} + +// ClientIsNil applies the IsNil predicate on the "client" field. +func ClientIsNil() predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldClient))) + }) +} + +// ClientNotNil applies the NotNil predicate on the "client" field. +func ClientNotNil() predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldClient))) + }) +} + +// ClientEqualFold applies the EqualFold predicate on the "client" field. +func ClientEqualFold(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldClient), v)) + }) +} + +// ClientContainsFold applies the ContainsFold predicate on the "client" field. +func ClientContainsFold(v string) predicate.Comment { + return predicate.Comment(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldClient), v)) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.Comment) predicate.Comment { return predicate.Comment(func(s *sql.Selector) { diff --git a/entc/integration/ent/comment_create.go b/entc/integration/ent/comment_create.go index b2ae35b70..78e8b81fc 100644 --- a/entc/integration/ent/comment_create.go +++ b/entc/integration/ent/comment_create.go @@ -80,6 +80,20 @@ func (cc *CommentCreate) SetNillableDir(s *schemadir.Dir) *CommentCreate { return cc } +// SetClient sets the "client" field. +func (cc *CommentCreate) SetClient(s string) *CommentCreate { + cc.mutation.SetClient(s) + return cc +} + +// SetNillableClient sets the "client" field if the given value is not nil. +func (cc *CommentCreate) SetNillableClient(s *string) *CommentCreate { + if s != nil { + cc.SetClient(*s) + } + return cc +} + // Mutation returns the CommentMutation object of the builder. func (cc *CommentCreate) Mutation() *CommentMutation { return cc.mutation @@ -230,6 +244,14 @@ func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { }) _node.Dir = value } + if value, ok := cc.mutation.GetClient(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: comment.FieldClient, + }) + _node.Client = value + } return _node, _spec } @@ -378,6 +400,24 @@ func (u *CommentUpsert) ClearDir() *CommentUpsert { return u } +// SetClient sets the "client" field. +func (u *CommentUpsert) SetClient(v string) *CommentUpsert { + u.Set(comment.FieldClient, v) + return u +} + +// UpdateClient sets the "client" field to the value that was provided on create. +func (u *CommentUpsert) UpdateClient() *CommentUpsert { + u.SetExcluded(comment.FieldClient) + return u +} + +// ClearClient clears the value of the "client" field. +func (u *CommentUpsert) ClearClient() *CommentUpsert { + u.SetNull(comment.FieldClient) + return u +} + // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // @@ -530,6 +570,27 @@ func (u *CommentUpsertOne) ClearDir() *CommentUpsertOne { }) } +// SetClient sets the "client" field. +func (u *CommentUpsertOne) SetClient(v string) *CommentUpsertOne { + return u.Update(func(s *CommentUpsert) { + s.SetClient(v) + }) +} + +// UpdateClient sets the "client" field to the value that was provided on create. +func (u *CommentUpsertOne) UpdateClient() *CommentUpsertOne { + return u.Update(func(s *CommentUpsert) { + s.UpdateClient() + }) +} + +// ClearClient clears the value of the "client" field. +func (u *CommentUpsertOne) ClearClient() *CommentUpsertOne { + return u.Update(func(s *CommentUpsert) { + s.ClearClient() + }) +} + // Exec executes the query. func (u *CommentUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { @@ -841,6 +902,27 @@ func (u *CommentUpsertBulk) ClearDir() *CommentUpsertBulk { }) } +// SetClient sets the "client" field. +func (u *CommentUpsertBulk) SetClient(v string) *CommentUpsertBulk { + return u.Update(func(s *CommentUpsert) { + s.SetClient(v) + }) +} + +// UpdateClient sets the "client" field to the value that was provided on create. +func (u *CommentUpsertBulk) UpdateClient() *CommentUpsertBulk { + return u.Update(func(s *CommentUpsert) { + s.UpdateClient() + }) +} + +// ClearClient clears the value of the "client" field. +func (u *CommentUpsertBulk) ClearClient() *CommentUpsertBulk { + return u.Update(func(s *CommentUpsert) { + s.ClearClient() + }) +} + // Exec executes the query. func (u *CommentUpsertBulk) Exec(ctx context.Context) error { for i, b := range u.create.builders { diff --git a/entc/integration/ent/comment_update.go b/entc/integration/ent/comment_update.go index 2bfb86cf1..1d2623474 100644 --- a/entc/integration/ent/comment_update.go +++ b/entc/integration/ent/comment_update.go @@ -126,6 +126,26 @@ func (cu *CommentUpdate) ClearDir() *CommentUpdate { return cu } +// SetClient sets the "client" field. +func (cu *CommentUpdate) SetClient(s string) *CommentUpdate { + cu.mutation.SetClient(s) + return cu +} + +// SetNillableClient sets the "client" field if the given value is not nil. +func (cu *CommentUpdate) SetNillableClient(s *string) *CommentUpdate { + if s != nil { + cu.SetClient(*s) + } + return cu +} + +// ClearClient clears the value of the "client" field. +func (cu *CommentUpdate) ClearClient() *CommentUpdate { + cu.mutation.ClearClient() + return cu +} + // Mutation returns the CommentMutation object of the builder. func (cu *CommentUpdate) Mutation() *CommentMutation { return cu.mutation @@ -283,6 +303,19 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: comment.FieldDir, }) } + if value, ok := cu.mutation.GetClient(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: comment.FieldClient, + }) + } + if cu.mutation.ClientCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: comment.FieldClient, + }) + } _spec.Modifiers = cu.modifiers if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -397,6 +430,26 @@ func (cuo *CommentUpdateOne) ClearDir() *CommentUpdateOne { return cuo } +// SetClient sets the "client" field. +func (cuo *CommentUpdateOne) SetClient(s string) *CommentUpdateOne { + cuo.mutation.SetClient(s) + return cuo +} + +// SetNillableClient sets the "client" field if the given value is not nil. +func (cuo *CommentUpdateOne) SetNillableClient(s *string) *CommentUpdateOne { + if s != nil { + cuo.SetClient(*s) + } + return cuo +} + +// ClearClient clears the value of the "client" field. +func (cuo *CommentUpdateOne) ClearClient() *CommentUpdateOne { + cuo.mutation.ClearClient() + return cuo +} + // Mutation returns the CommentMutation object of the builder. func (cuo *CommentUpdateOne) Mutation() *CommentMutation { return cuo.mutation @@ -584,6 +637,19 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Column: comment.FieldDir, }) } + if value, ok := cuo.mutation.GetClient(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: comment.FieldClient, + }) + } + if cuo.mutation.ClientCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: comment.FieldClient, + }) + } _spec.Modifiers = cuo.modifiers _node = &Comment{config: cuo.config} _spec.Assign = _node.assignValues diff --git a/entc/integration/ent/entql.go b/entc/integration/ent/entql.go index 721a37f09..636e9e86f 100644 --- a/entc/integration/ent/entql.go +++ b/entc/integration/ent/entql.go @@ -67,6 +67,7 @@ var schemaGraph = func() *sqlgraph.Schema { comment.FieldNillableInt: {Type: field.TypeInt, Column: comment.FieldNillableInt}, comment.FieldTable: {Type: field.TypeString, Column: comment.FieldTable}, comment.FieldDir: {Type: field.TypeJSON, Column: comment.FieldDir}, + comment.FieldClient: {Type: field.TypeString, Column: comment.FieldClient}, }, } graph.Nodes[2] = &sqlgraph.Node{ @@ -831,6 +832,11 @@ func (f *CommentFilter) WhereDir(p entql.BytesP) { f.Where(p.Field(comment.FieldDir)) } +// WhereClient applies the entql string predicate on the client field. +func (f *CommentFilter) WhereClient(p entql.StringP) { + f.Where(p.Field(comment.FieldClient)) +} + // addPredicate implements the predicateAdder interface. func (ftq *FieldTypeQuery) addPredicate(pred func(s *sql.Selector)) { ftq.predicates = append(ftq.predicates, pred) diff --git a/entc/integration/ent/migrate/schema.go b/entc/integration/ent/migrate/schema.go index d28b5732b..88ef951a8 100644 --- a/entc/integration/ent/migrate/schema.go +++ b/entc/integration/ent/migrate/schema.go @@ -62,6 +62,7 @@ var ( {Name: "nillable_int", Type: field.TypeInt, Nullable: true}, {Name: "table", Type: field.TypeString, Nullable: true}, {Name: "dir", Type: field.TypeJSON, Nullable: true}, + {Name: "client", Type: field.TypeString, Nullable: true}, } // CommentsTable holds the schema information for the "comments" table. CommentsTable = &schema.Table{ diff --git a/entc/integration/ent/mutation.go b/entc/integration/ent/mutation.go index c446112c3..f74592204 100644 --- a/entc/integration/ent/mutation.go +++ b/entc/integration/ent/mutation.go @@ -817,6 +817,7 @@ type CommentMutation struct { addnillable_int *int table *string dir *schemadir.Dir + client *string clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Comment, error) @@ -1201,6 +1202,55 @@ func (m *CommentMutation) ResetDir() { delete(m.clearedFields, comment.FieldDir) } +// SetClient sets the "client" field. +func (m *CommentMutation) SetClient(s string) { + m.client = &s +} + +// GetClient returns the value of the "client" field in the mutation. +func (m *CommentMutation) GetClient() (r string, exists bool) { + v := m.client + if v == nil { + return + } + return *v, true +} + +// OldClient returns the old "client" field's value of the Comment entity. +// If the Comment object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CommentMutation) OldClient(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldClient is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldClient requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldClient: %w", err) + } + return oldValue.Client, nil +} + +// ClearClient clears the value of the "client" field. +func (m *CommentMutation) ClearClient() { + m.client = nil + m.clearedFields[comment.FieldClient] = struct{}{} +} + +// ClientCleared returns if the "client" field was cleared in this mutation. +func (m *CommentMutation) ClientCleared() bool { + _, ok := m.clearedFields[comment.FieldClient] + return ok +} + +// ResetClient resets all changes to the "client" field. +func (m *CommentMutation) ResetClient() { + m.client = nil + delete(m.clearedFields, comment.FieldClient) +} + // Where appends a list predicates to the CommentMutation builder. func (m *CommentMutation) Where(ps ...predicate.Comment) { m.predicates = append(m.predicates, ps...) @@ -1220,7 +1270,7 @@ func (m *CommentMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *CommentMutation) Fields() []string { - fields := make([]string, 0, 5) + fields := make([]string, 0, 6) if m.unique_int != nil { fields = append(fields, comment.FieldUniqueInt) } @@ -1236,6 +1286,9 @@ func (m *CommentMutation) Fields() []string { if m.dir != nil { fields = append(fields, comment.FieldDir) } + if m.client != nil { + fields = append(fields, comment.FieldClient) + } return fields } @@ -1254,6 +1307,8 @@ func (m *CommentMutation) Field(name string) (ent.Value, bool) { return m.Table() case comment.FieldDir: return m.Dir() + case comment.FieldClient: + return m.GetClient() } return nil, false } @@ -1273,6 +1328,8 @@ func (m *CommentMutation) OldField(ctx context.Context, name string) (ent.Value, return m.OldTable(ctx) case comment.FieldDir: return m.OldDir(ctx) + case comment.FieldClient: + return m.OldClient(ctx) } return nil, fmt.Errorf("unknown Comment field %s", name) } @@ -1317,6 +1374,13 @@ func (m *CommentMutation) SetField(name string, value ent.Value) error { } m.SetDir(v) return nil + case comment.FieldClient: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetClient(v) + return nil } return fmt.Errorf("unknown Comment field %s", name) } @@ -1395,6 +1459,9 @@ func (m *CommentMutation) ClearedFields() []string { if m.FieldCleared(comment.FieldDir) { fields = append(fields, comment.FieldDir) } + if m.FieldCleared(comment.FieldClient) { + fields = append(fields, comment.FieldClient) + } return fields } @@ -1418,6 +1485,9 @@ func (m *CommentMutation) ClearField(name string) error { case comment.FieldDir: m.ClearDir() return nil + case comment.FieldClient: + m.ClearClient() + return nil } return fmt.Errorf("unknown Comment nullable field %s", name) } @@ -1441,6 +1511,9 @@ func (m *CommentMutation) ResetField(name string) error { case comment.FieldDir: m.ResetDir() return nil + case comment.FieldClient: + m.ResetClient() + return nil } return fmt.Errorf("unknown Comment field %s", name) } diff --git a/entc/integration/ent/schema/comment.go b/entc/integration/ent/schema/comment.go index d2383541f..d00e59865 100644 --- a/entc/integration/ent/schema/comment.go +++ b/entc/integration/ent/schema/comment.go @@ -29,5 +29,7 @@ func (Comment) Fields() []ent.Field { Optional(), field.JSON("dir", schemadir.Dir("")). Optional(), + field.String("client"). + Optional(), } } diff --git a/entc/integration/gremlin/ent/comment.go b/entc/integration/gremlin/ent/comment.go index 1213b15d1..1ea375eba 100644 --- a/entc/integration/gremlin/ent/comment.go +++ b/entc/integration/gremlin/ent/comment.go @@ -29,6 +29,8 @@ type Comment struct { Table string `json:"table,omitempty"` // Dir holds the value of the "dir" field. Dir schemadir.Dir `json:"dir,omitempty"` + // Client holds the value of the "client" field. + Client string `json:"client,omitempty"` } // FromResponse scans the gremlin response data into Comment. @@ -44,6 +46,7 @@ func (c *Comment) FromResponse(res *gremlin.Response) error { NillableInt *int `json:"nillable_int,omitempty"` Table string `json:"table,omitempty"` Dir schemadir.Dir `json:"dir,omitempty"` + Client string `json:"client,omitempty"` } if err := vmap.Decode(&scanc); err != nil { return err @@ -54,6 +57,7 @@ func (c *Comment) FromResponse(res *gremlin.Response) error { c.NillableInt = scanc.NillableInt c.Table = scanc.Table c.Dir = scanc.Dir + c.Client = scanc.Client return nil } @@ -96,6 +100,9 @@ func (c *Comment) String() string { builder.WriteString(", ") builder.WriteString("dir=") builder.WriteString(fmt.Sprintf("%v", c.Dir)) + builder.WriteString(", ") + builder.WriteString("client=") + builder.WriteString(c.Client) builder.WriteByte(')') return builder.String() } @@ -116,6 +123,7 @@ func (c *Comments) FromResponse(res *gremlin.Response) error { NillableInt *int `json:"nillable_int,omitempty"` Table string `json:"table,omitempty"` Dir schemadir.Dir `json:"dir,omitempty"` + Client string `json:"client,omitempty"` } if err := vmap.Decode(&scanc); err != nil { return err @@ -127,6 +135,7 @@ func (c *Comments) FromResponse(res *gremlin.Response) error { node.NillableInt = v.NillableInt node.Table = v.Table node.Dir = v.Dir + node.Client = v.Client *c = append(*c, node) } return nil diff --git a/entc/integration/gremlin/ent/comment/comment.go b/entc/integration/gremlin/ent/comment/comment.go index dc58d8d3c..4a2637b6b 100644 --- a/entc/integration/gremlin/ent/comment/comment.go +++ b/entc/integration/gremlin/ent/comment/comment.go @@ -21,6 +21,8 @@ const ( FieldTable = "table" // FieldDir holds the string denoting the dir field in the database. FieldDir = "dir" + // FieldClient holds the string denoting the client field in the database. + FieldClient = "client" ) // comment from another template. diff --git a/entc/integration/gremlin/ent/comment/where.go b/entc/integration/gremlin/ent/comment/where.go index 488590d41..31aecf0ba 100644 --- a/entc/integration/gremlin/ent/comment/where.go +++ b/entc/integration/gremlin/ent/comment/where.go @@ -105,6 +105,13 @@ func NillableInt(v int) predicate.Comment { }) } +// Client applies equality check predicate on the "client" field. It's identical to ClientEQ. +func Client(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.EQ(v)) + }) +} + // UniqueIntEQ applies the EQ predicate on the "unique_int" field. func UniqueIntEQ(v int) predicate.Comment { return predicate.Comment(func(t *dsl.Traversal) { @@ -424,6 +431,105 @@ func DirNotNil() predicate.Comment { }) } +// ClientEQ applies the EQ predicate on the "client" field. +func ClientEQ(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.EQ(v)) + }) +} + +// ClientNEQ applies the NEQ predicate on the "client" field. +func ClientNEQ(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.NEQ(v)) + }) +} + +// ClientIn applies the In predicate on the "client" field. +func ClientIn(vs ...string) predicate.Comment { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.Within(v...)) + }) +} + +// ClientNotIn applies the NotIn predicate on the "client" field. +func ClientNotIn(vs ...string) predicate.Comment { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.Without(v...)) + }) +} + +// ClientGT applies the GT predicate on the "client" field. +func ClientGT(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.GT(v)) + }) +} + +// ClientGTE applies the GTE predicate on the "client" field. +func ClientGTE(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.GTE(v)) + }) +} + +// ClientLT applies the LT predicate on the "client" field. +func ClientLT(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.LT(v)) + }) +} + +// ClientLTE applies the LTE predicate on the "client" field. +func ClientLTE(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.LTE(v)) + }) +} + +// ClientContains applies the Contains predicate on the "client" field. +func ClientContains(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.Containing(v)) + }) +} + +// ClientHasPrefix applies the HasPrefix predicate on the "client" field. +func ClientHasPrefix(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.StartingWith(v)) + }) +} + +// ClientHasSuffix applies the HasSuffix predicate on the "client" field. +func ClientHasSuffix(v string) predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.Has(Label, FieldClient, p.EndingWith(v)) + }) +} + +// ClientIsNil applies the IsNil predicate on the "client" field. +func ClientIsNil() predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.HasLabel(Label).HasNot(FieldClient) + }) +} + +// ClientNotNil applies the NotNil predicate on the "client" field. +func ClientNotNil() predicate.Comment { + return predicate.Comment(func(t *dsl.Traversal) { + t.HasLabel(Label).Has(FieldClient) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.Comment) predicate.Comment { return predicate.Comment(func(tr *dsl.Traversal) { diff --git a/entc/integration/gremlin/ent/comment_create.go b/entc/integration/gremlin/ent/comment_create.go index 67c8f47b6..f3b2278c6 100644 --- a/entc/integration/gremlin/ent/comment_create.go +++ b/entc/integration/gremlin/ent/comment_create.go @@ -81,6 +81,20 @@ func (cc *CommentCreate) SetNillableDir(s *schemadir.Dir) *CommentCreate { return cc } +// SetClient sets the "client" field. +func (cc *CommentCreate) SetClient(s string) *CommentCreate { + cc.mutation.SetClient(s) + return cc +} + +// SetNillableClient sets the "client" field if the given value is not nil. +func (cc *CommentCreate) SetNillableClient(s *string) *CommentCreate { + if s != nil { + cc.SetClient(*s) + } + return cc +} + // Mutation returns the CommentMutation object of the builder. func (cc *CommentCreate) Mutation() *CommentMutation { return cc.mutation @@ -212,6 +226,9 @@ func (cc *CommentCreate) gremlin() *dsl.Traversal { if value, ok := cc.mutation.Dir(); ok { v.Property(dsl.Single, comment.FieldDir, value) } + if value, ok := cc.mutation.GetClient(); ok { + v.Property(dsl.Single, comment.FieldClient, value) + } if len(constraints) == 0 { return v.ValueMap(true) } diff --git a/entc/integration/gremlin/ent/comment_update.go b/entc/integration/gremlin/ent/comment_update.go index e9a2d5291..08694954e 100644 --- a/entc/integration/gremlin/ent/comment_update.go +++ b/entc/integration/gremlin/ent/comment_update.go @@ -127,6 +127,26 @@ func (cu *CommentUpdate) ClearDir() *CommentUpdate { return cu } +// SetClient sets the "client" field. +func (cu *CommentUpdate) SetClient(s string) *CommentUpdate { + cu.mutation.SetClient(s) + return cu +} + +// SetNillableClient sets the "client" field if the given value is not nil. +func (cu *CommentUpdate) SetNillableClient(s *string) *CommentUpdate { + if s != nil { + cu.SetClient(*s) + } + return cu +} + +// ClearClient clears the value of the "client" field. +func (cu *CommentUpdate) ClearClient() *CommentUpdate { + cu.mutation.ClearClient() + return cu +} + // Mutation returns the CommentMutation object of the builder. func (cu *CommentUpdate) Mutation() *CommentMutation { return cu.mutation @@ -256,6 +276,9 @@ func (cu *CommentUpdate) gremlin() *dsl.Traversal { if value, ok := cu.mutation.Dir(); ok { v.Property(dsl.Single, comment.FieldDir, value) } + if value, ok := cu.mutation.GetClient(); ok { + v.Property(dsl.Single, comment.FieldClient, value) + } var properties []any if cu.mutation.NillableIntCleared() { properties = append(properties, comment.FieldNillableInt) @@ -266,6 +289,9 @@ func (cu *CommentUpdate) gremlin() *dsl.Traversal { if cu.mutation.DirCleared() { properties = append(properties, comment.FieldDir) } + if cu.mutation.ClientCleared() { + properties = append(properties, comment.FieldClient) + } if len(properties) > 0 { v.SideEffect(__.Properties(properties...).Drop()) } @@ -385,6 +411,26 @@ func (cuo *CommentUpdateOne) ClearDir() *CommentUpdateOne { return cuo } +// SetClient sets the "client" field. +func (cuo *CommentUpdateOne) SetClient(s string) *CommentUpdateOne { + cuo.mutation.SetClient(s) + return cuo +} + +// SetNillableClient sets the "client" field if the given value is not nil. +func (cuo *CommentUpdateOne) SetNillableClient(s *string) *CommentUpdateOne { + if s != nil { + cuo.SetClient(*s) + } + return cuo +} + +// ClearClient clears the value of the "client" field. +func (cuo *CommentUpdateOne) ClearClient() *CommentUpdateOne { + cuo.mutation.ClearClient() + return cuo +} + // Mutation returns the CommentMutation object of the builder. func (cuo *CommentUpdateOne) Mutation() *CommentMutation { return cuo.mutation @@ -532,6 +578,9 @@ func (cuo *CommentUpdateOne) gremlin(id string) *dsl.Traversal { if value, ok := cuo.mutation.Dir(); ok { v.Property(dsl.Single, comment.FieldDir, value) } + if value, ok := cuo.mutation.GetClient(); ok { + v.Property(dsl.Single, comment.FieldClient, value) + } var properties []any if cuo.mutation.NillableIntCleared() { properties = append(properties, comment.FieldNillableInt) @@ -542,6 +591,9 @@ func (cuo *CommentUpdateOne) gremlin(id string) *dsl.Traversal { if cuo.mutation.DirCleared() { properties = append(properties, comment.FieldDir) } + if cuo.mutation.ClientCleared() { + properties = append(properties, comment.FieldClient) + } if len(properties) > 0 { v.SideEffect(__.Properties(properties...).Drop()) } diff --git a/entc/integration/gremlin/ent/mutation.go b/entc/integration/gremlin/ent/mutation.go index 5d010bd01..128715b2c 100644 --- a/entc/integration/gremlin/ent/mutation.go +++ b/entc/integration/gremlin/ent/mutation.go @@ -817,6 +817,7 @@ type CommentMutation struct { addnillable_int *int table *string dir *schemadir.Dir + client *string clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Comment, error) @@ -1201,6 +1202,55 @@ func (m *CommentMutation) ResetDir() { delete(m.clearedFields, comment.FieldDir) } +// SetClient sets the "client" field. +func (m *CommentMutation) SetClient(s string) { + m.client = &s +} + +// GetClient returns the value of the "client" field in the mutation. +func (m *CommentMutation) GetClient() (r string, exists bool) { + v := m.client + if v == nil { + return + } + return *v, true +} + +// OldClient returns the old "client" field's value of the Comment entity. +// If the Comment object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CommentMutation) OldClient(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldClient is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldClient requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldClient: %w", err) + } + return oldValue.Client, nil +} + +// ClearClient clears the value of the "client" field. +func (m *CommentMutation) ClearClient() { + m.client = nil + m.clearedFields[comment.FieldClient] = struct{}{} +} + +// ClientCleared returns if the "client" field was cleared in this mutation. +func (m *CommentMutation) ClientCleared() bool { + _, ok := m.clearedFields[comment.FieldClient] + return ok +} + +// ResetClient resets all changes to the "client" field. +func (m *CommentMutation) ResetClient() { + m.client = nil + delete(m.clearedFields, comment.FieldClient) +} + // Where appends a list predicates to the CommentMutation builder. func (m *CommentMutation) Where(ps ...predicate.Comment) { m.predicates = append(m.predicates, ps...) @@ -1220,7 +1270,7 @@ func (m *CommentMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *CommentMutation) Fields() []string { - fields := make([]string, 0, 5) + fields := make([]string, 0, 6) if m.unique_int != nil { fields = append(fields, comment.FieldUniqueInt) } @@ -1236,6 +1286,9 @@ func (m *CommentMutation) Fields() []string { if m.dir != nil { fields = append(fields, comment.FieldDir) } + if m.client != nil { + fields = append(fields, comment.FieldClient) + } return fields } @@ -1254,6 +1307,8 @@ func (m *CommentMutation) Field(name string) (ent.Value, bool) { return m.Table() case comment.FieldDir: return m.Dir() + case comment.FieldClient: + return m.GetClient() } return nil, false } @@ -1273,6 +1328,8 @@ func (m *CommentMutation) OldField(ctx context.Context, name string) (ent.Value, return m.OldTable(ctx) case comment.FieldDir: return m.OldDir(ctx) + case comment.FieldClient: + return m.OldClient(ctx) } return nil, fmt.Errorf("unknown Comment field %s", name) } @@ -1317,6 +1374,13 @@ func (m *CommentMutation) SetField(name string, value ent.Value) error { } m.SetDir(v) return nil + case comment.FieldClient: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetClient(v) + return nil } return fmt.Errorf("unknown Comment field %s", name) } @@ -1395,6 +1459,9 @@ func (m *CommentMutation) ClearedFields() []string { if m.FieldCleared(comment.FieldDir) { fields = append(fields, comment.FieldDir) } + if m.FieldCleared(comment.FieldClient) { + fields = append(fields, comment.FieldClient) + } return fields } @@ -1418,6 +1485,9 @@ func (m *CommentMutation) ClearField(name string) error { case comment.FieldDir: m.ClearDir() return nil + case comment.FieldClient: + m.ClearClient() + return nil } return fmt.Errorf("unknown Comment nullable field %s", name) } @@ -1441,6 +1511,9 @@ func (m *CommentMutation) ResetField(name string) error { case comment.FieldDir: m.ResetDir() return nil + case comment.FieldClient: + m.ResetClient() + return nil } return fmt.Errorf("unknown Comment field %s", name) }