// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "football_api/ent/predicate" "football_api/ent/profile" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/google/uuid" ) // ProfileUpdate is the builder for updating Profile entities. type ProfileUpdate struct { config hooks []Hook mutation *ProfileMutation } // Where appends a list predicates to the ProfileUpdate builder. func (pu *ProfileUpdate) Where(ps ...predicate.Profile) *ProfileUpdate { pu.mutation.Where(ps...) return pu } // SetDisplayName sets the "display_name" field. func (pu *ProfileUpdate) SetDisplayName(s string) *ProfileUpdate { pu.mutation.SetDisplayName(s) return pu } // SetUserID sets the "user_id" field. func (pu *ProfileUpdate) SetUserID(u uuid.UUID) *ProfileUpdate { pu.mutation.SetUserID(u) return pu } // SetCreatedAt sets the "created_at" field. func (pu *ProfileUpdate) SetCreatedAt(t time.Time) *ProfileUpdate { pu.mutation.SetCreatedAt(t) return pu } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (pu *ProfileUpdate) SetNillableCreatedAt(t *time.Time) *ProfileUpdate { if t != nil { pu.SetCreatedAt(*t) } return pu } // SetUpdatedAt sets the "updated_at" field. func (pu *ProfileUpdate) SetUpdatedAt(t time.Time) *ProfileUpdate { pu.mutation.SetUpdatedAt(t) return pu } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (pu *ProfileUpdate) SetNillableUpdatedAt(t *time.Time) *ProfileUpdate { if t != nil { pu.SetUpdatedAt(*t) } return pu } // Mutation returns the ProfileMutation object of the builder. func (pu *ProfileUpdate) Mutation() *ProfileMutation { return pu.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (pu *ProfileUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. func (pu *ProfileUpdate) SaveX(ctx context.Context) int { affected, err := pu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (pu *ProfileUpdate) Exec(ctx context.Context) error { _, err := pu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (pu *ProfileUpdate) ExecX(ctx context.Context) { if err := pu.Exec(ctx); err != nil { panic(err) } } func (pu *ProfileUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := sqlgraph.NewUpdateSpec(profile.Table, profile.Columns, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID)) if ps := pu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := pu.mutation.DisplayName(); ok { _spec.SetField(profile.FieldDisplayName, field.TypeString, value) } if value, ok := pu.mutation.UserID(); ok { _spec.SetField(profile.FieldUserID, field.TypeUUID, value) } if value, ok := pu.mutation.CreatedAt(); ok { _spec.SetField(profile.FieldCreatedAt, field.TypeTime, value) } if value, ok := pu.mutation.UpdatedAt(); ok { _spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value) } if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{profile.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } pu.mutation.done = true return n, nil } // ProfileUpdateOne is the builder for updating a single Profile entity. type ProfileUpdateOne struct { config fields []string hooks []Hook mutation *ProfileMutation } // SetDisplayName sets the "display_name" field. func (puo *ProfileUpdateOne) SetDisplayName(s string) *ProfileUpdateOne { puo.mutation.SetDisplayName(s) return puo } // SetUserID sets the "user_id" field. func (puo *ProfileUpdateOne) SetUserID(u uuid.UUID) *ProfileUpdateOne { puo.mutation.SetUserID(u) return puo } // SetCreatedAt sets the "created_at" field. func (puo *ProfileUpdateOne) SetCreatedAt(t time.Time) *ProfileUpdateOne { puo.mutation.SetCreatedAt(t) return puo } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (puo *ProfileUpdateOne) SetNillableCreatedAt(t *time.Time) *ProfileUpdateOne { if t != nil { puo.SetCreatedAt(*t) } return puo } // SetUpdatedAt sets the "updated_at" field. func (puo *ProfileUpdateOne) SetUpdatedAt(t time.Time) *ProfileUpdateOne { puo.mutation.SetUpdatedAt(t) return puo } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (puo *ProfileUpdateOne) SetNillableUpdatedAt(t *time.Time) *ProfileUpdateOne { if t != nil { puo.SetUpdatedAt(*t) } return puo } // Mutation returns the ProfileMutation object of the builder. func (puo *ProfileUpdateOne) Mutation() *ProfileMutation { return puo.mutation } // Where appends a list predicates to the ProfileUpdate builder. func (puo *ProfileUpdateOne) Where(ps ...predicate.Profile) *ProfileUpdateOne { puo.mutation.Where(ps...) return puo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (puo *ProfileUpdateOne) Select(field string, fields ...string) *ProfileUpdateOne { puo.fields = append([]string{field}, fields...) return puo } // Save executes the query and returns the updated Profile entity. func (puo *ProfileUpdateOne) Save(ctx context.Context) (*Profile, error) { return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. func (puo *ProfileUpdateOne) SaveX(ctx context.Context) *Profile { node, err := puo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (puo *ProfileUpdateOne) Exec(ctx context.Context) error { _, err := puo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (puo *ProfileUpdateOne) ExecX(ctx context.Context) { if err := puo.Exec(ctx); err != nil { panic(err) } } func (puo *ProfileUpdateOne) sqlSave(ctx context.Context) (_node *Profile, err error) { _spec := sqlgraph.NewUpdateSpec(profile.Table, profile.Columns, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID)) id, ok := puo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Profile.id" for update`)} } _spec.Node.ID.Value = id if fields := puo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, profile.FieldID) for _, f := range fields { if !profile.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != profile.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := puo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := puo.mutation.DisplayName(); ok { _spec.SetField(profile.FieldDisplayName, field.TypeString, value) } if value, ok := puo.mutation.UserID(); ok { _spec.SetField(profile.FieldUserID, field.TypeUUID, value) } if value, ok := puo.mutation.CreatedAt(); ok { _spec.SetField(profile.FieldCreatedAt, field.TypeTime, value) } if value, ok := puo.mutation.UpdatedAt(); ok { _spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value) } _node = &Profile{config: puo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{profile.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } puo.mutation.done = true return _node, nil }