github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/post_update.go (about)

     1  // Code generated by entc, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  	"time"
    10  
    11  	"entgo.io/ent/dialect/sql"
    12  	"entgo.io/ent/dialect/sql/sqlgraph"
    13  	"entgo.io/ent/schema/field"
    14  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/comment"
    15  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/file"
    16  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/post"
    17  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/predicate"
    18  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/topic"
    19  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/user"
    20  )
    21  
    22  // PostUpdate is the builder for updating Post entities.
    23  type PostUpdate struct {
    24  	config
    25  	hooks    []Hook
    26  	mutation *PostMutation
    27  }
    28  
    29  // Where appends a list predicates to the PostUpdate builder.
    30  func (pu *PostUpdate) Where(ps ...predicate.Post) *PostUpdate {
    31  	pu.mutation.Where(ps...)
    32  	return pu
    33  }
    34  
    35  // SetUpdatedAt sets the "updated_at" field.
    36  func (pu *PostUpdate) SetUpdatedAt(t time.Time) *PostUpdate {
    37  	pu.mutation.SetUpdatedAt(t)
    38  	return pu
    39  }
    40  
    41  // SetDeletedAt sets the "deleted_at" field.
    42  func (pu *PostUpdate) SetDeletedAt(t time.Time) *PostUpdate {
    43  	pu.mutation.SetDeletedAt(t)
    44  	return pu
    45  }
    46  
    47  // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
    48  func (pu *PostUpdate) SetNillableDeletedAt(t *time.Time) *PostUpdate {
    49  	if t != nil {
    50  		pu.SetDeletedAt(*t)
    51  	}
    52  	return pu
    53  }
    54  
    55  // ClearDeletedAt clears the value of the "deleted_at" field.
    56  func (pu *PostUpdate) ClearDeletedAt() *PostUpdate {
    57  	pu.mutation.ClearDeletedAt()
    58  	return pu
    59  }
    60  
    61  // SetName sets the "name" field.
    62  func (pu *PostUpdate) SetName(s string) *PostUpdate {
    63  	pu.mutation.SetName(s)
    64  	return pu
    65  }
    66  
    67  // SetSlug sets the "slug" field.
    68  func (pu *PostUpdate) SetSlug(s string) *PostUpdate {
    69  	pu.mutation.SetSlug(s)
    70  	return pu
    71  }
    72  
    73  // SetDescription sets the "description" field.
    74  func (pu *PostUpdate) SetDescription(s string) *PostUpdate {
    75  	pu.mutation.SetDescription(s)
    76  	return pu
    77  }
    78  
    79  // SetNillableDescription sets the "description" field if the given value is not nil.
    80  func (pu *PostUpdate) SetNillableDescription(s *string) *PostUpdate {
    81  	if s != nil {
    82  		pu.SetDescription(*s)
    83  	}
    84  	return pu
    85  }
    86  
    87  // ClearDescription clears the value of the "description" field.
    88  func (pu *PostUpdate) ClearDescription() *PostUpdate {
    89  	pu.mutation.ClearDescription()
    90  	return pu
    91  }
    92  
    93  // SetContent sets the "content" field.
    94  func (pu *PostUpdate) SetContent(s string) *PostUpdate {
    95  	pu.mutation.SetContent(s)
    96  	return pu
    97  }
    98  
    99  // SetContentHTML sets the "content_html" field.
   100  func (pu *PostUpdate) SetContentHTML(s string) *PostUpdate {
   101  	pu.mutation.SetContentHTML(s)
   102  	return pu
   103  }
   104  
   105  // SetViewCount sets the "view_count" field.
   106  func (pu *PostUpdate) SetViewCount(i int64) *PostUpdate {
   107  	pu.mutation.ResetViewCount()
   108  	pu.mutation.SetViewCount(i)
   109  	return pu
   110  }
   111  
   112  // SetNillableViewCount sets the "view_count" field if the given value is not nil.
   113  func (pu *PostUpdate) SetNillableViewCount(i *int64) *PostUpdate {
   114  	if i != nil {
   115  		pu.SetViewCount(*i)
   116  	}
   117  	return pu
   118  }
   119  
   120  // AddViewCount adds i to the "view_count" field.
   121  func (pu *PostUpdate) AddViewCount(i int64) *PostUpdate {
   122  	pu.mutation.AddViewCount(i)
   123  	return pu
   124  }
   125  
   126  // SetCommentCount sets the "comment_count" field.
   127  func (pu *PostUpdate) SetCommentCount(i int64) *PostUpdate {
   128  	pu.mutation.ResetCommentCount()
   129  	pu.mutation.SetCommentCount(i)
   130  	return pu
   131  }
   132  
   133  // SetNillableCommentCount sets the "comment_count" field if the given value is not nil.
   134  func (pu *PostUpdate) SetNillableCommentCount(i *int64) *PostUpdate {
   135  	if i != nil {
   136  		pu.SetCommentCount(*i)
   137  	}
   138  	return pu
   139  }
   140  
   141  // AddCommentCount adds i to the "comment_count" field.
   142  func (pu *PostUpdate) AddCommentCount(i int64) *PostUpdate {
   143  	pu.mutation.AddCommentCount(i)
   144  	return pu
   145  }
   146  
   147  // SetRatingCount sets the "rating_count" field.
   148  func (pu *PostUpdate) SetRatingCount(i int64) *PostUpdate {
   149  	pu.mutation.ResetRatingCount()
   150  	pu.mutation.SetRatingCount(i)
   151  	return pu
   152  }
   153  
   154  // SetNillableRatingCount sets the "rating_count" field if the given value is not nil.
   155  func (pu *PostUpdate) SetNillableRatingCount(i *int64) *PostUpdate {
   156  	if i != nil {
   157  		pu.SetRatingCount(*i)
   158  	}
   159  	return pu
   160  }
   161  
   162  // AddRatingCount adds i to the "rating_count" field.
   163  func (pu *PostUpdate) AddRatingCount(i int64) *PostUpdate {
   164  	pu.mutation.AddRatingCount(i)
   165  	return pu
   166  }
   167  
   168  // ClearRatingCount clears the value of the "rating_count" field.
   169  func (pu *PostUpdate) ClearRatingCount() *PostUpdate {
   170  	pu.mutation.ClearRatingCount()
   171  	return pu
   172  }
   173  
   174  // SetRatingTotal sets the "rating_total" field.
   175  func (pu *PostUpdate) SetRatingTotal(i int64) *PostUpdate {
   176  	pu.mutation.ResetRatingTotal()
   177  	pu.mutation.SetRatingTotal(i)
   178  	return pu
   179  }
   180  
   181  // SetNillableRatingTotal sets the "rating_total" field if the given value is not nil.
   182  func (pu *PostUpdate) SetNillableRatingTotal(i *int64) *PostUpdate {
   183  	if i != nil {
   184  		pu.SetRatingTotal(*i)
   185  	}
   186  	return pu
   187  }
   188  
   189  // AddRatingTotal adds i to the "rating_total" field.
   190  func (pu *PostUpdate) AddRatingTotal(i int64) *PostUpdate {
   191  	pu.mutation.AddRatingTotal(i)
   192  	return pu
   193  }
   194  
   195  // ClearRatingTotal clears the value of the "rating_total" field.
   196  func (pu *PostUpdate) ClearRatingTotal() *PostUpdate {
   197  	pu.mutation.ClearRatingTotal()
   198  	return pu
   199  }
   200  
   201  // SetDraft sets the "draft" field.
   202  func (pu *PostUpdate) SetDraft(b bool) *PostUpdate {
   203  	pu.mutation.SetDraft(b)
   204  	return pu
   205  }
   206  
   207  // SetNillableDraft sets the "draft" field if the given value is not nil.
   208  func (pu *PostUpdate) SetNillableDraft(b *bool) *PostUpdate {
   209  	if b != nil {
   210  		pu.SetDraft(*b)
   211  	}
   212  	return pu
   213  }
   214  
   215  // ClearDraft clears the value of the "draft" field.
   216  func (pu *PostUpdate) ClearDraft() *PostUpdate {
   217  	pu.mutation.ClearDraft()
   218  	return pu
   219  }
   220  
   221  // SetApproved sets the "approved" field.
   222  func (pu *PostUpdate) SetApproved(b bool) *PostUpdate {
   223  	pu.mutation.SetApproved(b)
   224  	return pu
   225  }
   226  
   227  // SetNillableApproved sets the "approved" field if the given value is not nil.
   228  func (pu *PostUpdate) SetNillableApproved(b *bool) *PostUpdate {
   229  	if b != nil {
   230  		pu.SetApproved(*b)
   231  	}
   232  	return pu
   233  }
   234  
   235  // ClearApproved clears the value of the "approved" field.
   236  func (pu *PostUpdate) ClearApproved() *PostUpdate {
   237  	pu.mutation.ClearApproved()
   238  	return pu
   239  }
   240  
   241  // SetFeaturedImageID sets the "featured_image_id" field.
   242  func (pu *PostUpdate) SetFeaturedImageID(i int) *PostUpdate {
   243  	pu.mutation.SetFeaturedImageID(i)
   244  	return pu
   245  }
   246  
   247  // SetNillableFeaturedImageID sets the "featured_image_id" field if the given value is not nil.
   248  func (pu *PostUpdate) SetNillableFeaturedImageID(i *int) *PostUpdate {
   249  	if i != nil {
   250  		pu.SetFeaturedImageID(*i)
   251  	}
   252  	return pu
   253  }
   254  
   255  // ClearFeaturedImageID clears the value of the "featured_image_id" field.
   256  func (pu *PostUpdate) ClearFeaturedImageID() *PostUpdate {
   257  	pu.mutation.ClearFeaturedImageID()
   258  	return pu
   259  }
   260  
   261  // SetUserID sets the "user_id" field.
   262  func (pu *PostUpdate) SetUserID(i int) *PostUpdate {
   263  	pu.mutation.SetUserID(i)
   264  	return pu
   265  }
   266  
   267  // SetNillableUserID sets the "user_id" field if the given value is not nil.
   268  func (pu *PostUpdate) SetNillableUserID(i *int) *PostUpdate {
   269  	if i != nil {
   270  		pu.SetUserID(*i)
   271  	}
   272  	return pu
   273  }
   274  
   275  // ClearUserID clears the value of the "user_id" field.
   276  func (pu *PostUpdate) ClearUserID() *PostUpdate {
   277  	pu.mutation.ClearUserID()
   278  	return pu
   279  }
   280  
   281  // SetUser sets the "user" edge to the User entity.
   282  func (pu *PostUpdate) SetUser(u *User) *PostUpdate {
   283  	return pu.SetUserID(u.ID)
   284  }
   285  
   286  // AddTopicIDs adds the "topics" edge to the Topic entity by IDs.
   287  func (pu *PostUpdate) AddTopicIDs(ids ...int) *PostUpdate {
   288  	pu.mutation.AddTopicIDs(ids...)
   289  	return pu
   290  }
   291  
   292  // AddTopics adds the "topics" edges to the Topic entity.
   293  func (pu *PostUpdate) AddTopics(t ...*Topic) *PostUpdate {
   294  	ids := make([]int, len(t))
   295  	for i := range t {
   296  		ids[i] = t[i].ID
   297  	}
   298  	return pu.AddTopicIDs(ids...)
   299  }
   300  
   301  // SetFeaturedImage sets the "featured_image" edge to the File entity.
   302  func (pu *PostUpdate) SetFeaturedImage(f *File) *PostUpdate {
   303  	return pu.SetFeaturedImageID(f.ID)
   304  }
   305  
   306  // AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
   307  func (pu *PostUpdate) AddCommentIDs(ids ...int) *PostUpdate {
   308  	pu.mutation.AddCommentIDs(ids...)
   309  	return pu
   310  }
   311  
   312  // AddComments adds the "comments" edges to the Comment entity.
   313  func (pu *PostUpdate) AddComments(c ...*Comment) *PostUpdate {
   314  	ids := make([]int, len(c))
   315  	for i := range c {
   316  		ids[i] = c[i].ID
   317  	}
   318  	return pu.AddCommentIDs(ids...)
   319  }
   320  
   321  // Mutation returns the PostMutation object of the builder.
   322  func (pu *PostUpdate) Mutation() *PostMutation {
   323  	return pu.mutation
   324  }
   325  
   326  // ClearUser clears the "user" edge to the User entity.
   327  func (pu *PostUpdate) ClearUser() *PostUpdate {
   328  	pu.mutation.ClearUser()
   329  	return pu
   330  }
   331  
   332  // ClearTopics clears all "topics" edges to the Topic entity.
   333  func (pu *PostUpdate) ClearTopics() *PostUpdate {
   334  	pu.mutation.ClearTopics()
   335  	return pu
   336  }
   337  
   338  // RemoveTopicIDs removes the "topics" edge to Topic entities by IDs.
   339  func (pu *PostUpdate) RemoveTopicIDs(ids ...int) *PostUpdate {
   340  	pu.mutation.RemoveTopicIDs(ids...)
   341  	return pu
   342  }
   343  
   344  // RemoveTopics removes "topics" edges to Topic entities.
   345  func (pu *PostUpdate) RemoveTopics(t ...*Topic) *PostUpdate {
   346  	ids := make([]int, len(t))
   347  	for i := range t {
   348  		ids[i] = t[i].ID
   349  	}
   350  	return pu.RemoveTopicIDs(ids...)
   351  }
   352  
   353  // ClearFeaturedImage clears the "featured_image" edge to the File entity.
   354  func (pu *PostUpdate) ClearFeaturedImage() *PostUpdate {
   355  	pu.mutation.ClearFeaturedImage()
   356  	return pu
   357  }
   358  
   359  // ClearComments clears all "comments" edges to the Comment entity.
   360  func (pu *PostUpdate) ClearComments() *PostUpdate {
   361  	pu.mutation.ClearComments()
   362  	return pu
   363  }
   364  
   365  // RemoveCommentIDs removes the "comments" edge to Comment entities by IDs.
   366  func (pu *PostUpdate) RemoveCommentIDs(ids ...int) *PostUpdate {
   367  	pu.mutation.RemoveCommentIDs(ids...)
   368  	return pu
   369  }
   370  
   371  // RemoveComments removes "comments" edges to Comment entities.
   372  func (pu *PostUpdate) RemoveComments(c ...*Comment) *PostUpdate {
   373  	ids := make([]int, len(c))
   374  	for i := range c {
   375  		ids[i] = c[i].ID
   376  	}
   377  	return pu.RemoveCommentIDs(ids...)
   378  }
   379  
   380  // Save executes the query and returns the number of nodes affected by the update operation.
   381  func (pu *PostUpdate) Save(ctx context.Context) (int, error) {
   382  	var (
   383  		err      error
   384  		affected int
   385  	)
   386  	pu.defaults()
   387  	if len(pu.hooks) == 0 {
   388  		affected, err = pu.sqlSave(ctx)
   389  	} else {
   390  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   391  			mutation, ok := m.(*PostMutation)
   392  			if !ok {
   393  				return nil, fmt.Errorf("unexpected mutation type %T", m)
   394  			}
   395  			pu.mutation = mutation
   396  			affected, err = pu.sqlSave(ctx)
   397  			mutation.done = true
   398  			return affected, err
   399  		})
   400  		for i := len(pu.hooks) - 1; i >= 0; i-- {
   401  			if pu.hooks[i] == nil {
   402  				return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
   403  			}
   404  			mut = pu.hooks[i](mut)
   405  		}
   406  		if _, err := mut.Mutate(ctx, pu.mutation); err != nil {
   407  			return 0, err
   408  		}
   409  	}
   410  	return affected, err
   411  }
   412  
   413  // SaveX is like Save, but panics if an error occurs.
   414  func (pu *PostUpdate) SaveX(ctx context.Context) int {
   415  	affected, err := pu.Save(ctx)
   416  	if err != nil {
   417  		panic(err)
   418  	}
   419  	return affected
   420  }
   421  
   422  // Exec executes the query.
   423  func (pu *PostUpdate) Exec(ctx context.Context) error {
   424  	_, err := pu.Save(ctx)
   425  	return err
   426  }
   427  
   428  // ExecX is like Exec, but panics if an error occurs.
   429  func (pu *PostUpdate) ExecX(ctx context.Context) {
   430  	if err := pu.Exec(ctx); err != nil {
   431  		panic(err)
   432  	}
   433  }
   434  
   435  // defaults sets the default values of the builder before save.
   436  func (pu *PostUpdate) defaults() {
   437  	if _, ok := pu.mutation.UpdatedAt(); !ok {
   438  		v := post.UpdateDefaultUpdatedAt()
   439  		pu.mutation.SetUpdatedAt(v)
   440  	}
   441  }
   442  
   443  func (pu *PostUpdate) sqlSave(ctx context.Context) (n int, err error) {
   444  	_spec := &sqlgraph.UpdateSpec{
   445  		Node: &sqlgraph.NodeSpec{
   446  			Table:   post.Table,
   447  			Columns: post.Columns,
   448  			ID: &sqlgraph.FieldSpec{
   449  				Type:   field.TypeInt,
   450  				Column: post.FieldID,
   451  			},
   452  		},
   453  	}
   454  	if ps := pu.mutation.predicates; len(ps) > 0 {
   455  		_spec.Predicate = func(selector *sql.Selector) {
   456  			for i := range ps {
   457  				ps[i](selector)
   458  			}
   459  		}
   460  	}
   461  	if value, ok := pu.mutation.UpdatedAt(); ok {
   462  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   463  			Type:   field.TypeTime,
   464  			Value:  value,
   465  			Column: post.FieldUpdatedAt,
   466  		})
   467  	}
   468  	if value, ok := pu.mutation.DeletedAt(); ok {
   469  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   470  			Type:   field.TypeTime,
   471  			Value:  value,
   472  			Column: post.FieldDeletedAt,
   473  		})
   474  	}
   475  	if pu.mutation.DeletedAtCleared() {
   476  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   477  			Type:   field.TypeTime,
   478  			Column: post.FieldDeletedAt,
   479  		})
   480  	}
   481  	if value, ok := pu.mutation.Name(); ok {
   482  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   483  			Type:   field.TypeString,
   484  			Value:  value,
   485  			Column: post.FieldName,
   486  		})
   487  	}
   488  	if value, ok := pu.mutation.Slug(); ok {
   489  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   490  			Type:   field.TypeString,
   491  			Value:  value,
   492  			Column: post.FieldSlug,
   493  		})
   494  	}
   495  	if value, ok := pu.mutation.Description(); ok {
   496  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   497  			Type:   field.TypeString,
   498  			Value:  value,
   499  			Column: post.FieldDescription,
   500  		})
   501  	}
   502  	if pu.mutation.DescriptionCleared() {
   503  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   504  			Type:   field.TypeString,
   505  			Column: post.FieldDescription,
   506  		})
   507  	}
   508  	if value, ok := pu.mutation.Content(); ok {
   509  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   510  			Type:   field.TypeString,
   511  			Value:  value,
   512  			Column: post.FieldContent,
   513  		})
   514  	}
   515  	if value, ok := pu.mutation.ContentHTML(); ok {
   516  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   517  			Type:   field.TypeString,
   518  			Value:  value,
   519  			Column: post.FieldContentHTML,
   520  		})
   521  	}
   522  	if value, ok := pu.mutation.ViewCount(); ok {
   523  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   524  			Type:   field.TypeInt64,
   525  			Value:  value,
   526  			Column: post.FieldViewCount,
   527  		})
   528  	}
   529  	if value, ok := pu.mutation.AddedViewCount(); ok {
   530  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   531  			Type:   field.TypeInt64,
   532  			Value:  value,
   533  			Column: post.FieldViewCount,
   534  		})
   535  	}
   536  	if value, ok := pu.mutation.CommentCount(); ok {
   537  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   538  			Type:   field.TypeInt64,
   539  			Value:  value,
   540  			Column: post.FieldCommentCount,
   541  		})
   542  	}
   543  	if value, ok := pu.mutation.AddedCommentCount(); ok {
   544  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   545  			Type:   field.TypeInt64,
   546  			Value:  value,
   547  			Column: post.FieldCommentCount,
   548  		})
   549  	}
   550  	if value, ok := pu.mutation.RatingCount(); ok {
   551  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   552  			Type:   field.TypeInt64,
   553  			Value:  value,
   554  			Column: post.FieldRatingCount,
   555  		})
   556  	}
   557  	if value, ok := pu.mutation.AddedRatingCount(); ok {
   558  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   559  			Type:   field.TypeInt64,
   560  			Value:  value,
   561  			Column: post.FieldRatingCount,
   562  		})
   563  	}
   564  	if pu.mutation.RatingCountCleared() {
   565  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   566  			Type:   field.TypeInt64,
   567  			Column: post.FieldRatingCount,
   568  		})
   569  	}
   570  	if value, ok := pu.mutation.RatingTotal(); ok {
   571  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   572  			Type:   field.TypeInt64,
   573  			Value:  value,
   574  			Column: post.FieldRatingTotal,
   575  		})
   576  	}
   577  	if value, ok := pu.mutation.AddedRatingTotal(); ok {
   578  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   579  			Type:   field.TypeInt64,
   580  			Value:  value,
   581  			Column: post.FieldRatingTotal,
   582  		})
   583  	}
   584  	if pu.mutation.RatingTotalCleared() {
   585  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   586  			Type:   field.TypeInt64,
   587  			Column: post.FieldRatingTotal,
   588  		})
   589  	}
   590  	if value, ok := pu.mutation.Draft(); ok {
   591  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   592  			Type:   field.TypeBool,
   593  			Value:  value,
   594  			Column: post.FieldDraft,
   595  		})
   596  	}
   597  	if pu.mutation.DraftCleared() {
   598  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   599  			Type:   field.TypeBool,
   600  			Column: post.FieldDraft,
   601  		})
   602  	}
   603  	if value, ok := pu.mutation.Approved(); ok {
   604  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   605  			Type:   field.TypeBool,
   606  			Value:  value,
   607  			Column: post.FieldApproved,
   608  		})
   609  	}
   610  	if pu.mutation.ApprovedCleared() {
   611  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   612  			Type:   field.TypeBool,
   613  			Column: post.FieldApproved,
   614  		})
   615  	}
   616  	if pu.mutation.UserCleared() {
   617  		edge := &sqlgraph.EdgeSpec{
   618  			Rel:     sqlgraph.M2O,
   619  			Inverse: true,
   620  			Table:   post.UserTable,
   621  			Columns: []string{post.UserColumn},
   622  			Bidi:    false,
   623  			Target: &sqlgraph.EdgeTarget{
   624  				IDSpec: &sqlgraph.FieldSpec{
   625  					Type:   field.TypeInt,
   626  					Column: user.FieldID,
   627  				},
   628  			},
   629  		}
   630  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   631  	}
   632  	if nodes := pu.mutation.UserIDs(); len(nodes) > 0 {
   633  		edge := &sqlgraph.EdgeSpec{
   634  			Rel:     sqlgraph.M2O,
   635  			Inverse: true,
   636  			Table:   post.UserTable,
   637  			Columns: []string{post.UserColumn},
   638  			Bidi:    false,
   639  			Target: &sqlgraph.EdgeTarget{
   640  				IDSpec: &sqlgraph.FieldSpec{
   641  					Type:   field.TypeInt,
   642  					Column: user.FieldID,
   643  				},
   644  			},
   645  		}
   646  		for _, k := range nodes {
   647  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   648  		}
   649  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
   650  	}
   651  	if pu.mutation.TopicsCleared() {
   652  		edge := &sqlgraph.EdgeSpec{
   653  			Rel:     sqlgraph.M2M,
   654  			Inverse: true,
   655  			Table:   post.TopicsTable,
   656  			Columns: post.TopicsPrimaryKey,
   657  			Bidi:    false,
   658  			Target: &sqlgraph.EdgeTarget{
   659  				IDSpec: &sqlgraph.FieldSpec{
   660  					Type:   field.TypeInt,
   661  					Column: topic.FieldID,
   662  				},
   663  			},
   664  		}
   665  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   666  	}
   667  	if nodes := pu.mutation.RemovedTopicsIDs(); len(nodes) > 0 && !pu.mutation.TopicsCleared() {
   668  		edge := &sqlgraph.EdgeSpec{
   669  			Rel:     sqlgraph.M2M,
   670  			Inverse: true,
   671  			Table:   post.TopicsTable,
   672  			Columns: post.TopicsPrimaryKey,
   673  			Bidi:    false,
   674  			Target: &sqlgraph.EdgeTarget{
   675  				IDSpec: &sqlgraph.FieldSpec{
   676  					Type:   field.TypeInt,
   677  					Column: topic.FieldID,
   678  				},
   679  			},
   680  		}
   681  		for _, k := range nodes {
   682  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   683  		}
   684  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   685  	}
   686  	if nodes := pu.mutation.TopicsIDs(); len(nodes) > 0 {
   687  		edge := &sqlgraph.EdgeSpec{
   688  			Rel:     sqlgraph.M2M,
   689  			Inverse: true,
   690  			Table:   post.TopicsTable,
   691  			Columns: post.TopicsPrimaryKey,
   692  			Bidi:    false,
   693  			Target: &sqlgraph.EdgeTarget{
   694  				IDSpec: &sqlgraph.FieldSpec{
   695  					Type:   field.TypeInt,
   696  					Column: topic.FieldID,
   697  				},
   698  			},
   699  		}
   700  		for _, k := range nodes {
   701  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   702  		}
   703  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
   704  	}
   705  	if pu.mutation.FeaturedImageCleared() {
   706  		edge := &sqlgraph.EdgeSpec{
   707  			Rel:     sqlgraph.M2O,
   708  			Inverse: true,
   709  			Table:   post.FeaturedImageTable,
   710  			Columns: []string{post.FeaturedImageColumn},
   711  			Bidi:    false,
   712  			Target: &sqlgraph.EdgeTarget{
   713  				IDSpec: &sqlgraph.FieldSpec{
   714  					Type:   field.TypeInt,
   715  					Column: file.FieldID,
   716  				},
   717  			},
   718  		}
   719  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   720  	}
   721  	if nodes := pu.mutation.FeaturedImageIDs(); len(nodes) > 0 {
   722  		edge := &sqlgraph.EdgeSpec{
   723  			Rel:     sqlgraph.M2O,
   724  			Inverse: true,
   725  			Table:   post.FeaturedImageTable,
   726  			Columns: []string{post.FeaturedImageColumn},
   727  			Bidi:    false,
   728  			Target: &sqlgraph.EdgeTarget{
   729  				IDSpec: &sqlgraph.FieldSpec{
   730  					Type:   field.TypeInt,
   731  					Column: file.FieldID,
   732  				},
   733  			},
   734  		}
   735  		for _, k := range nodes {
   736  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   737  		}
   738  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
   739  	}
   740  	if pu.mutation.CommentsCleared() {
   741  		edge := &sqlgraph.EdgeSpec{
   742  			Rel:     sqlgraph.O2M,
   743  			Inverse: false,
   744  			Table:   post.CommentsTable,
   745  			Columns: []string{post.CommentsColumn},
   746  			Bidi:    false,
   747  			Target: &sqlgraph.EdgeTarget{
   748  				IDSpec: &sqlgraph.FieldSpec{
   749  					Type:   field.TypeInt,
   750  					Column: comment.FieldID,
   751  				},
   752  			},
   753  		}
   754  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   755  	}
   756  	if nodes := pu.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !pu.mutation.CommentsCleared() {
   757  		edge := &sqlgraph.EdgeSpec{
   758  			Rel:     sqlgraph.O2M,
   759  			Inverse: false,
   760  			Table:   post.CommentsTable,
   761  			Columns: []string{post.CommentsColumn},
   762  			Bidi:    false,
   763  			Target: &sqlgraph.EdgeTarget{
   764  				IDSpec: &sqlgraph.FieldSpec{
   765  					Type:   field.TypeInt,
   766  					Column: comment.FieldID,
   767  				},
   768  			},
   769  		}
   770  		for _, k := range nodes {
   771  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   772  		}
   773  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   774  	}
   775  	if nodes := pu.mutation.CommentsIDs(); len(nodes) > 0 {
   776  		edge := &sqlgraph.EdgeSpec{
   777  			Rel:     sqlgraph.O2M,
   778  			Inverse: false,
   779  			Table:   post.CommentsTable,
   780  			Columns: []string{post.CommentsColumn},
   781  			Bidi:    false,
   782  			Target: &sqlgraph.EdgeTarget{
   783  				IDSpec: &sqlgraph.FieldSpec{
   784  					Type:   field.TypeInt,
   785  					Column: comment.FieldID,
   786  				},
   787  			},
   788  		}
   789  		for _, k := range nodes {
   790  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   791  		}
   792  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
   793  	}
   794  	if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
   795  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   796  			err = &NotFoundError{post.Label}
   797  		} else if sqlgraph.IsConstraintError(err) {
   798  			err = &ConstraintError{err.Error(), err}
   799  		}
   800  		return 0, err
   801  	}
   802  	return n, nil
   803  }
   804  
   805  // PostUpdateOne is the builder for updating a single Post entity.
   806  type PostUpdateOne struct {
   807  	config
   808  	fields   []string
   809  	hooks    []Hook
   810  	mutation *PostMutation
   811  }
   812  
   813  // SetUpdatedAt sets the "updated_at" field.
   814  func (puo *PostUpdateOne) SetUpdatedAt(t time.Time) *PostUpdateOne {
   815  	puo.mutation.SetUpdatedAt(t)
   816  	return puo
   817  }
   818  
   819  // SetDeletedAt sets the "deleted_at" field.
   820  func (puo *PostUpdateOne) SetDeletedAt(t time.Time) *PostUpdateOne {
   821  	puo.mutation.SetDeletedAt(t)
   822  	return puo
   823  }
   824  
   825  // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
   826  func (puo *PostUpdateOne) SetNillableDeletedAt(t *time.Time) *PostUpdateOne {
   827  	if t != nil {
   828  		puo.SetDeletedAt(*t)
   829  	}
   830  	return puo
   831  }
   832  
   833  // ClearDeletedAt clears the value of the "deleted_at" field.
   834  func (puo *PostUpdateOne) ClearDeletedAt() *PostUpdateOne {
   835  	puo.mutation.ClearDeletedAt()
   836  	return puo
   837  }
   838  
   839  // SetName sets the "name" field.
   840  func (puo *PostUpdateOne) SetName(s string) *PostUpdateOne {
   841  	puo.mutation.SetName(s)
   842  	return puo
   843  }
   844  
   845  // SetSlug sets the "slug" field.
   846  func (puo *PostUpdateOne) SetSlug(s string) *PostUpdateOne {
   847  	puo.mutation.SetSlug(s)
   848  	return puo
   849  }
   850  
   851  // SetDescription sets the "description" field.
   852  func (puo *PostUpdateOne) SetDescription(s string) *PostUpdateOne {
   853  	puo.mutation.SetDescription(s)
   854  	return puo
   855  }
   856  
   857  // SetNillableDescription sets the "description" field if the given value is not nil.
   858  func (puo *PostUpdateOne) SetNillableDescription(s *string) *PostUpdateOne {
   859  	if s != nil {
   860  		puo.SetDescription(*s)
   861  	}
   862  	return puo
   863  }
   864  
   865  // ClearDescription clears the value of the "description" field.
   866  func (puo *PostUpdateOne) ClearDescription() *PostUpdateOne {
   867  	puo.mutation.ClearDescription()
   868  	return puo
   869  }
   870  
   871  // SetContent sets the "content" field.
   872  func (puo *PostUpdateOne) SetContent(s string) *PostUpdateOne {
   873  	puo.mutation.SetContent(s)
   874  	return puo
   875  }
   876  
   877  // SetContentHTML sets the "content_html" field.
   878  func (puo *PostUpdateOne) SetContentHTML(s string) *PostUpdateOne {
   879  	puo.mutation.SetContentHTML(s)
   880  	return puo
   881  }
   882  
   883  // SetViewCount sets the "view_count" field.
   884  func (puo *PostUpdateOne) SetViewCount(i int64) *PostUpdateOne {
   885  	puo.mutation.ResetViewCount()
   886  	puo.mutation.SetViewCount(i)
   887  	return puo
   888  }
   889  
   890  // SetNillableViewCount sets the "view_count" field if the given value is not nil.
   891  func (puo *PostUpdateOne) SetNillableViewCount(i *int64) *PostUpdateOne {
   892  	if i != nil {
   893  		puo.SetViewCount(*i)
   894  	}
   895  	return puo
   896  }
   897  
   898  // AddViewCount adds i to the "view_count" field.
   899  func (puo *PostUpdateOne) AddViewCount(i int64) *PostUpdateOne {
   900  	puo.mutation.AddViewCount(i)
   901  	return puo
   902  }
   903  
   904  // SetCommentCount sets the "comment_count" field.
   905  func (puo *PostUpdateOne) SetCommentCount(i int64) *PostUpdateOne {
   906  	puo.mutation.ResetCommentCount()
   907  	puo.mutation.SetCommentCount(i)
   908  	return puo
   909  }
   910  
   911  // SetNillableCommentCount sets the "comment_count" field if the given value is not nil.
   912  func (puo *PostUpdateOne) SetNillableCommentCount(i *int64) *PostUpdateOne {
   913  	if i != nil {
   914  		puo.SetCommentCount(*i)
   915  	}
   916  	return puo
   917  }
   918  
   919  // AddCommentCount adds i to the "comment_count" field.
   920  func (puo *PostUpdateOne) AddCommentCount(i int64) *PostUpdateOne {
   921  	puo.mutation.AddCommentCount(i)
   922  	return puo
   923  }
   924  
   925  // SetRatingCount sets the "rating_count" field.
   926  func (puo *PostUpdateOne) SetRatingCount(i int64) *PostUpdateOne {
   927  	puo.mutation.ResetRatingCount()
   928  	puo.mutation.SetRatingCount(i)
   929  	return puo
   930  }
   931  
   932  // SetNillableRatingCount sets the "rating_count" field if the given value is not nil.
   933  func (puo *PostUpdateOne) SetNillableRatingCount(i *int64) *PostUpdateOne {
   934  	if i != nil {
   935  		puo.SetRatingCount(*i)
   936  	}
   937  	return puo
   938  }
   939  
   940  // AddRatingCount adds i to the "rating_count" field.
   941  func (puo *PostUpdateOne) AddRatingCount(i int64) *PostUpdateOne {
   942  	puo.mutation.AddRatingCount(i)
   943  	return puo
   944  }
   945  
   946  // ClearRatingCount clears the value of the "rating_count" field.
   947  func (puo *PostUpdateOne) ClearRatingCount() *PostUpdateOne {
   948  	puo.mutation.ClearRatingCount()
   949  	return puo
   950  }
   951  
   952  // SetRatingTotal sets the "rating_total" field.
   953  func (puo *PostUpdateOne) SetRatingTotal(i int64) *PostUpdateOne {
   954  	puo.mutation.ResetRatingTotal()
   955  	puo.mutation.SetRatingTotal(i)
   956  	return puo
   957  }
   958  
   959  // SetNillableRatingTotal sets the "rating_total" field if the given value is not nil.
   960  func (puo *PostUpdateOne) SetNillableRatingTotal(i *int64) *PostUpdateOne {
   961  	if i != nil {
   962  		puo.SetRatingTotal(*i)
   963  	}
   964  	return puo
   965  }
   966  
   967  // AddRatingTotal adds i to the "rating_total" field.
   968  func (puo *PostUpdateOne) AddRatingTotal(i int64) *PostUpdateOne {
   969  	puo.mutation.AddRatingTotal(i)
   970  	return puo
   971  }
   972  
   973  // ClearRatingTotal clears the value of the "rating_total" field.
   974  func (puo *PostUpdateOne) ClearRatingTotal() *PostUpdateOne {
   975  	puo.mutation.ClearRatingTotal()
   976  	return puo
   977  }
   978  
   979  // SetDraft sets the "draft" field.
   980  func (puo *PostUpdateOne) SetDraft(b bool) *PostUpdateOne {
   981  	puo.mutation.SetDraft(b)
   982  	return puo
   983  }
   984  
   985  // SetNillableDraft sets the "draft" field if the given value is not nil.
   986  func (puo *PostUpdateOne) SetNillableDraft(b *bool) *PostUpdateOne {
   987  	if b != nil {
   988  		puo.SetDraft(*b)
   989  	}
   990  	return puo
   991  }
   992  
   993  // ClearDraft clears the value of the "draft" field.
   994  func (puo *PostUpdateOne) ClearDraft() *PostUpdateOne {
   995  	puo.mutation.ClearDraft()
   996  	return puo
   997  }
   998  
   999  // SetApproved sets the "approved" field.
  1000  func (puo *PostUpdateOne) SetApproved(b bool) *PostUpdateOne {
  1001  	puo.mutation.SetApproved(b)
  1002  	return puo
  1003  }
  1004  
  1005  // SetNillableApproved sets the "approved" field if the given value is not nil.
  1006  func (puo *PostUpdateOne) SetNillableApproved(b *bool) *PostUpdateOne {
  1007  	if b != nil {
  1008  		puo.SetApproved(*b)
  1009  	}
  1010  	return puo
  1011  }
  1012  
  1013  // ClearApproved clears the value of the "approved" field.
  1014  func (puo *PostUpdateOne) ClearApproved() *PostUpdateOne {
  1015  	puo.mutation.ClearApproved()
  1016  	return puo
  1017  }
  1018  
  1019  // SetFeaturedImageID sets the "featured_image_id" field.
  1020  func (puo *PostUpdateOne) SetFeaturedImageID(i int) *PostUpdateOne {
  1021  	puo.mutation.SetFeaturedImageID(i)
  1022  	return puo
  1023  }
  1024  
  1025  // SetNillableFeaturedImageID sets the "featured_image_id" field if the given value is not nil.
  1026  func (puo *PostUpdateOne) SetNillableFeaturedImageID(i *int) *PostUpdateOne {
  1027  	if i != nil {
  1028  		puo.SetFeaturedImageID(*i)
  1029  	}
  1030  	return puo
  1031  }
  1032  
  1033  // ClearFeaturedImageID clears the value of the "featured_image_id" field.
  1034  func (puo *PostUpdateOne) ClearFeaturedImageID() *PostUpdateOne {
  1035  	puo.mutation.ClearFeaturedImageID()
  1036  	return puo
  1037  }
  1038  
  1039  // SetUserID sets the "user_id" field.
  1040  func (puo *PostUpdateOne) SetUserID(i int) *PostUpdateOne {
  1041  	puo.mutation.SetUserID(i)
  1042  	return puo
  1043  }
  1044  
  1045  // SetNillableUserID sets the "user_id" field if the given value is not nil.
  1046  func (puo *PostUpdateOne) SetNillableUserID(i *int) *PostUpdateOne {
  1047  	if i != nil {
  1048  		puo.SetUserID(*i)
  1049  	}
  1050  	return puo
  1051  }
  1052  
  1053  // ClearUserID clears the value of the "user_id" field.
  1054  func (puo *PostUpdateOne) ClearUserID() *PostUpdateOne {
  1055  	puo.mutation.ClearUserID()
  1056  	return puo
  1057  }
  1058  
  1059  // SetUser sets the "user" edge to the User entity.
  1060  func (puo *PostUpdateOne) SetUser(u *User) *PostUpdateOne {
  1061  	return puo.SetUserID(u.ID)
  1062  }
  1063  
  1064  // AddTopicIDs adds the "topics" edge to the Topic entity by IDs.
  1065  func (puo *PostUpdateOne) AddTopicIDs(ids ...int) *PostUpdateOne {
  1066  	puo.mutation.AddTopicIDs(ids...)
  1067  	return puo
  1068  }
  1069  
  1070  // AddTopics adds the "topics" edges to the Topic entity.
  1071  func (puo *PostUpdateOne) AddTopics(t ...*Topic) *PostUpdateOne {
  1072  	ids := make([]int, len(t))
  1073  	for i := range t {
  1074  		ids[i] = t[i].ID
  1075  	}
  1076  	return puo.AddTopicIDs(ids...)
  1077  }
  1078  
  1079  // SetFeaturedImage sets the "featured_image" edge to the File entity.
  1080  func (puo *PostUpdateOne) SetFeaturedImage(f *File) *PostUpdateOne {
  1081  	return puo.SetFeaturedImageID(f.ID)
  1082  }
  1083  
  1084  // AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
  1085  func (puo *PostUpdateOne) AddCommentIDs(ids ...int) *PostUpdateOne {
  1086  	puo.mutation.AddCommentIDs(ids...)
  1087  	return puo
  1088  }
  1089  
  1090  // AddComments adds the "comments" edges to the Comment entity.
  1091  func (puo *PostUpdateOne) AddComments(c ...*Comment) *PostUpdateOne {
  1092  	ids := make([]int, len(c))
  1093  	for i := range c {
  1094  		ids[i] = c[i].ID
  1095  	}
  1096  	return puo.AddCommentIDs(ids...)
  1097  }
  1098  
  1099  // Mutation returns the PostMutation object of the builder.
  1100  func (puo *PostUpdateOne) Mutation() *PostMutation {
  1101  	return puo.mutation
  1102  }
  1103  
  1104  // ClearUser clears the "user" edge to the User entity.
  1105  func (puo *PostUpdateOne) ClearUser() *PostUpdateOne {
  1106  	puo.mutation.ClearUser()
  1107  	return puo
  1108  }
  1109  
  1110  // ClearTopics clears all "topics" edges to the Topic entity.
  1111  func (puo *PostUpdateOne) ClearTopics() *PostUpdateOne {
  1112  	puo.mutation.ClearTopics()
  1113  	return puo
  1114  }
  1115  
  1116  // RemoveTopicIDs removes the "topics" edge to Topic entities by IDs.
  1117  func (puo *PostUpdateOne) RemoveTopicIDs(ids ...int) *PostUpdateOne {
  1118  	puo.mutation.RemoveTopicIDs(ids...)
  1119  	return puo
  1120  }
  1121  
  1122  // RemoveTopics removes "topics" edges to Topic entities.
  1123  func (puo *PostUpdateOne) RemoveTopics(t ...*Topic) *PostUpdateOne {
  1124  	ids := make([]int, len(t))
  1125  	for i := range t {
  1126  		ids[i] = t[i].ID
  1127  	}
  1128  	return puo.RemoveTopicIDs(ids...)
  1129  }
  1130  
  1131  // ClearFeaturedImage clears the "featured_image" edge to the File entity.
  1132  func (puo *PostUpdateOne) ClearFeaturedImage() *PostUpdateOne {
  1133  	puo.mutation.ClearFeaturedImage()
  1134  	return puo
  1135  }
  1136  
  1137  // ClearComments clears all "comments" edges to the Comment entity.
  1138  func (puo *PostUpdateOne) ClearComments() *PostUpdateOne {
  1139  	puo.mutation.ClearComments()
  1140  	return puo
  1141  }
  1142  
  1143  // RemoveCommentIDs removes the "comments" edge to Comment entities by IDs.
  1144  func (puo *PostUpdateOne) RemoveCommentIDs(ids ...int) *PostUpdateOne {
  1145  	puo.mutation.RemoveCommentIDs(ids...)
  1146  	return puo
  1147  }
  1148  
  1149  // RemoveComments removes "comments" edges to Comment entities.
  1150  func (puo *PostUpdateOne) RemoveComments(c ...*Comment) *PostUpdateOne {
  1151  	ids := make([]int, len(c))
  1152  	for i := range c {
  1153  		ids[i] = c[i].ID
  1154  	}
  1155  	return puo.RemoveCommentIDs(ids...)
  1156  }
  1157  
  1158  // Select allows selecting one or more fields (columns) of the returned entity.
  1159  // The default is selecting all fields defined in the entity schema.
  1160  func (puo *PostUpdateOne) Select(field string, fields ...string) *PostUpdateOne {
  1161  	puo.fields = append([]string{field}, fields...)
  1162  	return puo
  1163  }
  1164  
  1165  // Save executes the query and returns the updated Post entity.
  1166  func (puo *PostUpdateOne) Save(ctx context.Context) (*Post, error) {
  1167  	var (
  1168  		err  error
  1169  		node *Post
  1170  	)
  1171  	puo.defaults()
  1172  	if len(puo.hooks) == 0 {
  1173  		node, err = puo.sqlSave(ctx)
  1174  	} else {
  1175  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  1176  			mutation, ok := m.(*PostMutation)
  1177  			if !ok {
  1178  				return nil, fmt.Errorf("unexpected mutation type %T", m)
  1179  			}
  1180  			puo.mutation = mutation
  1181  			node, err = puo.sqlSave(ctx)
  1182  			mutation.done = true
  1183  			return node, err
  1184  		})
  1185  		for i := len(puo.hooks) - 1; i >= 0; i-- {
  1186  			if puo.hooks[i] == nil {
  1187  				return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  1188  			}
  1189  			mut = puo.hooks[i](mut)
  1190  		}
  1191  		if _, err := mut.Mutate(ctx, puo.mutation); err != nil {
  1192  			return nil, err
  1193  		}
  1194  	}
  1195  	return node, err
  1196  }
  1197  
  1198  // SaveX is like Save, but panics if an error occurs.
  1199  func (puo *PostUpdateOne) SaveX(ctx context.Context) *Post {
  1200  	node, err := puo.Save(ctx)
  1201  	if err != nil {
  1202  		panic(err)
  1203  	}
  1204  	return node
  1205  }
  1206  
  1207  // Exec executes the query on the entity.
  1208  func (puo *PostUpdateOne) Exec(ctx context.Context) error {
  1209  	_, err := puo.Save(ctx)
  1210  	return err
  1211  }
  1212  
  1213  // ExecX is like Exec, but panics if an error occurs.
  1214  func (puo *PostUpdateOne) ExecX(ctx context.Context) {
  1215  	if err := puo.Exec(ctx); err != nil {
  1216  		panic(err)
  1217  	}
  1218  }
  1219  
  1220  // defaults sets the default values of the builder before save.
  1221  func (puo *PostUpdateOne) defaults() {
  1222  	if _, ok := puo.mutation.UpdatedAt(); !ok {
  1223  		v := post.UpdateDefaultUpdatedAt()
  1224  		puo.mutation.SetUpdatedAt(v)
  1225  	}
  1226  }
  1227  
  1228  func (puo *PostUpdateOne) sqlSave(ctx context.Context) (_node *Post, err error) {
  1229  	_spec := &sqlgraph.UpdateSpec{
  1230  		Node: &sqlgraph.NodeSpec{
  1231  			Table:   post.Table,
  1232  			Columns: post.Columns,
  1233  			ID: &sqlgraph.FieldSpec{
  1234  				Type:   field.TypeInt,
  1235  				Column: post.FieldID,
  1236  			},
  1237  		},
  1238  	}
  1239  	id, ok := puo.mutation.ID()
  1240  	if !ok {
  1241  		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Post.id" for update`)}
  1242  	}
  1243  	_spec.Node.ID.Value = id
  1244  	if fields := puo.fields; len(fields) > 0 {
  1245  		_spec.Node.Columns = make([]string, 0, len(fields))
  1246  		_spec.Node.Columns = append(_spec.Node.Columns, post.FieldID)
  1247  		for _, f := range fields {
  1248  			if !post.ValidColumn(f) {
  1249  				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1250  			}
  1251  			if f != post.FieldID {
  1252  				_spec.Node.Columns = append(_spec.Node.Columns, f)
  1253  			}
  1254  		}
  1255  	}
  1256  	if ps := puo.mutation.predicates; len(ps) > 0 {
  1257  		_spec.Predicate = func(selector *sql.Selector) {
  1258  			for i := range ps {
  1259  				ps[i](selector)
  1260  			}
  1261  		}
  1262  	}
  1263  	if value, ok := puo.mutation.UpdatedAt(); ok {
  1264  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1265  			Type:   field.TypeTime,
  1266  			Value:  value,
  1267  			Column: post.FieldUpdatedAt,
  1268  		})
  1269  	}
  1270  	if value, ok := puo.mutation.DeletedAt(); ok {
  1271  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1272  			Type:   field.TypeTime,
  1273  			Value:  value,
  1274  			Column: post.FieldDeletedAt,
  1275  		})
  1276  	}
  1277  	if puo.mutation.DeletedAtCleared() {
  1278  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  1279  			Type:   field.TypeTime,
  1280  			Column: post.FieldDeletedAt,
  1281  		})
  1282  	}
  1283  	if value, ok := puo.mutation.Name(); ok {
  1284  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1285  			Type:   field.TypeString,
  1286  			Value:  value,
  1287  			Column: post.FieldName,
  1288  		})
  1289  	}
  1290  	if value, ok := puo.mutation.Slug(); ok {
  1291  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1292  			Type:   field.TypeString,
  1293  			Value:  value,
  1294  			Column: post.FieldSlug,
  1295  		})
  1296  	}
  1297  	if value, ok := puo.mutation.Description(); ok {
  1298  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1299  			Type:   field.TypeString,
  1300  			Value:  value,
  1301  			Column: post.FieldDescription,
  1302  		})
  1303  	}
  1304  	if puo.mutation.DescriptionCleared() {
  1305  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  1306  			Type:   field.TypeString,
  1307  			Column: post.FieldDescription,
  1308  		})
  1309  	}
  1310  	if value, ok := puo.mutation.Content(); ok {
  1311  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1312  			Type:   field.TypeString,
  1313  			Value:  value,
  1314  			Column: post.FieldContent,
  1315  		})
  1316  	}
  1317  	if value, ok := puo.mutation.ContentHTML(); ok {
  1318  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1319  			Type:   field.TypeString,
  1320  			Value:  value,
  1321  			Column: post.FieldContentHTML,
  1322  		})
  1323  	}
  1324  	if value, ok := puo.mutation.ViewCount(); ok {
  1325  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1326  			Type:   field.TypeInt64,
  1327  			Value:  value,
  1328  			Column: post.FieldViewCount,
  1329  		})
  1330  	}
  1331  	if value, ok := puo.mutation.AddedViewCount(); ok {
  1332  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  1333  			Type:   field.TypeInt64,
  1334  			Value:  value,
  1335  			Column: post.FieldViewCount,
  1336  		})
  1337  	}
  1338  	if value, ok := puo.mutation.CommentCount(); ok {
  1339  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1340  			Type:   field.TypeInt64,
  1341  			Value:  value,
  1342  			Column: post.FieldCommentCount,
  1343  		})
  1344  	}
  1345  	if value, ok := puo.mutation.AddedCommentCount(); ok {
  1346  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  1347  			Type:   field.TypeInt64,
  1348  			Value:  value,
  1349  			Column: post.FieldCommentCount,
  1350  		})
  1351  	}
  1352  	if value, ok := puo.mutation.RatingCount(); ok {
  1353  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1354  			Type:   field.TypeInt64,
  1355  			Value:  value,
  1356  			Column: post.FieldRatingCount,
  1357  		})
  1358  	}
  1359  	if value, ok := puo.mutation.AddedRatingCount(); ok {
  1360  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  1361  			Type:   field.TypeInt64,
  1362  			Value:  value,
  1363  			Column: post.FieldRatingCount,
  1364  		})
  1365  	}
  1366  	if puo.mutation.RatingCountCleared() {
  1367  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  1368  			Type:   field.TypeInt64,
  1369  			Column: post.FieldRatingCount,
  1370  		})
  1371  	}
  1372  	if value, ok := puo.mutation.RatingTotal(); ok {
  1373  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1374  			Type:   field.TypeInt64,
  1375  			Value:  value,
  1376  			Column: post.FieldRatingTotal,
  1377  		})
  1378  	}
  1379  	if value, ok := puo.mutation.AddedRatingTotal(); ok {
  1380  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  1381  			Type:   field.TypeInt64,
  1382  			Value:  value,
  1383  			Column: post.FieldRatingTotal,
  1384  		})
  1385  	}
  1386  	if puo.mutation.RatingTotalCleared() {
  1387  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  1388  			Type:   field.TypeInt64,
  1389  			Column: post.FieldRatingTotal,
  1390  		})
  1391  	}
  1392  	if value, ok := puo.mutation.Draft(); ok {
  1393  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1394  			Type:   field.TypeBool,
  1395  			Value:  value,
  1396  			Column: post.FieldDraft,
  1397  		})
  1398  	}
  1399  	if puo.mutation.DraftCleared() {
  1400  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  1401  			Type:   field.TypeBool,
  1402  			Column: post.FieldDraft,
  1403  		})
  1404  	}
  1405  	if value, ok := puo.mutation.Approved(); ok {
  1406  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1407  			Type:   field.TypeBool,
  1408  			Value:  value,
  1409  			Column: post.FieldApproved,
  1410  		})
  1411  	}
  1412  	if puo.mutation.ApprovedCleared() {
  1413  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  1414  			Type:   field.TypeBool,
  1415  			Column: post.FieldApproved,
  1416  		})
  1417  	}
  1418  	if puo.mutation.UserCleared() {
  1419  		edge := &sqlgraph.EdgeSpec{
  1420  			Rel:     sqlgraph.M2O,
  1421  			Inverse: true,
  1422  			Table:   post.UserTable,
  1423  			Columns: []string{post.UserColumn},
  1424  			Bidi:    false,
  1425  			Target: &sqlgraph.EdgeTarget{
  1426  				IDSpec: &sqlgraph.FieldSpec{
  1427  					Type:   field.TypeInt,
  1428  					Column: user.FieldID,
  1429  				},
  1430  			},
  1431  		}
  1432  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1433  	}
  1434  	if nodes := puo.mutation.UserIDs(); len(nodes) > 0 {
  1435  		edge := &sqlgraph.EdgeSpec{
  1436  			Rel:     sqlgraph.M2O,
  1437  			Inverse: true,
  1438  			Table:   post.UserTable,
  1439  			Columns: []string{post.UserColumn},
  1440  			Bidi:    false,
  1441  			Target: &sqlgraph.EdgeTarget{
  1442  				IDSpec: &sqlgraph.FieldSpec{
  1443  					Type:   field.TypeInt,
  1444  					Column: user.FieldID,
  1445  				},
  1446  			},
  1447  		}
  1448  		for _, k := range nodes {
  1449  			edge.Target.Nodes = append(edge.Target.Nodes, k)
  1450  		}
  1451  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
  1452  	}
  1453  	if puo.mutation.TopicsCleared() {
  1454  		edge := &sqlgraph.EdgeSpec{
  1455  			Rel:     sqlgraph.M2M,
  1456  			Inverse: true,
  1457  			Table:   post.TopicsTable,
  1458  			Columns: post.TopicsPrimaryKey,
  1459  			Bidi:    false,
  1460  			Target: &sqlgraph.EdgeTarget{
  1461  				IDSpec: &sqlgraph.FieldSpec{
  1462  					Type:   field.TypeInt,
  1463  					Column: topic.FieldID,
  1464  				},
  1465  			},
  1466  		}
  1467  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1468  	}
  1469  	if nodes := puo.mutation.RemovedTopicsIDs(); len(nodes) > 0 && !puo.mutation.TopicsCleared() {
  1470  		edge := &sqlgraph.EdgeSpec{
  1471  			Rel:     sqlgraph.M2M,
  1472  			Inverse: true,
  1473  			Table:   post.TopicsTable,
  1474  			Columns: post.TopicsPrimaryKey,
  1475  			Bidi:    false,
  1476  			Target: &sqlgraph.EdgeTarget{
  1477  				IDSpec: &sqlgraph.FieldSpec{
  1478  					Type:   field.TypeInt,
  1479  					Column: topic.FieldID,
  1480  				},
  1481  			},
  1482  		}
  1483  		for _, k := range nodes {
  1484  			edge.Target.Nodes = append(edge.Target.Nodes, k)
  1485  		}
  1486  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1487  	}
  1488  	if nodes := puo.mutation.TopicsIDs(); len(nodes) > 0 {
  1489  		edge := &sqlgraph.EdgeSpec{
  1490  			Rel:     sqlgraph.M2M,
  1491  			Inverse: true,
  1492  			Table:   post.TopicsTable,
  1493  			Columns: post.TopicsPrimaryKey,
  1494  			Bidi:    false,
  1495  			Target: &sqlgraph.EdgeTarget{
  1496  				IDSpec: &sqlgraph.FieldSpec{
  1497  					Type:   field.TypeInt,
  1498  					Column: topic.FieldID,
  1499  				},
  1500  			},
  1501  		}
  1502  		for _, k := range nodes {
  1503  			edge.Target.Nodes = append(edge.Target.Nodes, k)
  1504  		}
  1505  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
  1506  	}
  1507  	if puo.mutation.FeaturedImageCleared() {
  1508  		edge := &sqlgraph.EdgeSpec{
  1509  			Rel:     sqlgraph.M2O,
  1510  			Inverse: true,
  1511  			Table:   post.FeaturedImageTable,
  1512  			Columns: []string{post.FeaturedImageColumn},
  1513  			Bidi:    false,
  1514  			Target: &sqlgraph.EdgeTarget{
  1515  				IDSpec: &sqlgraph.FieldSpec{
  1516  					Type:   field.TypeInt,
  1517  					Column: file.FieldID,
  1518  				},
  1519  			},
  1520  		}
  1521  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1522  	}
  1523  	if nodes := puo.mutation.FeaturedImageIDs(); len(nodes) > 0 {
  1524  		edge := &sqlgraph.EdgeSpec{
  1525  			Rel:     sqlgraph.M2O,
  1526  			Inverse: true,
  1527  			Table:   post.FeaturedImageTable,
  1528  			Columns: []string{post.FeaturedImageColumn},
  1529  			Bidi:    false,
  1530  			Target: &sqlgraph.EdgeTarget{
  1531  				IDSpec: &sqlgraph.FieldSpec{
  1532  					Type:   field.TypeInt,
  1533  					Column: file.FieldID,
  1534  				},
  1535  			},
  1536  		}
  1537  		for _, k := range nodes {
  1538  			edge.Target.Nodes = append(edge.Target.Nodes, k)
  1539  		}
  1540  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
  1541  	}
  1542  	if puo.mutation.CommentsCleared() {
  1543  		edge := &sqlgraph.EdgeSpec{
  1544  			Rel:     sqlgraph.O2M,
  1545  			Inverse: false,
  1546  			Table:   post.CommentsTable,
  1547  			Columns: []string{post.CommentsColumn},
  1548  			Bidi:    false,
  1549  			Target: &sqlgraph.EdgeTarget{
  1550  				IDSpec: &sqlgraph.FieldSpec{
  1551  					Type:   field.TypeInt,
  1552  					Column: comment.FieldID,
  1553  				},
  1554  			},
  1555  		}
  1556  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1557  	}
  1558  	if nodes := puo.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !puo.mutation.CommentsCleared() {
  1559  		edge := &sqlgraph.EdgeSpec{
  1560  			Rel:     sqlgraph.O2M,
  1561  			Inverse: false,
  1562  			Table:   post.CommentsTable,
  1563  			Columns: []string{post.CommentsColumn},
  1564  			Bidi:    false,
  1565  			Target: &sqlgraph.EdgeTarget{
  1566  				IDSpec: &sqlgraph.FieldSpec{
  1567  					Type:   field.TypeInt,
  1568  					Column: comment.FieldID,
  1569  				},
  1570  			},
  1571  		}
  1572  		for _, k := range nodes {
  1573  			edge.Target.Nodes = append(edge.Target.Nodes, k)
  1574  		}
  1575  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1576  	}
  1577  	if nodes := puo.mutation.CommentsIDs(); len(nodes) > 0 {
  1578  		edge := &sqlgraph.EdgeSpec{
  1579  			Rel:     sqlgraph.O2M,
  1580  			Inverse: false,
  1581  			Table:   post.CommentsTable,
  1582  			Columns: []string{post.CommentsColumn},
  1583  			Bidi:    false,
  1584  			Target: &sqlgraph.EdgeTarget{
  1585  				IDSpec: &sqlgraph.FieldSpec{
  1586  					Type:   field.TypeInt,
  1587  					Column: comment.FieldID,
  1588  				},
  1589  			},
  1590  		}
  1591  		for _, k := range nodes {
  1592  			edge.Target.Nodes = append(edge.Target.Nodes, k)
  1593  		}
  1594  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
  1595  	}
  1596  	_node = &Post{config: puo.config}
  1597  	_spec.Assign = _node.assignValues
  1598  	_spec.ScanValues = _node.scanValues
  1599  	if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
  1600  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1601  			err = &NotFoundError{post.Label}
  1602  		} else if sqlgraph.IsConstraintError(err) {
  1603  			err = &ConstraintError{err.Error(), err}
  1604  		}
  1605  		return nil, err
  1606  	}
  1607  	return _node, nil
  1608  }