// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "code.icod.de/dalu/ka/ent/post" "code.icod.de/dalu/ka/ent/predicate" "code.icod.de/dalu/ka/ent/profile" "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 } // SetUpdatedAt sets the "updated_at" field. func (pu *ProfileUpdate) SetUpdatedAt(t time.Time) *ProfileUpdate { pu.mutation.SetUpdatedAt(t) return pu } // ClearUpdatedAt clears the value of the "updated_at" field. func (pu *ProfileUpdate) ClearUpdatedAt() *ProfileUpdate { pu.mutation.ClearUpdatedAt() return pu } // SetName sets the "name" field. func (pu *ProfileUpdate) SetName(s string) *ProfileUpdate { pu.mutation.SetName(s) return pu } // SetNillableName sets the "name" field if the given value is not nil. func (pu *ProfileUpdate) SetNillableName(s *string) *ProfileUpdate { if s != nil { pu.SetName(*s) } return pu } // ClearName clears the value of the "name" field. func (pu *ProfileUpdate) ClearName() *ProfileUpdate { pu.mutation.ClearName() return pu } // SetAddress sets the "address" field. func (pu *ProfileUpdate) SetAddress(s string) *ProfileUpdate { pu.mutation.SetAddress(s) return pu } // SetNillableAddress sets the "address" field if the given value is not nil. func (pu *ProfileUpdate) SetNillableAddress(s *string) *ProfileUpdate { if s != nil { pu.SetAddress(*s) } return pu } // ClearAddress clears the value of the "address" field. func (pu *ProfileUpdate) ClearAddress() *ProfileUpdate { pu.mutation.ClearAddress() return pu } // SetPhone sets the "phone" field. func (pu *ProfileUpdate) SetPhone(s string) *ProfileUpdate { pu.mutation.SetPhone(s) return pu } // SetNillablePhone sets the "phone" field if the given value is not nil. func (pu *ProfileUpdate) SetNillablePhone(s *string) *ProfileUpdate { if s != nil { pu.SetPhone(*s) } return pu } // ClearPhone clears the value of the "phone" field. func (pu *ProfileUpdate) ClearPhone() *ProfileUpdate { pu.mutation.ClearPhone() return pu } // AddPostIDs adds the "posts" edge to the Post entity by IDs. func (pu *ProfileUpdate) AddPostIDs(ids ...uuid.UUID) *ProfileUpdate { pu.mutation.AddPostIDs(ids...) return pu } // AddPosts adds the "posts" edges to the Post entity. func (pu *ProfileUpdate) AddPosts(p ...*Post) *ProfileUpdate { ids := make([]uuid.UUID, len(p)) for i := range p { ids[i] = p[i].ID } return pu.AddPostIDs(ids...) } // Mutation returns the ProfileMutation object of the builder. func (pu *ProfileUpdate) Mutation() *ProfileMutation { return pu.mutation } // ClearPosts clears all "posts" edges to the Post entity. func (pu *ProfileUpdate) ClearPosts() *ProfileUpdate { pu.mutation.ClearPosts() return pu } // RemovePostIDs removes the "posts" edge to Post entities by IDs. func (pu *ProfileUpdate) RemovePostIDs(ids ...uuid.UUID) *ProfileUpdate { pu.mutation.RemovePostIDs(ids...) return pu } // RemovePosts removes "posts" edges to Post entities. func (pu *ProfileUpdate) RemovePosts(p ...*Post) *ProfileUpdate { ids := make([]uuid.UUID, len(p)) for i := range p { ids[i] = p[i].ID } return pu.RemovePostIDs(ids...) } // Save executes the query and returns the number of nodes affected by the update operation. func (pu *ProfileUpdate) Save(ctx context.Context) (int, error) { pu.defaults() 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) } } // defaults sets the default values of the builder before save. func (pu *ProfileUpdate) defaults() { if _, ok := pu.mutation.UpdatedAt(); !ok && !pu.mutation.UpdatedAtCleared() { v := profile.UpdateDefaultUpdatedAt() pu.mutation.SetUpdatedAt(v) } } 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.UpdatedAt(); ok { _spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value) } if pu.mutation.UpdatedAtCleared() { _spec.ClearField(profile.FieldUpdatedAt, field.TypeTime) } if value, ok := pu.mutation.Name(); ok { _spec.SetField(profile.FieldName, field.TypeString, value) } if pu.mutation.NameCleared() { _spec.ClearField(profile.FieldName, field.TypeString) } if value, ok := pu.mutation.Address(); ok { _spec.SetField(profile.FieldAddress, field.TypeString, value) } if pu.mutation.AddressCleared() { _spec.ClearField(profile.FieldAddress, field.TypeString) } if value, ok := pu.mutation.Phone(); ok { _spec.SetField(profile.FieldPhone, field.TypeString, value) } if pu.mutation.PhoneCleared() { _spec.ClearField(profile.FieldPhone, field.TypeString) } if pu.mutation.PostsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: profile.PostsTable, Columns: []string{profile.PostsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pu.mutation.RemovedPostsIDs(); len(nodes) > 0 && !pu.mutation.PostsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: profile.PostsTable, Columns: []string{profile.PostsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pu.mutation.PostsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: profile.PostsTable, Columns: []string{profile.PostsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } 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 } // SetUpdatedAt sets the "updated_at" field. func (puo *ProfileUpdateOne) SetUpdatedAt(t time.Time) *ProfileUpdateOne { puo.mutation.SetUpdatedAt(t) return puo } // ClearUpdatedAt clears the value of the "updated_at" field. func (puo *ProfileUpdateOne) ClearUpdatedAt() *ProfileUpdateOne { puo.mutation.ClearUpdatedAt() return puo } // SetName sets the "name" field. func (puo *ProfileUpdateOne) SetName(s string) *ProfileUpdateOne { puo.mutation.SetName(s) return puo } // SetNillableName sets the "name" field if the given value is not nil. func (puo *ProfileUpdateOne) SetNillableName(s *string) *ProfileUpdateOne { if s != nil { puo.SetName(*s) } return puo } // ClearName clears the value of the "name" field. func (puo *ProfileUpdateOne) ClearName() *ProfileUpdateOne { puo.mutation.ClearName() return puo } // SetAddress sets the "address" field. func (puo *ProfileUpdateOne) SetAddress(s string) *ProfileUpdateOne { puo.mutation.SetAddress(s) return puo } // SetNillableAddress sets the "address" field if the given value is not nil. func (puo *ProfileUpdateOne) SetNillableAddress(s *string) *ProfileUpdateOne { if s != nil { puo.SetAddress(*s) } return puo } // ClearAddress clears the value of the "address" field. func (puo *ProfileUpdateOne) ClearAddress() *ProfileUpdateOne { puo.mutation.ClearAddress() return puo } // SetPhone sets the "phone" field. func (puo *ProfileUpdateOne) SetPhone(s string) *ProfileUpdateOne { puo.mutation.SetPhone(s) return puo } // SetNillablePhone sets the "phone" field if the given value is not nil. func (puo *ProfileUpdateOne) SetNillablePhone(s *string) *ProfileUpdateOne { if s != nil { puo.SetPhone(*s) } return puo } // ClearPhone clears the value of the "phone" field. func (puo *ProfileUpdateOne) ClearPhone() *ProfileUpdateOne { puo.mutation.ClearPhone() return puo } // AddPostIDs adds the "posts" edge to the Post entity by IDs. func (puo *ProfileUpdateOne) AddPostIDs(ids ...uuid.UUID) *ProfileUpdateOne { puo.mutation.AddPostIDs(ids...) return puo } // AddPosts adds the "posts" edges to the Post entity. func (puo *ProfileUpdateOne) AddPosts(p ...*Post) *ProfileUpdateOne { ids := make([]uuid.UUID, len(p)) for i := range p { ids[i] = p[i].ID } return puo.AddPostIDs(ids...) } // Mutation returns the ProfileMutation object of the builder. func (puo *ProfileUpdateOne) Mutation() *ProfileMutation { return puo.mutation } // ClearPosts clears all "posts" edges to the Post entity. func (puo *ProfileUpdateOne) ClearPosts() *ProfileUpdateOne { puo.mutation.ClearPosts() return puo } // RemovePostIDs removes the "posts" edge to Post entities by IDs. func (puo *ProfileUpdateOne) RemovePostIDs(ids ...uuid.UUID) *ProfileUpdateOne { puo.mutation.RemovePostIDs(ids...) return puo } // RemovePosts removes "posts" edges to Post entities. func (puo *ProfileUpdateOne) RemovePosts(p ...*Post) *ProfileUpdateOne { ids := make([]uuid.UUID, len(p)) for i := range p { ids[i] = p[i].ID } return puo.RemovePostIDs(ids...) } // 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) { puo.defaults() 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) } } // defaults sets the default values of the builder before save. func (puo *ProfileUpdateOne) defaults() { if _, ok := puo.mutation.UpdatedAt(); !ok && !puo.mutation.UpdatedAtCleared() { v := profile.UpdateDefaultUpdatedAt() puo.mutation.SetUpdatedAt(v) } } 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.UpdatedAt(); ok { _spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value) } if puo.mutation.UpdatedAtCleared() { _spec.ClearField(profile.FieldUpdatedAt, field.TypeTime) } if value, ok := puo.mutation.Name(); ok { _spec.SetField(profile.FieldName, field.TypeString, value) } if puo.mutation.NameCleared() { _spec.ClearField(profile.FieldName, field.TypeString) } if value, ok := puo.mutation.Address(); ok { _spec.SetField(profile.FieldAddress, field.TypeString, value) } if puo.mutation.AddressCleared() { _spec.ClearField(profile.FieldAddress, field.TypeString) } if value, ok := puo.mutation.Phone(); ok { _spec.SetField(profile.FieldPhone, field.TypeString, value) } if puo.mutation.PhoneCleared() { _spec.ClearField(profile.FieldPhone, field.TypeString) } if puo.mutation.PostsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: profile.PostsTable, Columns: []string{profile.PostsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := puo.mutation.RemovedPostsIDs(); len(nodes) > 0 && !puo.mutation.PostsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: profile.PostsTable, Columns: []string{profile.PostsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := puo.mutation.PostsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: profile.PostsTable, Columns: []string{profile.PostsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _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 }