// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "tss-rocks-be/ent/post" "tss-rocks-be/ent/postcontent" "tss-rocks-be/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // PostContentUpdate is the builder for updating PostContent entities. type PostContentUpdate struct { config hooks []Hook mutation *PostContentMutation } // Where appends a list predicates to the PostContentUpdate builder. func (pcu *PostContentUpdate) Where(ps ...predicate.PostContent) *PostContentUpdate { pcu.mutation.Where(ps...) return pcu } // SetLanguageCode sets the "language_code" field. func (pcu *PostContentUpdate) SetLanguageCode(pc postcontent.LanguageCode) *PostContentUpdate { pcu.mutation.SetLanguageCode(pc) return pcu } // SetNillableLanguageCode sets the "language_code" field if the given value is not nil. func (pcu *PostContentUpdate) SetNillableLanguageCode(pc *postcontent.LanguageCode) *PostContentUpdate { if pc != nil { pcu.SetLanguageCode(*pc) } return pcu } // SetTitle sets the "title" field. func (pcu *PostContentUpdate) SetTitle(s string) *PostContentUpdate { pcu.mutation.SetTitle(s) return pcu } // SetNillableTitle sets the "title" field if the given value is not nil. func (pcu *PostContentUpdate) SetNillableTitle(s *string) *PostContentUpdate { if s != nil { pcu.SetTitle(*s) } return pcu } // SetContentMarkdown sets the "content_markdown" field. func (pcu *PostContentUpdate) SetContentMarkdown(s string) *PostContentUpdate { pcu.mutation.SetContentMarkdown(s) return pcu } // SetNillableContentMarkdown sets the "content_markdown" field if the given value is not nil. func (pcu *PostContentUpdate) SetNillableContentMarkdown(s *string) *PostContentUpdate { if s != nil { pcu.SetContentMarkdown(*s) } return pcu } // SetSummary sets the "summary" field. func (pcu *PostContentUpdate) SetSummary(s string) *PostContentUpdate { pcu.mutation.SetSummary(s) return pcu } // SetNillableSummary sets the "summary" field if the given value is not nil. func (pcu *PostContentUpdate) SetNillableSummary(s *string) *PostContentUpdate { if s != nil { pcu.SetSummary(*s) } return pcu } // SetMetaKeywords sets the "meta_keywords" field. func (pcu *PostContentUpdate) SetMetaKeywords(s string) *PostContentUpdate { pcu.mutation.SetMetaKeywords(s) return pcu } // SetNillableMetaKeywords sets the "meta_keywords" field if the given value is not nil. func (pcu *PostContentUpdate) SetNillableMetaKeywords(s *string) *PostContentUpdate { if s != nil { pcu.SetMetaKeywords(*s) } return pcu } // ClearMetaKeywords clears the value of the "meta_keywords" field. func (pcu *PostContentUpdate) ClearMetaKeywords() *PostContentUpdate { pcu.mutation.ClearMetaKeywords() return pcu } // SetMetaDescription sets the "meta_description" field. func (pcu *PostContentUpdate) SetMetaDescription(s string) *PostContentUpdate { pcu.mutation.SetMetaDescription(s) return pcu } // SetNillableMetaDescription sets the "meta_description" field if the given value is not nil. func (pcu *PostContentUpdate) SetNillableMetaDescription(s *string) *PostContentUpdate { if s != nil { pcu.SetMetaDescription(*s) } return pcu } // ClearMetaDescription clears the value of the "meta_description" field. func (pcu *PostContentUpdate) ClearMetaDescription() *PostContentUpdate { pcu.mutation.ClearMetaDescription() return pcu } // SetSlug sets the "slug" field. func (pcu *PostContentUpdate) SetSlug(s string) *PostContentUpdate { pcu.mutation.SetSlug(s) return pcu } // SetNillableSlug sets the "slug" field if the given value is not nil. func (pcu *PostContentUpdate) SetNillableSlug(s *string) *PostContentUpdate { if s != nil { pcu.SetSlug(*s) } return pcu } // SetPostID sets the "post" edge to the Post entity by ID. func (pcu *PostContentUpdate) SetPostID(id int) *PostContentUpdate { pcu.mutation.SetPostID(id) return pcu } // SetNillablePostID sets the "post" edge to the Post entity by ID if the given value is not nil. func (pcu *PostContentUpdate) SetNillablePostID(id *int) *PostContentUpdate { if id != nil { pcu = pcu.SetPostID(*id) } return pcu } // SetPost sets the "post" edge to the Post entity. func (pcu *PostContentUpdate) SetPost(p *Post) *PostContentUpdate { return pcu.SetPostID(p.ID) } // Mutation returns the PostContentMutation object of the builder. func (pcu *PostContentUpdate) Mutation() *PostContentMutation { return pcu.mutation } // ClearPost clears the "post" edge to the Post entity. func (pcu *PostContentUpdate) ClearPost() *PostContentUpdate { pcu.mutation.ClearPost() return pcu } // Save executes the query and returns the number of nodes affected by the update operation. func (pcu *PostContentUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, pcu.sqlSave, pcu.mutation, pcu.hooks) } // SaveX is like Save, but panics if an error occurs. func (pcu *PostContentUpdate) SaveX(ctx context.Context) int { affected, err := pcu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (pcu *PostContentUpdate) Exec(ctx context.Context) error { _, err := pcu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (pcu *PostContentUpdate) ExecX(ctx context.Context) { if err := pcu.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (pcu *PostContentUpdate) check() error { if v, ok := pcu.mutation.LanguageCode(); ok { if err := postcontent.LanguageCodeValidator(v); err != nil { return &ValidationError{Name: "language_code", err: fmt.Errorf(`ent: validator failed for field "PostContent.language_code": %w`, err)} } } if v, ok := pcu.mutation.Title(); ok { if err := postcontent.TitleValidator(v); err != nil { return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "PostContent.title": %w`, err)} } } if v, ok := pcu.mutation.ContentMarkdown(); ok { if err := postcontent.ContentMarkdownValidator(v); err != nil { return &ValidationError{Name: "content_markdown", err: fmt.Errorf(`ent: validator failed for field "PostContent.content_markdown": %w`, err)} } } if v, ok := pcu.mutation.Summary(); ok { if err := postcontent.SummaryValidator(v); err != nil { return &ValidationError{Name: "summary", err: fmt.Errorf(`ent: validator failed for field "PostContent.summary": %w`, err)} } } if v, ok := pcu.mutation.Slug(); ok { if err := postcontent.SlugValidator(v); err != nil { return &ValidationError{Name: "slug", err: fmt.Errorf(`ent: validator failed for field "PostContent.slug": %w`, err)} } } return nil } func (pcu *PostContentUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := pcu.check(); err != nil { return n, err } _spec := sqlgraph.NewUpdateSpec(postcontent.Table, postcontent.Columns, sqlgraph.NewFieldSpec(postcontent.FieldID, field.TypeInt)) if ps := pcu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := pcu.mutation.LanguageCode(); ok { _spec.SetField(postcontent.FieldLanguageCode, field.TypeEnum, value) } if value, ok := pcu.mutation.Title(); ok { _spec.SetField(postcontent.FieldTitle, field.TypeString, value) } if value, ok := pcu.mutation.ContentMarkdown(); ok { _spec.SetField(postcontent.FieldContentMarkdown, field.TypeString, value) } if value, ok := pcu.mutation.Summary(); ok { _spec.SetField(postcontent.FieldSummary, field.TypeString, value) } if value, ok := pcu.mutation.MetaKeywords(); ok { _spec.SetField(postcontent.FieldMetaKeywords, field.TypeString, value) } if pcu.mutation.MetaKeywordsCleared() { _spec.ClearField(postcontent.FieldMetaKeywords, field.TypeString) } if value, ok := pcu.mutation.MetaDescription(); ok { _spec.SetField(postcontent.FieldMetaDescription, field.TypeString, value) } if pcu.mutation.MetaDescriptionCleared() { _spec.ClearField(postcontent.FieldMetaDescription, field.TypeString) } if value, ok := pcu.mutation.Slug(); ok { _spec.SetField(postcontent.FieldSlug, field.TypeString, value) } if pcu.mutation.PostCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: postcontent.PostTable, Columns: []string{postcontent.PostColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pcu.mutation.PostIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: postcontent.PostTable, Columns: []string{postcontent.PostColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt), }, } 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, pcu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{postcontent.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } pcu.mutation.done = true return n, nil } // PostContentUpdateOne is the builder for updating a single PostContent entity. type PostContentUpdateOne struct { config fields []string hooks []Hook mutation *PostContentMutation } // SetLanguageCode sets the "language_code" field. func (pcuo *PostContentUpdateOne) SetLanguageCode(pc postcontent.LanguageCode) *PostContentUpdateOne { pcuo.mutation.SetLanguageCode(pc) return pcuo } // SetNillableLanguageCode sets the "language_code" field if the given value is not nil. func (pcuo *PostContentUpdateOne) SetNillableLanguageCode(pc *postcontent.LanguageCode) *PostContentUpdateOne { if pc != nil { pcuo.SetLanguageCode(*pc) } return pcuo } // SetTitle sets the "title" field. func (pcuo *PostContentUpdateOne) SetTitle(s string) *PostContentUpdateOne { pcuo.mutation.SetTitle(s) return pcuo } // SetNillableTitle sets the "title" field if the given value is not nil. func (pcuo *PostContentUpdateOne) SetNillableTitle(s *string) *PostContentUpdateOne { if s != nil { pcuo.SetTitle(*s) } return pcuo } // SetContentMarkdown sets the "content_markdown" field. func (pcuo *PostContentUpdateOne) SetContentMarkdown(s string) *PostContentUpdateOne { pcuo.mutation.SetContentMarkdown(s) return pcuo } // SetNillableContentMarkdown sets the "content_markdown" field if the given value is not nil. func (pcuo *PostContentUpdateOne) SetNillableContentMarkdown(s *string) *PostContentUpdateOne { if s != nil { pcuo.SetContentMarkdown(*s) } return pcuo } // SetSummary sets the "summary" field. func (pcuo *PostContentUpdateOne) SetSummary(s string) *PostContentUpdateOne { pcuo.mutation.SetSummary(s) return pcuo } // SetNillableSummary sets the "summary" field if the given value is not nil. func (pcuo *PostContentUpdateOne) SetNillableSummary(s *string) *PostContentUpdateOne { if s != nil { pcuo.SetSummary(*s) } return pcuo } // SetMetaKeywords sets the "meta_keywords" field. func (pcuo *PostContentUpdateOne) SetMetaKeywords(s string) *PostContentUpdateOne { pcuo.mutation.SetMetaKeywords(s) return pcuo } // SetNillableMetaKeywords sets the "meta_keywords" field if the given value is not nil. func (pcuo *PostContentUpdateOne) SetNillableMetaKeywords(s *string) *PostContentUpdateOne { if s != nil { pcuo.SetMetaKeywords(*s) } return pcuo } // ClearMetaKeywords clears the value of the "meta_keywords" field. func (pcuo *PostContentUpdateOne) ClearMetaKeywords() *PostContentUpdateOne { pcuo.mutation.ClearMetaKeywords() return pcuo } // SetMetaDescription sets the "meta_description" field. func (pcuo *PostContentUpdateOne) SetMetaDescription(s string) *PostContentUpdateOne { pcuo.mutation.SetMetaDescription(s) return pcuo } // SetNillableMetaDescription sets the "meta_description" field if the given value is not nil. func (pcuo *PostContentUpdateOne) SetNillableMetaDescription(s *string) *PostContentUpdateOne { if s != nil { pcuo.SetMetaDescription(*s) } return pcuo } // ClearMetaDescription clears the value of the "meta_description" field. func (pcuo *PostContentUpdateOne) ClearMetaDescription() *PostContentUpdateOne { pcuo.mutation.ClearMetaDescription() return pcuo } // SetSlug sets the "slug" field. func (pcuo *PostContentUpdateOne) SetSlug(s string) *PostContentUpdateOne { pcuo.mutation.SetSlug(s) return pcuo } // SetNillableSlug sets the "slug" field if the given value is not nil. func (pcuo *PostContentUpdateOne) SetNillableSlug(s *string) *PostContentUpdateOne { if s != nil { pcuo.SetSlug(*s) } return pcuo } // SetPostID sets the "post" edge to the Post entity by ID. func (pcuo *PostContentUpdateOne) SetPostID(id int) *PostContentUpdateOne { pcuo.mutation.SetPostID(id) return pcuo } // SetNillablePostID sets the "post" edge to the Post entity by ID if the given value is not nil. func (pcuo *PostContentUpdateOne) SetNillablePostID(id *int) *PostContentUpdateOne { if id != nil { pcuo = pcuo.SetPostID(*id) } return pcuo } // SetPost sets the "post" edge to the Post entity. func (pcuo *PostContentUpdateOne) SetPost(p *Post) *PostContentUpdateOne { return pcuo.SetPostID(p.ID) } // Mutation returns the PostContentMutation object of the builder. func (pcuo *PostContentUpdateOne) Mutation() *PostContentMutation { return pcuo.mutation } // ClearPost clears the "post" edge to the Post entity. func (pcuo *PostContentUpdateOne) ClearPost() *PostContentUpdateOne { pcuo.mutation.ClearPost() return pcuo } // Where appends a list predicates to the PostContentUpdate builder. func (pcuo *PostContentUpdateOne) Where(ps ...predicate.PostContent) *PostContentUpdateOne { pcuo.mutation.Where(ps...) return pcuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (pcuo *PostContentUpdateOne) Select(field string, fields ...string) *PostContentUpdateOne { pcuo.fields = append([]string{field}, fields...) return pcuo } // Save executes the query and returns the updated PostContent entity. func (pcuo *PostContentUpdateOne) Save(ctx context.Context) (*PostContent, error) { return withHooks(ctx, pcuo.sqlSave, pcuo.mutation, pcuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (pcuo *PostContentUpdateOne) SaveX(ctx context.Context) *PostContent { node, err := pcuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (pcuo *PostContentUpdateOne) Exec(ctx context.Context) error { _, err := pcuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (pcuo *PostContentUpdateOne) ExecX(ctx context.Context) { if err := pcuo.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (pcuo *PostContentUpdateOne) check() error { if v, ok := pcuo.mutation.LanguageCode(); ok { if err := postcontent.LanguageCodeValidator(v); err != nil { return &ValidationError{Name: "language_code", err: fmt.Errorf(`ent: validator failed for field "PostContent.language_code": %w`, err)} } } if v, ok := pcuo.mutation.Title(); ok { if err := postcontent.TitleValidator(v); err != nil { return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "PostContent.title": %w`, err)} } } if v, ok := pcuo.mutation.ContentMarkdown(); ok { if err := postcontent.ContentMarkdownValidator(v); err != nil { return &ValidationError{Name: "content_markdown", err: fmt.Errorf(`ent: validator failed for field "PostContent.content_markdown": %w`, err)} } } if v, ok := pcuo.mutation.Summary(); ok { if err := postcontent.SummaryValidator(v); err != nil { return &ValidationError{Name: "summary", err: fmt.Errorf(`ent: validator failed for field "PostContent.summary": %w`, err)} } } if v, ok := pcuo.mutation.Slug(); ok { if err := postcontent.SlugValidator(v); err != nil { return &ValidationError{Name: "slug", err: fmt.Errorf(`ent: validator failed for field "PostContent.slug": %w`, err)} } } return nil } func (pcuo *PostContentUpdateOne) sqlSave(ctx context.Context) (_node *PostContent, err error) { if err := pcuo.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(postcontent.Table, postcontent.Columns, sqlgraph.NewFieldSpec(postcontent.FieldID, field.TypeInt)) id, ok := pcuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PostContent.id" for update`)} } _spec.Node.ID.Value = id if fields := pcuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, postcontent.FieldID) for _, f := range fields { if !postcontent.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != postcontent.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := pcuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := pcuo.mutation.LanguageCode(); ok { _spec.SetField(postcontent.FieldLanguageCode, field.TypeEnum, value) } if value, ok := pcuo.mutation.Title(); ok { _spec.SetField(postcontent.FieldTitle, field.TypeString, value) } if value, ok := pcuo.mutation.ContentMarkdown(); ok { _spec.SetField(postcontent.FieldContentMarkdown, field.TypeString, value) } if value, ok := pcuo.mutation.Summary(); ok { _spec.SetField(postcontent.FieldSummary, field.TypeString, value) } if value, ok := pcuo.mutation.MetaKeywords(); ok { _spec.SetField(postcontent.FieldMetaKeywords, field.TypeString, value) } if pcuo.mutation.MetaKeywordsCleared() { _spec.ClearField(postcontent.FieldMetaKeywords, field.TypeString) } if value, ok := pcuo.mutation.MetaDescription(); ok { _spec.SetField(postcontent.FieldMetaDescription, field.TypeString, value) } if pcuo.mutation.MetaDescriptionCleared() { _spec.ClearField(postcontent.FieldMetaDescription, field.TypeString) } if value, ok := pcuo.mutation.Slug(); ok { _spec.SetField(postcontent.FieldSlug, field.TypeString, value) } if pcuo.mutation.PostCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: postcontent.PostTable, Columns: []string{postcontent.PostColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := pcuo.mutation.PostIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: postcontent.PostTable, Columns: []string{postcontent.PostColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &PostContent{config: pcuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, pcuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{postcontent.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } pcuo.mutation.done = true return _node, nil }