// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/attachment" "bj_power_mes/ent/predicate" "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // AttachmentUpdate is the builder for updating Attachment entities. type AttachmentUpdate struct { config hooks []Hook mutation *AttachmentMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the AttachmentUpdate builder. func (_u *AttachmentUpdate) Where(ps ...predicate.Attachment) *AttachmentUpdate { _u.mutation.Where(ps...) return _u } // SetBizType sets the "bizType" field. func (_u *AttachmentUpdate) SetBizType(v string) *AttachmentUpdate { _u.mutation.SetBizType(v) return _u } // SetNillableBizType sets the "bizType" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableBizType(v *string) *AttachmentUpdate { if v != nil { _u.SetBizType(*v) } return _u } // SetBizId sets the "bizId" field. func (_u *AttachmentUpdate) SetBizId(v string) *AttachmentUpdate { _u.mutation.SetBizId(v) return _u } // SetNillableBizId sets the "bizId" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableBizId(v *string) *AttachmentUpdate { if v != nil { _u.SetBizId(*v) } return _u } // SetFileName sets the "fileName" field. func (_u *AttachmentUpdate) SetFileName(v string) *AttachmentUpdate { _u.mutation.SetFileName(v) return _u } // SetNillableFileName sets the "fileName" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableFileName(v *string) *AttachmentUpdate { if v != nil { _u.SetFileName(*v) } return _u } // SetFilePath sets the "filePath" field. func (_u *AttachmentUpdate) SetFilePath(v string) *AttachmentUpdate { _u.mutation.SetFilePath(v) return _u } // SetNillableFilePath sets the "filePath" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableFilePath(v *string) *AttachmentUpdate { if v != nil { _u.SetFilePath(*v) } return _u } // SetFileSize sets the "fileSize" field. func (_u *AttachmentUpdate) SetFileSize(v int) *AttachmentUpdate { _u.mutation.ResetFileSize() _u.mutation.SetFileSize(v) return _u } // SetNillableFileSize sets the "fileSize" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableFileSize(v *int) *AttachmentUpdate { if v != nil { _u.SetFileSize(*v) } return _u } // AddFileSize adds value to the "fileSize" field. func (_u *AttachmentUpdate) AddFileSize(v int) *AttachmentUpdate { _u.mutation.AddFileSize(v) return _u } // SetUploader sets the "uploader" field. func (_u *AttachmentUpdate) SetUploader(v string) *AttachmentUpdate { _u.mutation.SetUploader(v) return _u } // SetNillableUploader sets the "uploader" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableUploader(v *string) *AttachmentUpdate { if v != nil { _u.SetUploader(*v) } return _u } // SetFileType sets the "fileType" field. func (_u *AttachmentUpdate) SetFileType(v string) *AttachmentUpdate { _u.mutation.SetFileType(v) return _u } // SetNillableFileType sets the "fileType" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableFileType(v *string) *AttachmentUpdate { if v != nil { _u.SetFileType(*v) } return _u } // SetFileExt sets the "fileExt" field. func (_u *AttachmentUpdate) SetFileExt(v string) *AttachmentUpdate { _u.mutation.SetFileExt(v) return _u } // SetNillableFileExt sets the "fileExt" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableFileExt(v *string) *AttachmentUpdate { if v != nil { _u.SetFileExt(*v) } return _u } // SetFileMd5 sets the "fileMd5" field. func (_u *AttachmentUpdate) SetFileMd5(v string) *AttachmentUpdate { _u.mutation.SetFileMd5(v) return _u } // SetNillableFileMd5 sets the "fileMd5" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableFileMd5(v *string) *AttachmentUpdate { if v != nil { _u.SetFileMd5(*v) } return _u } // SetMimeType sets the "mimeType" field. func (_u *AttachmentUpdate) SetMimeType(v string) *AttachmentUpdate { _u.mutation.SetMimeType(v) return _u } // SetNillableMimeType sets the "mimeType" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableMimeType(v *string) *AttachmentUpdate { if v != nil { _u.SetMimeType(*v) } return _u } // SetArchived sets the "archived" field. func (_u *AttachmentUpdate) SetArchived(v bool) *AttachmentUpdate { _u.mutation.SetArchived(v) return _u } // SetNillableArchived sets the "archived" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableArchived(v *bool) *AttachmentUpdate { if v != nil { _u.SetArchived(*v) } return _u } // SetArchivedAt sets the "archivedAt" field. func (_u *AttachmentUpdate) SetArchivedAt(v int64) *AttachmentUpdate { _u.mutation.ResetArchivedAt() _u.mutation.SetArchivedAt(v) return _u } // SetNillableArchivedAt sets the "archivedAt" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableArchivedAt(v *int64) *AttachmentUpdate { if v != nil { _u.SetArchivedAt(*v) } return _u } // AddArchivedAt adds value to the "archivedAt" field. func (_u *AttachmentUpdate) AddArchivedAt(v int64) *AttachmentUpdate { _u.mutation.AddArchivedAt(v) return _u } // SetDeleted sets the "deleted" field. func (_u *AttachmentUpdate) SetDeleted(v bool) *AttachmentUpdate { _u.mutation.SetDeleted(v) return _u } // SetNillableDeleted sets the "deleted" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableDeleted(v *bool) *AttachmentUpdate { if v != nil { _u.SetDeleted(*v) } return _u } // SetDeletedAt sets the "deletedAt" field. func (_u *AttachmentUpdate) SetDeletedAt(v int64) *AttachmentUpdate { _u.mutation.ResetDeletedAt() _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deletedAt" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableDeletedAt(v *int64) *AttachmentUpdate { if v != nil { _u.SetDeletedAt(*v) } return _u } // AddDeletedAt adds value to the "deletedAt" field. func (_u *AttachmentUpdate) AddDeletedAt(v int64) *AttachmentUpdate { _u.mutation.AddDeletedAt(v) return _u } // SetDeletedBy sets the "deletedBy" field. func (_u *AttachmentUpdate) SetDeletedBy(v string) *AttachmentUpdate { _u.mutation.SetDeletedBy(v) return _u } // SetNillableDeletedBy sets the "deletedBy" field if the given value is not nil. func (_u *AttachmentUpdate) SetNillableDeletedBy(v *string) *AttachmentUpdate { if v != nil { _u.SetDeletedBy(*v) } return _u } // Mutation returns the AttachmentMutation object of the builder. func (_u *AttachmentUpdate) Mutation() *AttachmentMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *AttachmentUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *AttachmentUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *AttachmentUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *AttachmentUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_u *AttachmentUpdate) check() error { if v, ok := _u.mutation.BizType(); ok { if err := attachment.BizTypeValidator(v); err != nil { return &ValidationError{Name: "bizType", err: fmt.Errorf(`ent: validator failed for field "Attachment.bizType": %w`, err)} } } if v, ok := _u.mutation.BizId(); ok { if err := attachment.BizIdValidator(v); err != nil { return &ValidationError{Name: "bizId", err: fmt.Errorf(`ent: validator failed for field "Attachment.bizId": %w`, err)} } } if v, ok := _u.mutation.FileName(); ok { if err := attachment.FileNameValidator(v); err != nil { return &ValidationError{Name: "fileName", err: fmt.Errorf(`ent: validator failed for field "Attachment.fileName": %w`, err)} } } if v, ok := _u.mutation.FilePath(); ok { if err := attachment.FilePathValidator(v); err != nil { return &ValidationError{Name: "filePath", err: fmt.Errorf(`ent: validator failed for field "Attachment.filePath": %w`, err)} } } if v, ok := _u.mutation.Uploader(); ok { if err := attachment.UploaderValidator(v); err != nil { return &ValidationError{Name: "uploader", err: fmt.Errorf(`ent: validator failed for field "Attachment.uploader": %w`, err)} } } if v, ok := _u.mutation.FileType(); ok { if err := attachment.FileTypeValidator(v); err != nil { return &ValidationError{Name: "fileType", err: fmt.Errorf(`ent: validator failed for field "Attachment.fileType": %w`, err)} } } if v, ok := _u.mutation.FileExt(); ok { if err := attachment.FileExtValidator(v); err != nil { return &ValidationError{Name: "fileExt", err: fmt.Errorf(`ent: validator failed for field "Attachment.fileExt": %w`, err)} } } if v, ok := _u.mutation.FileMd5(); ok { if err := attachment.FileMd5Validator(v); err != nil { return &ValidationError{Name: "fileMd5", err: fmt.Errorf(`ent: validator failed for field "Attachment.fileMd5": %w`, err)} } } if v, ok := _u.mutation.MimeType(); ok { if err := attachment.MimeTypeValidator(v); err != nil { return &ValidationError{Name: "mimeType", err: fmt.Errorf(`ent: validator failed for field "Attachment.mimeType": %w`, err)} } } if v, ok := _u.mutation.DeletedBy(); ok { if err := attachment.DeletedByValidator(v); err != nil { return &ValidationError{Name: "deletedBy", err: fmt.Errorf(`ent: validator failed for field "Attachment.deletedBy": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *AttachmentUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AttachmentUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *AttachmentUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeInt)) if ps := _u.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := _u.mutation.BizType(); ok { _spec.SetField(attachment.FieldBizType, field.TypeString, value) } if value, ok := _u.mutation.BizId(); ok { _spec.SetField(attachment.FieldBizId, field.TypeString, value) } if value, ok := _u.mutation.FileName(); ok { _spec.SetField(attachment.FieldFileName, field.TypeString, value) } if value, ok := _u.mutation.FilePath(); ok { _spec.SetField(attachment.FieldFilePath, field.TypeString, value) } if value, ok := _u.mutation.FileSize(); ok { _spec.SetField(attachment.FieldFileSize, field.TypeInt, value) } if value, ok := _u.mutation.AddedFileSize(); ok { _spec.AddField(attachment.FieldFileSize, field.TypeInt, value) } if value, ok := _u.mutation.Uploader(); ok { _spec.SetField(attachment.FieldUploader, field.TypeString, value) } if value, ok := _u.mutation.FileType(); ok { _spec.SetField(attachment.FieldFileType, field.TypeString, value) } if value, ok := _u.mutation.FileExt(); ok { _spec.SetField(attachment.FieldFileExt, field.TypeString, value) } if value, ok := _u.mutation.FileMd5(); ok { _spec.SetField(attachment.FieldFileMd5, field.TypeString, value) } if value, ok := _u.mutation.MimeType(); ok { _spec.SetField(attachment.FieldMimeType, field.TypeString, value) } if value, ok := _u.mutation.Archived(); ok { _spec.SetField(attachment.FieldArchived, field.TypeBool, value) } if value, ok := _u.mutation.ArchivedAt(); ok { _spec.SetField(attachment.FieldArchivedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedArchivedAt(); ok { _spec.AddField(attachment.FieldArchivedAt, field.TypeInt64, value) } if value, ok := _u.mutation.Deleted(); ok { _spec.SetField(attachment.FieldDeleted, field.TypeBool, value) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(attachment.FieldDeletedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedDeletedAt(); ok { _spec.AddField(attachment.FieldDeletedAt, field.TypeInt64, value) } if value, ok := _u.mutation.DeletedBy(); ok { _spec.SetField(attachment.FieldDeletedBy, field.TypeString, value) } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{attachment.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // AttachmentUpdateOne is the builder for updating a single Attachment entity. type AttachmentUpdateOne struct { config fields []string hooks []Hook mutation *AttachmentMutation modifiers []func(*sql.UpdateBuilder) } // SetBizType sets the "bizType" field. func (_u *AttachmentUpdateOne) SetBizType(v string) *AttachmentUpdateOne { _u.mutation.SetBizType(v) return _u } // SetNillableBizType sets the "bizType" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableBizType(v *string) *AttachmentUpdateOne { if v != nil { _u.SetBizType(*v) } return _u } // SetBizId sets the "bizId" field. func (_u *AttachmentUpdateOne) SetBizId(v string) *AttachmentUpdateOne { _u.mutation.SetBizId(v) return _u } // SetNillableBizId sets the "bizId" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableBizId(v *string) *AttachmentUpdateOne { if v != nil { _u.SetBizId(*v) } return _u } // SetFileName sets the "fileName" field. func (_u *AttachmentUpdateOne) SetFileName(v string) *AttachmentUpdateOne { _u.mutation.SetFileName(v) return _u } // SetNillableFileName sets the "fileName" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableFileName(v *string) *AttachmentUpdateOne { if v != nil { _u.SetFileName(*v) } return _u } // SetFilePath sets the "filePath" field. func (_u *AttachmentUpdateOne) SetFilePath(v string) *AttachmentUpdateOne { _u.mutation.SetFilePath(v) return _u } // SetNillableFilePath sets the "filePath" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableFilePath(v *string) *AttachmentUpdateOne { if v != nil { _u.SetFilePath(*v) } return _u } // SetFileSize sets the "fileSize" field. func (_u *AttachmentUpdateOne) SetFileSize(v int) *AttachmentUpdateOne { _u.mutation.ResetFileSize() _u.mutation.SetFileSize(v) return _u } // SetNillableFileSize sets the "fileSize" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableFileSize(v *int) *AttachmentUpdateOne { if v != nil { _u.SetFileSize(*v) } return _u } // AddFileSize adds value to the "fileSize" field. func (_u *AttachmentUpdateOne) AddFileSize(v int) *AttachmentUpdateOne { _u.mutation.AddFileSize(v) return _u } // SetUploader sets the "uploader" field. func (_u *AttachmentUpdateOne) SetUploader(v string) *AttachmentUpdateOne { _u.mutation.SetUploader(v) return _u } // SetNillableUploader sets the "uploader" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableUploader(v *string) *AttachmentUpdateOne { if v != nil { _u.SetUploader(*v) } return _u } // SetFileType sets the "fileType" field. func (_u *AttachmentUpdateOne) SetFileType(v string) *AttachmentUpdateOne { _u.mutation.SetFileType(v) return _u } // SetNillableFileType sets the "fileType" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableFileType(v *string) *AttachmentUpdateOne { if v != nil { _u.SetFileType(*v) } return _u } // SetFileExt sets the "fileExt" field. func (_u *AttachmentUpdateOne) SetFileExt(v string) *AttachmentUpdateOne { _u.mutation.SetFileExt(v) return _u } // SetNillableFileExt sets the "fileExt" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableFileExt(v *string) *AttachmentUpdateOne { if v != nil { _u.SetFileExt(*v) } return _u } // SetFileMd5 sets the "fileMd5" field. func (_u *AttachmentUpdateOne) SetFileMd5(v string) *AttachmentUpdateOne { _u.mutation.SetFileMd5(v) return _u } // SetNillableFileMd5 sets the "fileMd5" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableFileMd5(v *string) *AttachmentUpdateOne { if v != nil { _u.SetFileMd5(*v) } return _u } // SetMimeType sets the "mimeType" field. func (_u *AttachmentUpdateOne) SetMimeType(v string) *AttachmentUpdateOne { _u.mutation.SetMimeType(v) return _u } // SetNillableMimeType sets the "mimeType" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableMimeType(v *string) *AttachmentUpdateOne { if v != nil { _u.SetMimeType(*v) } return _u } // SetArchived sets the "archived" field. func (_u *AttachmentUpdateOne) SetArchived(v bool) *AttachmentUpdateOne { _u.mutation.SetArchived(v) return _u } // SetNillableArchived sets the "archived" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableArchived(v *bool) *AttachmentUpdateOne { if v != nil { _u.SetArchived(*v) } return _u } // SetArchivedAt sets the "archivedAt" field. func (_u *AttachmentUpdateOne) SetArchivedAt(v int64) *AttachmentUpdateOne { _u.mutation.ResetArchivedAt() _u.mutation.SetArchivedAt(v) return _u } // SetNillableArchivedAt sets the "archivedAt" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableArchivedAt(v *int64) *AttachmentUpdateOne { if v != nil { _u.SetArchivedAt(*v) } return _u } // AddArchivedAt adds value to the "archivedAt" field. func (_u *AttachmentUpdateOne) AddArchivedAt(v int64) *AttachmentUpdateOne { _u.mutation.AddArchivedAt(v) return _u } // SetDeleted sets the "deleted" field. func (_u *AttachmentUpdateOne) SetDeleted(v bool) *AttachmentUpdateOne { _u.mutation.SetDeleted(v) return _u } // SetNillableDeleted sets the "deleted" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableDeleted(v *bool) *AttachmentUpdateOne { if v != nil { _u.SetDeleted(*v) } return _u } // SetDeletedAt sets the "deletedAt" field. func (_u *AttachmentUpdateOne) SetDeletedAt(v int64) *AttachmentUpdateOne { _u.mutation.ResetDeletedAt() _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deletedAt" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableDeletedAt(v *int64) *AttachmentUpdateOne { if v != nil { _u.SetDeletedAt(*v) } return _u } // AddDeletedAt adds value to the "deletedAt" field. func (_u *AttachmentUpdateOne) AddDeletedAt(v int64) *AttachmentUpdateOne { _u.mutation.AddDeletedAt(v) return _u } // SetDeletedBy sets the "deletedBy" field. func (_u *AttachmentUpdateOne) SetDeletedBy(v string) *AttachmentUpdateOne { _u.mutation.SetDeletedBy(v) return _u } // SetNillableDeletedBy sets the "deletedBy" field if the given value is not nil. func (_u *AttachmentUpdateOne) SetNillableDeletedBy(v *string) *AttachmentUpdateOne { if v != nil { _u.SetDeletedBy(*v) } return _u } // Mutation returns the AttachmentMutation object of the builder. func (_u *AttachmentUpdateOne) Mutation() *AttachmentMutation { return _u.mutation } // Where appends a list predicates to the AttachmentUpdate builder. func (_u *AttachmentUpdateOne) Where(ps ...predicate.Attachment) *AttachmentUpdateOne { _u.mutation.Where(ps...) return _u } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (_u *AttachmentUpdateOne) Select(field string, fields ...string) *AttachmentUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated Attachment entity. func (_u *AttachmentUpdateOne) Save(ctx context.Context) (*Attachment, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *AttachmentUpdateOne) SaveX(ctx context.Context) *Attachment { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *AttachmentUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *AttachmentUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_u *AttachmentUpdateOne) check() error { if v, ok := _u.mutation.BizType(); ok { if err := attachment.BizTypeValidator(v); err != nil { return &ValidationError{Name: "bizType", err: fmt.Errorf(`ent: validator failed for field "Attachment.bizType": %w`, err)} } } if v, ok := _u.mutation.BizId(); ok { if err := attachment.BizIdValidator(v); err != nil { return &ValidationError{Name: "bizId", err: fmt.Errorf(`ent: validator failed for field "Attachment.bizId": %w`, err)} } } if v, ok := _u.mutation.FileName(); ok { if err := attachment.FileNameValidator(v); err != nil { return &ValidationError{Name: "fileName", err: fmt.Errorf(`ent: validator failed for field "Attachment.fileName": %w`, err)} } } if v, ok := _u.mutation.FilePath(); ok { if err := attachment.FilePathValidator(v); err != nil { return &ValidationError{Name: "filePath", err: fmt.Errorf(`ent: validator failed for field "Attachment.filePath": %w`, err)} } } if v, ok := _u.mutation.Uploader(); ok { if err := attachment.UploaderValidator(v); err != nil { return &ValidationError{Name: "uploader", err: fmt.Errorf(`ent: validator failed for field "Attachment.uploader": %w`, err)} } } if v, ok := _u.mutation.FileType(); ok { if err := attachment.FileTypeValidator(v); err != nil { return &ValidationError{Name: "fileType", err: fmt.Errorf(`ent: validator failed for field "Attachment.fileType": %w`, err)} } } if v, ok := _u.mutation.FileExt(); ok { if err := attachment.FileExtValidator(v); err != nil { return &ValidationError{Name: "fileExt", err: fmt.Errorf(`ent: validator failed for field "Attachment.fileExt": %w`, err)} } } if v, ok := _u.mutation.FileMd5(); ok { if err := attachment.FileMd5Validator(v); err != nil { return &ValidationError{Name: "fileMd5", err: fmt.Errorf(`ent: validator failed for field "Attachment.fileMd5": %w`, err)} } } if v, ok := _u.mutation.MimeType(); ok { if err := attachment.MimeTypeValidator(v); err != nil { return &ValidationError{Name: "mimeType", err: fmt.Errorf(`ent: validator failed for field "Attachment.mimeType": %w`, err)} } } if v, ok := _u.mutation.DeletedBy(); ok { if err := attachment.DeletedByValidator(v); err != nil { return &ValidationError{Name: "deletedBy", err: fmt.Errorf(`ent: validator failed for field "Attachment.deletedBy": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *AttachmentUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AttachmentUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Attachment.id" for update`)} } _spec.Node.ID.Value = id if fields := _u.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, attachment.FieldID) for _, f := range fields { if !attachment.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != attachment.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := _u.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := _u.mutation.BizType(); ok { _spec.SetField(attachment.FieldBizType, field.TypeString, value) } if value, ok := _u.mutation.BizId(); ok { _spec.SetField(attachment.FieldBizId, field.TypeString, value) } if value, ok := _u.mutation.FileName(); ok { _spec.SetField(attachment.FieldFileName, field.TypeString, value) } if value, ok := _u.mutation.FilePath(); ok { _spec.SetField(attachment.FieldFilePath, field.TypeString, value) } if value, ok := _u.mutation.FileSize(); ok { _spec.SetField(attachment.FieldFileSize, field.TypeInt, value) } if value, ok := _u.mutation.AddedFileSize(); ok { _spec.AddField(attachment.FieldFileSize, field.TypeInt, value) } if value, ok := _u.mutation.Uploader(); ok { _spec.SetField(attachment.FieldUploader, field.TypeString, value) } if value, ok := _u.mutation.FileType(); ok { _spec.SetField(attachment.FieldFileType, field.TypeString, value) } if value, ok := _u.mutation.FileExt(); ok { _spec.SetField(attachment.FieldFileExt, field.TypeString, value) } if value, ok := _u.mutation.FileMd5(); ok { _spec.SetField(attachment.FieldFileMd5, field.TypeString, value) } if value, ok := _u.mutation.MimeType(); ok { _spec.SetField(attachment.FieldMimeType, field.TypeString, value) } if value, ok := _u.mutation.Archived(); ok { _spec.SetField(attachment.FieldArchived, field.TypeBool, value) } if value, ok := _u.mutation.ArchivedAt(); ok { _spec.SetField(attachment.FieldArchivedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedArchivedAt(); ok { _spec.AddField(attachment.FieldArchivedAt, field.TypeInt64, value) } if value, ok := _u.mutation.Deleted(); ok { _spec.SetField(attachment.FieldDeleted, field.TypeBool, value) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(attachment.FieldDeletedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedDeletedAt(); ok { _spec.AddField(attachment.FieldDeletedAt, field.TypeInt64, value) } if value, ok := _u.mutation.DeletedBy(); ok { _spec.SetField(attachment.FieldDeletedBy, field.TypeString, value) } _spec.AddModifiers(_u.modifiers...) _node = &Attachment{config: _u.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{attachment.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }