Files
epic-ent/internal/ent/epicheroinfo_update.go

999 lines
32 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"epic-ent/internal/ent/epicheroinfo"
"epic-ent/internal/ent/predicate"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// EpicHeroInfoUpdate is the builder for updating EpicHeroInfo entities.
type EpicHeroInfoUpdate struct {
config
hooks []Hook
mutation *EpicHeroInfoMutation
}
// Where appends a list predicates to the EpicHeroInfoUpdate builder.
func (_u *EpicHeroInfoUpdate) Where(ps ...predicate.EpicHeroInfo) *EpicHeroInfoUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetHeroName sets the "hero_name" field.
func (_u *EpicHeroInfoUpdate) SetHeroName(v string) *EpicHeroInfoUpdate {
_u.mutation.SetHeroName(v)
return _u
}
// SetNillableHeroName sets the "hero_name" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableHeroName(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetHeroName(*v)
}
return _u
}
// SetHeroCode sets the "hero_code" field.
func (_u *EpicHeroInfoUpdate) SetHeroCode(v string) *EpicHeroInfoUpdate {
_u.mutation.SetHeroCode(v)
return _u
}
// SetNillableHeroCode sets the "hero_code" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableHeroCode(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetHeroCode(*v)
}
return _u
}
// SetHeroAttrLv60 sets the "hero_attr_lv60" field.
func (_u *EpicHeroInfoUpdate) SetHeroAttrLv60(v string) *EpicHeroInfoUpdate {
_u.mutation.SetHeroAttrLv60(v)
return _u
}
// SetNillableHeroAttrLv60 sets the "hero_attr_lv60" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableHeroAttrLv60(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetHeroAttrLv60(*v)
}
return _u
}
// SetCreator sets the "creator" field.
func (_u *EpicHeroInfoUpdate) SetCreator(v string) *EpicHeroInfoUpdate {
_u.mutation.SetCreator(v)
return _u
}
// SetNillableCreator sets the "creator" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableCreator(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetCreator(*v)
}
return _u
}
// SetCreateTime sets the "create_time" field.
func (_u *EpicHeroInfoUpdate) SetCreateTime(v time.Time) *EpicHeroInfoUpdate {
_u.mutation.SetCreateTime(v)
return _u
}
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableCreateTime(v *time.Time) *EpicHeroInfoUpdate {
if v != nil {
_u.SetCreateTime(*v)
}
return _u
}
// ClearCreateTime clears the value of the "create_time" field.
func (_u *EpicHeroInfoUpdate) ClearCreateTime() *EpicHeroInfoUpdate {
_u.mutation.ClearCreateTime()
return _u
}
// SetUpdater sets the "updater" field.
func (_u *EpicHeroInfoUpdate) SetUpdater(v string) *EpicHeroInfoUpdate {
_u.mutation.SetUpdater(v)
return _u
}
// SetNillableUpdater sets the "updater" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableUpdater(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetUpdater(*v)
}
return _u
}
// SetUpdateTime sets the "update_time" field.
func (_u *EpicHeroInfoUpdate) SetUpdateTime(v time.Time) *EpicHeroInfoUpdate {
_u.mutation.SetUpdateTime(v)
return _u
}
// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableUpdateTime(v *time.Time) *EpicHeroInfoUpdate {
if v != nil {
_u.SetUpdateTime(*v)
}
return _u
}
// ClearUpdateTime clears the value of the "update_time" field.
func (_u *EpicHeroInfoUpdate) ClearUpdateTime() *EpicHeroInfoUpdate {
_u.mutation.ClearUpdateTime()
return _u
}
// SetDeleted sets the "deleted" field.
func (_u *EpicHeroInfoUpdate) SetDeleted(v bool) *EpicHeroInfoUpdate {
_u.mutation.SetDeleted(v)
return _u
}
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableDeleted(v *bool) *EpicHeroInfoUpdate {
if v != nil {
_u.SetDeleted(*v)
}
return _u
}
// SetNickName sets the "nick_name" field.
func (_u *EpicHeroInfoUpdate) SetNickName(v string) *EpicHeroInfoUpdate {
_u.mutation.SetNickName(v)
return _u
}
// SetNillableNickName sets the "nick_name" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableNickName(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetNickName(*v)
}
return _u
}
// SetRarity sets the "rarity" field.
func (_u *EpicHeroInfoUpdate) SetRarity(v string) *EpicHeroInfoUpdate {
_u.mutation.SetRarity(v)
return _u
}
// SetNillableRarity sets the "rarity" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableRarity(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetRarity(*v)
}
return _u
}
// SetRole sets the "role" field.
func (_u *EpicHeroInfoUpdate) SetRole(v string) *EpicHeroInfoUpdate {
_u.mutation.SetRole(v)
return _u
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableRole(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetRole(*v)
}
return _u
}
// SetZodiac sets the "zodiac" field.
func (_u *EpicHeroInfoUpdate) SetZodiac(v string) *EpicHeroInfoUpdate {
_u.mutation.SetZodiac(v)
return _u
}
// SetNillableZodiac sets the "zodiac" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableZodiac(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetZodiac(*v)
}
return _u
}
// SetHeadImgURL sets the "head_img_url" field.
func (_u *EpicHeroInfoUpdate) SetHeadImgURL(v string) *EpicHeroInfoUpdate {
_u.mutation.SetHeadImgURL(v)
return _u
}
// SetNillableHeadImgURL sets the "head_img_url" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableHeadImgURL(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetHeadImgURL(*v)
}
return _u
}
// SetAttribute sets the "attribute" field.
func (_u *EpicHeroInfoUpdate) SetAttribute(v string) *EpicHeroInfoUpdate {
_u.mutation.SetAttribute(v)
return _u
}
// SetNillableAttribute sets the "attribute" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableAttribute(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetAttribute(*v)
}
return _u
}
// SetRemark sets the "remark" field.
func (_u *EpicHeroInfoUpdate) SetRemark(v string) *EpicHeroInfoUpdate {
_u.mutation.SetRemark(v)
return _u
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableRemark(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetRemark(*v)
}
return _u
}
// SetRawJSON sets the "raw_json" field.
func (_u *EpicHeroInfoUpdate) SetRawJSON(v string) *EpicHeroInfoUpdate {
_u.mutation.SetRawJSON(v)
return _u
}
// SetNillableRawJSON sets the "raw_json" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableRawJSON(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetRawJSON(*v)
}
return _u
}
// SetContentJSONSet sets the "content_json_set" field.
func (_u *EpicHeroInfoUpdate) SetContentJSONSet(v string) *EpicHeroInfoUpdate {
_u.mutation.SetContentJSONSet(v)
return _u
}
// SetNillableContentJSONSet sets the "content_json_set" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableContentJSONSet(v *string) *EpicHeroInfoUpdate {
if v != nil {
_u.SetContentJSONSet(*v)
}
return _u
}
// SetUpdateTimeSet sets the "update_time_set" field.
func (_u *EpicHeroInfoUpdate) SetUpdateTimeSet(v time.Time) *EpicHeroInfoUpdate {
_u.mutation.SetUpdateTimeSet(v)
return _u
}
// SetNillableUpdateTimeSet sets the "update_time_set" field if the given value is not nil.
func (_u *EpicHeroInfoUpdate) SetNillableUpdateTimeSet(v *time.Time) *EpicHeroInfoUpdate {
if v != nil {
_u.SetUpdateTimeSet(*v)
}
return _u
}
// ClearUpdateTimeSet clears the value of the "update_time_set" field.
func (_u *EpicHeroInfoUpdate) ClearUpdateTimeSet() *EpicHeroInfoUpdate {
_u.mutation.ClearUpdateTimeSet()
return _u
}
// Mutation returns the EpicHeroInfoMutation object of the builder.
func (_u *EpicHeroInfoUpdate) Mutation() *EpicHeroInfoMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *EpicHeroInfoUpdate) 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 *EpicHeroInfoUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *EpicHeroInfoUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *EpicHeroInfoUpdate) 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 *EpicHeroInfoUpdate) check() error {
if v, ok := _u.mutation.HeroName(); ok {
if err := epicheroinfo.HeroNameValidator(v); err != nil {
return &ValidationError{Name: "hero_name", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.hero_name": %w`, err)}
}
}
if v, ok := _u.mutation.HeroCode(); ok {
if err := epicheroinfo.HeroCodeValidator(v); err != nil {
return &ValidationError{Name: "hero_code", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.hero_code": %w`, err)}
}
}
if v, ok := _u.mutation.HeroAttrLv60(); ok {
if err := epicheroinfo.HeroAttrLv60Validator(v); err != nil {
return &ValidationError{Name: "hero_attr_lv60", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.hero_attr_lv60": %w`, err)}
}
}
if v, ok := _u.mutation.Creator(); ok {
if err := epicheroinfo.CreatorValidator(v); err != nil {
return &ValidationError{Name: "creator", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.creator": %w`, err)}
}
}
if v, ok := _u.mutation.Updater(); ok {
if err := epicheroinfo.UpdaterValidator(v); err != nil {
return &ValidationError{Name: "updater", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.updater": %w`, err)}
}
}
if v, ok := _u.mutation.NickName(); ok {
if err := epicheroinfo.NickNameValidator(v); err != nil {
return &ValidationError{Name: "nick_name", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.nick_name": %w`, err)}
}
}
if v, ok := _u.mutation.Rarity(); ok {
if err := epicheroinfo.RarityValidator(v); err != nil {
return &ValidationError{Name: "rarity", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.rarity": %w`, err)}
}
}
if v, ok := _u.mutation.Role(); ok {
if err := epicheroinfo.RoleValidator(v); err != nil {
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.role": %w`, err)}
}
}
if v, ok := _u.mutation.Zodiac(); ok {
if err := epicheroinfo.ZodiacValidator(v); err != nil {
return &ValidationError{Name: "zodiac", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.zodiac": %w`, err)}
}
}
if v, ok := _u.mutation.HeadImgURL(); ok {
if err := epicheroinfo.HeadImgURLValidator(v); err != nil {
return &ValidationError{Name: "head_img_url", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.head_img_url": %w`, err)}
}
}
if v, ok := _u.mutation.Attribute(); ok {
if err := epicheroinfo.AttributeValidator(v); err != nil {
return &ValidationError{Name: "attribute", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.attribute": %w`, err)}
}
}
if v, ok := _u.mutation.Remark(); ok {
if err := epicheroinfo.RemarkValidator(v); err != nil {
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.remark": %w`, err)}
}
}
if v, ok := _u.mutation.RawJSON(); ok {
if err := epicheroinfo.RawJSONValidator(v); err != nil {
return &ValidationError{Name: "raw_json", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.raw_json": %w`, err)}
}
}
if v, ok := _u.mutation.ContentJSONSet(); ok {
if err := epicheroinfo.ContentJSONSetValidator(v); err != nil {
return &ValidationError{Name: "content_json_set", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.content_json_set": %w`, err)}
}
}
return nil
}
func (_u *EpicHeroInfoUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(epicheroinfo.Table, epicheroinfo.Columns, sqlgraph.NewFieldSpec(epicheroinfo.FieldID, field.TypeInt64))
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.HeroName(); ok {
_spec.SetField(epicheroinfo.FieldHeroName, field.TypeString, value)
}
if value, ok := _u.mutation.HeroCode(); ok {
_spec.SetField(epicheroinfo.FieldHeroCode, field.TypeString, value)
}
if value, ok := _u.mutation.HeroAttrLv60(); ok {
_spec.SetField(epicheroinfo.FieldHeroAttrLv60, field.TypeString, value)
}
if value, ok := _u.mutation.Creator(); ok {
_spec.SetField(epicheroinfo.FieldCreator, field.TypeString, value)
}
if value, ok := _u.mutation.CreateTime(); ok {
_spec.SetField(epicheroinfo.FieldCreateTime, field.TypeTime, value)
}
if _u.mutation.CreateTimeCleared() {
_spec.ClearField(epicheroinfo.FieldCreateTime, field.TypeTime)
}
if value, ok := _u.mutation.Updater(); ok {
_spec.SetField(epicheroinfo.FieldUpdater, field.TypeString, value)
}
if value, ok := _u.mutation.UpdateTime(); ok {
_spec.SetField(epicheroinfo.FieldUpdateTime, field.TypeTime, value)
}
if _u.mutation.UpdateTimeCleared() {
_spec.ClearField(epicheroinfo.FieldUpdateTime, field.TypeTime)
}
if value, ok := _u.mutation.Deleted(); ok {
_spec.SetField(epicheroinfo.FieldDeleted, field.TypeBool, value)
}
if value, ok := _u.mutation.NickName(); ok {
_spec.SetField(epicheroinfo.FieldNickName, field.TypeString, value)
}
if value, ok := _u.mutation.Rarity(); ok {
_spec.SetField(epicheroinfo.FieldRarity, field.TypeString, value)
}
if value, ok := _u.mutation.Role(); ok {
_spec.SetField(epicheroinfo.FieldRole, field.TypeString, value)
}
if value, ok := _u.mutation.Zodiac(); ok {
_spec.SetField(epicheroinfo.FieldZodiac, field.TypeString, value)
}
if value, ok := _u.mutation.HeadImgURL(); ok {
_spec.SetField(epicheroinfo.FieldHeadImgURL, field.TypeString, value)
}
if value, ok := _u.mutation.Attribute(); ok {
_spec.SetField(epicheroinfo.FieldAttribute, field.TypeString, value)
}
if value, ok := _u.mutation.Remark(); ok {
_spec.SetField(epicheroinfo.FieldRemark, field.TypeString, value)
}
if value, ok := _u.mutation.RawJSON(); ok {
_spec.SetField(epicheroinfo.FieldRawJSON, field.TypeString, value)
}
if value, ok := _u.mutation.ContentJSONSet(); ok {
_spec.SetField(epicheroinfo.FieldContentJSONSet, field.TypeString, value)
}
if value, ok := _u.mutation.UpdateTimeSet(); ok {
_spec.SetField(epicheroinfo.FieldUpdateTimeSet, field.TypeTime, value)
}
if _u.mutation.UpdateTimeSetCleared() {
_spec.ClearField(epicheroinfo.FieldUpdateTimeSet, field.TypeTime)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{epicheroinfo.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// EpicHeroInfoUpdateOne is the builder for updating a single EpicHeroInfo entity.
type EpicHeroInfoUpdateOne struct {
config
fields []string
hooks []Hook
mutation *EpicHeroInfoMutation
}
// SetHeroName sets the "hero_name" field.
func (_u *EpicHeroInfoUpdateOne) SetHeroName(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetHeroName(v)
return _u
}
// SetNillableHeroName sets the "hero_name" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableHeroName(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetHeroName(*v)
}
return _u
}
// SetHeroCode sets the "hero_code" field.
func (_u *EpicHeroInfoUpdateOne) SetHeroCode(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetHeroCode(v)
return _u
}
// SetNillableHeroCode sets the "hero_code" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableHeroCode(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetHeroCode(*v)
}
return _u
}
// SetHeroAttrLv60 sets the "hero_attr_lv60" field.
func (_u *EpicHeroInfoUpdateOne) SetHeroAttrLv60(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetHeroAttrLv60(v)
return _u
}
// SetNillableHeroAttrLv60 sets the "hero_attr_lv60" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableHeroAttrLv60(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetHeroAttrLv60(*v)
}
return _u
}
// SetCreator sets the "creator" field.
func (_u *EpicHeroInfoUpdateOne) SetCreator(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetCreator(v)
return _u
}
// SetNillableCreator sets the "creator" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableCreator(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetCreator(*v)
}
return _u
}
// SetCreateTime sets the "create_time" field.
func (_u *EpicHeroInfoUpdateOne) SetCreateTime(v time.Time) *EpicHeroInfoUpdateOne {
_u.mutation.SetCreateTime(v)
return _u
}
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableCreateTime(v *time.Time) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetCreateTime(*v)
}
return _u
}
// ClearCreateTime clears the value of the "create_time" field.
func (_u *EpicHeroInfoUpdateOne) ClearCreateTime() *EpicHeroInfoUpdateOne {
_u.mutation.ClearCreateTime()
return _u
}
// SetUpdater sets the "updater" field.
func (_u *EpicHeroInfoUpdateOne) SetUpdater(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetUpdater(v)
return _u
}
// SetNillableUpdater sets the "updater" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableUpdater(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetUpdater(*v)
}
return _u
}
// SetUpdateTime sets the "update_time" field.
func (_u *EpicHeroInfoUpdateOne) SetUpdateTime(v time.Time) *EpicHeroInfoUpdateOne {
_u.mutation.SetUpdateTime(v)
return _u
}
// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableUpdateTime(v *time.Time) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetUpdateTime(*v)
}
return _u
}
// ClearUpdateTime clears the value of the "update_time" field.
func (_u *EpicHeroInfoUpdateOne) ClearUpdateTime() *EpicHeroInfoUpdateOne {
_u.mutation.ClearUpdateTime()
return _u
}
// SetDeleted sets the "deleted" field.
func (_u *EpicHeroInfoUpdateOne) SetDeleted(v bool) *EpicHeroInfoUpdateOne {
_u.mutation.SetDeleted(v)
return _u
}
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableDeleted(v *bool) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetDeleted(*v)
}
return _u
}
// SetNickName sets the "nick_name" field.
func (_u *EpicHeroInfoUpdateOne) SetNickName(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetNickName(v)
return _u
}
// SetNillableNickName sets the "nick_name" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableNickName(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetNickName(*v)
}
return _u
}
// SetRarity sets the "rarity" field.
func (_u *EpicHeroInfoUpdateOne) SetRarity(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetRarity(v)
return _u
}
// SetNillableRarity sets the "rarity" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableRarity(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetRarity(*v)
}
return _u
}
// SetRole sets the "role" field.
func (_u *EpicHeroInfoUpdateOne) SetRole(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetRole(v)
return _u
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableRole(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetRole(*v)
}
return _u
}
// SetZodiac sets the "zodiac" field.
func (_u *EpicHeroInfoUpdateOne) SetZodiac(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetZodiac(v)
return _u
}
// SetNillableZodiac sets the "zodiac" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableZodiac(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetZodiac(*v)
}
return _u
}
// SetHeadImgURL sets the "head_img_url" field.
func (_u *EpicHeroInfoUpdateOne) SetHeadImgURL(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetHeadImgURL(v)
return _u
}
// SetNillableHeadImgURL sets the "head_img_url" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableHeadImgURL(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetHeadImgURL(*v)
}
return _u
}
// SetAttribute sets the "attribute" field.
func (_u *EpicHeroInfoUpdateOne) SetAttribute(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetAttribute(v)
return _u
}
// SetNillableAttribute sets the "attribute" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableAttribute(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetAttribute(*v)
}
return _u
}
// SetRemark sets the "remark" field.
func (_u *EpicHeroInfoUpdateOne) SetRemark(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetRemark(v)
return _u
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableRemark(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetRemark(*v)
}
return _u
}
// SetRawJSON sets the "raw_json" field.
func (_u *EpicHeroInfoUpdateOne) SetRawJSON(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetRawJSON(v)
return _u
}
// SetNillableRawJSON sets the "raw_json" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableRawJSON(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetRawJSON(*v)
}
return _u
}
// SetContentJSONSet sets the "content_json_set" field.
func (_u *EpicHeroInfoUpdateOne) SetContentJSONSet(v string) *EpicHeroInfoUpdateOne {
_u.mutation.SetContentJSONSet(v)
return _u
}
// SetNillableContentJSONSet sets the "content_json_set" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableContentJSONSet(v *string) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetContentJSONSet(*v)
}
return _u
}
// SetUpdateTimeSet sets the "update_time_set" field.
func (_u *EpicHeroInfoUpdateOne) SetUpdateTimeSet(v time.Time) *EpicHeroInfoUpdateOne {
_u.mutation.SetUpdateTimeSet(v)
return _u
}
// SetNillableUpdateTimeSet sets the "update_time_set" field if the given value is not nil.
func (_u *EpicHeroInfoUpdateOne) SetNillableUpdateTimeSet(v *time.Time) *EpicHeroInfoUpdateOne {
if v != nil {
_u.SetUpdateTimeSet(*v)
}
return _u
}
// ClearUpdateTimeSet clears the value of the "update_time_set" field.
func (_u *EpicHeroInfoUpdateOne) ClearUpdateTimeSet() *EpicHeroInfoUpdateOne {
_u.mutation.ClearUpdateTimeSet()
return _u
}
// Mutation returns the EpicHeroInfoMutation object of the builder.
func (_u *EpicHeroInfoUpdateOne) Mutation() *EpicHeroInfoMutation {
return _u.mutation
}
// Where appends a list predicates to the EpicHeroInfoUpdate builder.
func (_u *EpicHeroInfoUpdateOne) Where(ps ...predicate.EpicHeroInfo) *EpicHeroInfoUpdateOne {
_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 *EpicHeroInfoUpdateOne) Select(field string, fields ...string) *EpicHeroInfoUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated EpicHeroInfo entity.
func (_u *EpicHeroInfoUpdateOne) Save(ctx context.Context) (*EpicHeroInfo, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *EpicHeroInfoUpdateOne) SaveX(ctx context.Context) *EpicHeroInfo {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *EpicHeroInfoUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *EpicHeroInfoUpdateOne) 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 *EpicHeroInfoUpdateOne) check() error {
if v, ok := _u.mutation.HeroName(); ok {
if err := epicheroinfo.HeroNameValidator(v); err != nil {
return &ValidationError{Name: "hero_name", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.hero_name": %w`, err)}
}
}
if v, ok := _u.mutation.HeroCode(); ok {
if err := epicheroinfo.HeroCodeValidator(v); err != nil {
return &ValidationError{Name: "hero_code", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.hero_code": %w`, err)}
}
}
if v, ok := _u.mutation.HeroAttrLv60(); ok {
if err := epicheroinfo.HeroAttrLv60Validator(v); err != nil {
return &ValidationError{Name: "hero_attr_lv60", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.hero_attr_lv60": %w`, err)}
}
}
if v, ok := _u.mutation.Creator(); ok {
if err := epicheroinfo.CreatorValidator(v); err != nil {
return &ValidationError{Name: "creator", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.creator": %w`, err)}
}
}
if v, ok := _u.mutation.Updater(); ok {
if err := epicheroinfo.UpdaterValidator(v); err != nil {
return &ValidationError{Name: "updater", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.updater": %w`, err)}
}
}
if v, ok := _u.mutation.NickName(); ok {
if err := epicheroinfo.NickNameValidator(v); err != nil {
return &ValidationError{Name: "nick_name", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.nick_name": %w`, err)}
}
}
if v, ok := _u.mutation.Rarity(); ok {
if err := epicheroinfo.RarityValidator(v); err != nil {
return &ValidationError{Name: "rarity", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.rarity": %w`, err)}
}
}
if v, ok := _u.mutation.Role(); ok {
if err := epicheroinfo.RoleValidator(v); err != nil {
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.role": %w`, err)}
}
}
if v, ok := _u.mutation.Zodiac(); ok {
if err := epicheroinfo.ZodiacValidator(v); err != nil {
return &ValidationError{Name: "zodiac", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.zodiac": %w`, err)}
}
}
if v, ok := _u.mutation.HeadImgURL(); ok {
if err := epicheroinfo.HeadImgURLValidator(v); err != nil {
return &ValidationError{Name: "head_img_url", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.head_img_url": %w`, err)}
}
}
if v, ok := _u.mutation.Attribute(); ok {
if err := epicheroinfo.AttributeValidator(v); err != nil {
return &ValidationError{Name: "attribute", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.attribute": %w`, err)}
}
}
if v, ok := _u.mutation.Remark(); ok {
if err := epicheroinfo.RemarkValidator(v); err != nil {
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.remark": %w`, err)}
}
}
if v, ok := _u.mutation.RawJSON(); ok {
if err := epicheroinfo.RawJSONValidator(v); err != nil {
return &ValidationError{Name: "raw_json", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.raw_json": %w`, err)}
}
}
if v, ok := _u.mutation.ContentJSONSet(); ok {
if err := epicheroinfo.ContentJSONSetValidator(v); err != nil {
return &ValidationError{Name: "content_json_set", err: fmt.Errorf(`ent: validator failed for field "EpicHeroInfo.content_json_set": %w`, err)}
}
}
return nil
}
func (_u *EpicHeroInfoUpdateOne) sqlSave(ctx context.Context) (_node *EpicHeroInfo, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(epicheroinfo.Table, epicheroinfo.Columns, sqlgraph.NewFieldSpec(epicheroinfo.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "EpicHeroInfo.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, epicheroinfo.FieldID)
for _, f := range fields {
if !epicheroinfo.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != epicheroinfo.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.HeroName(); ok {
_spec.SetField(epicheroinfo.FieldHeroName, field.TypeString, value)
}
if value, ok := _u.mutation.HeroCode(); ok {
_spec.SetField(epicheroinfo.FieldHeroCode, field.TypeString, value)
}
if value, ok := _u.mutation.HeroAttrLv60(); ok {
_spec.SetField(epicheroinfo.FieldHeroAttrLv60, field.TypeString, value)
}
if value, ok := _u.mutation.Creator(); ok {
_spec.SetField(epicheroinfo.FieldCreator, field.TypeString, value)
}
if value, ok := _u.mutation.CreateTime(); ok {
_spec.SetField(epicheroinfo.FieldCreateTime, field.TypeTime, value)
}
if _u.mutation.CreateTimeCleared() {
_spec.ClearField(epicheroinfo.FieldCreateTime, field.TypeTime)
}
if value, ok := _u.mutation.Updater(); ok {
_spec.SetField(epicheroinfo.FieldUpdater, field.TypeString, value)
}
if value, ok := _u.mutation.UpdateTime(); ok {
_spec.SetField(epicheroinfo.FieldUpdateTime, field.TypeTime, value)
}
if _u.mutation.UpdateTimeCleared() {
_spec.ClearField(epicheroinfo.FieldUpdateTime, field.TypeTime)
}
if value, ok := _u.mutation.Deleted(); ok {
_spec.SetField(epicheroinfo.FieldDeleted, field.TypeBool, value)
}
if value, ok := _u.mutation.NickName(); ok {
_spec.SetField(epicheroinfo.FieldNickName, field.TypeString, value)
}
if value, ok := _u.mutation.Rarity(); ok {
_spec.SetField(epicheroinfo.FieldRarity, field.TypeString, value)
}
if value, ok := _u.mutation.Role(); ok {
_spec.SetField(epicheroinfo.FieldRole, field.TypeString, value)
}
if value, ok := _u.mutation.Zodiac(); ok {
_spec.SetField(epicheroinfo.FieldZodiac, field.TypeString, value)
}
if value, ok := _u.mutation.HeadImgURL(); ok {
_spec.SetField(epicheroinfo.FieldHeadImgURL, field.TypeString, value)
}
if value, ok := _u.mutation.Attribute(); ok {
_spec.SetField(epicheroinfo.FieldAttribute, field.TypeString, value)
}
if value, ok := _u.mutation.Remark(); ok {
_spec.SetField(epicheroinfo.FieldRemark, field.TypeString, value)
}
if value, ok := _u.mutation.RawJSON(); ok {
_spec.SetField(epicheroinfo.FieldRawJSON, field.TypeString, value)
}
if value, ok := _u.mutation.ContentJSONSet(); ok {
_spec.SetField(epicheroinfo.FieldContentJSONSet, field.TypeString, value)
}
if value, ok := _u.mutation.UpdateTimeSet(); ok {
_spec.SetField(epicheroinfo.FieldUpdateTimeSet, field.TypeTime, value)
}
if _u.mutation.UpdateTimeSetCleared() {
_spec.ClearField(epicheroinfo.FieldUpdateTimeSet, field.TypeTime)
}
_node = &EpicHeroInfo{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{epicheroinfo.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}