// Code generated by ent, DO NOT EDIT. package ent import ( "cn/oneao/base-go/ent/predicate" "cn/oneao/base-go/ent/userinfo" "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // UserInfoUpdate is the builder for updating UserInfo entities. type UserInfoUpdate struct { config hooks []Hook mutation *UserInfoMutation } // Where appends a list predicates to the UserInfoUpdate builder. func (_u *UserInfoUpdate) Where(ps ...predicate.UserInfo) *UserInfoUpdate { _u.mutation.Where(ps...) return _u } // SetSeqNo sets the "seq_no" field. func (_u *UserInfoUpdate) SetSeqNo(v int64) *UserInfoUpdate { _u.mutation.ResetSeqNo() _u.mutation.SetSeqNo(v) return _u } // SetNillableSeqNo sets the "seq_no" field if the given value is not nil. func (_u *UserInfoUpdate) SetNillableSeqNo(v *int64) *UserInfoUpdate { if v != nil { _u.SetSeqNo(*v) } return _u } // AddSeqNo adds value to the "seq_no" field. func (_u *UserInfoUpdate) AddSeqNo(v int64) *UserInfoUpdate { _u.mutation.AddSeqNo(v) return _u } // SetEmail sets the "email" field. func (_u *UserInfoUpdate) SetEmail(v string) *UserInfoUpdate { _u.mutation.SetEmail(v) return _u } // SetNillableEmail sets the "email" field if the given value is not nil. func (_u *UserInfoUpdate) SetNillableEmail(v *string) *UserInfoUpdate { if v != nil { _u.SetEmail(*v) } return _u } // SetUsername sets the "username" field. func (_u *UserInfoUpdate) SetUsername(v string) *UserInfoUpdate { _u.mutation.SetUsername(v) return _u } // SetNillableUsername sets the "username" field if the given value is not nil. func (_u *UserInfoUpdate) SetNillableUsername(v *string) *UserInfoUpdate { if v != nil { _u.SetUsername(*v) } return _u } // SetPassword sets the "password" field. func (_u *UserInfoUpdate) SetPassword(v string) *UserInfoUpdate { _u.mutation.SetPassword(v) return _u } // SetNillablePassword sets the "password" field if the given value is not nil. func (_u *UserInfoUpdate) SetNillablePassword(v *string) *UserInfoUpdate { if v != nil { _u.SetPassword(*v) } return _u } // SetGender sets the "gender" field. func (_u *UserInfoUpdate) SetGender(v int64) *UserInfoUpdate { _u.mutation.ResetGender() _u.mutation.SetGender(v) return _u } // SetNillableGender sets the "gender" field if the given value is not nil. func (_u *UserInfoUpdate) SetNillableGender(v *int64) *UserInfoUpdate { if v != nil { _u.SetGender(*v) } return _u } // AddGender adds value to the "gender" field. func (_u *UserInfoUpdate) AddGender(v int64) *UserInfoUpdate { _u.mutation.AddGender(v) return _u } // SetAccount sets the "account" field. func (_u *UserInfoUpdate) SetAccount(v string) *UserInfoUpdate { _u.mutation.SetAccount(v) return _u } // SetNillableAccount sets the "account" field if the given value is not nil. func (_u *UserInfoUpdate) SetNillableAccount(v *string) *UserInfoUpdate { if v != nil { _u.SetAccount(*v) } return _u } // SetUpdateTime sets the "update_time" field. func (_u *UserInfoUpdate) SetUpdateTime(v time.Time) *UserInfoUpdate { _u.mutation.SetUpdateTime(v) return _u } // SetLastLoginTime sets the "last_login_time" field. func (_u *UserInfoUpdate) SetLastLoginTime(v time.Time) *UserInfoUpdate { _u.mutation.SetLastLoginTime(v) return _u } // SetNillableLastLoginTime sets the "last_login_time" field if the given value is not nil. func (_u *UserInfoUpdate) SetNillableLastLoginTime(v *time.Time) *UserInfoUpdate { if v != nil { _u.SetLastLoginTime(*v) } return _u } // ClearLastLoginTime clears the value of the "last_login_time" field. func (_u *UserInfoUpdate) ClearLastLoginTime() *UserInfoUpdate { _u.mutation.ClearLastLoginTime() return _u } // Mutation returns the UserInfoMutation object of the builder. func (_u *UserInfoUpdate) Mutation() *UserInfoMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *UserInfoUpdate) Save(ctx context.Context) (int, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *UserInfoUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *UserInfoUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *UserInfoUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_u *UserInfoUpdate) defaults() { if _, ok := _u.mutation.UpdateTime(); !ok { v := userinfo.UpdateDefaultUpdateTime() _u.mutation.SetUpdateTime(v) } } // check runs all checks and user-defined validators on the builder. func (_u *UserInfoUpdate) check() error { if v, ok := _u.mutation.Email(); ok { if err := userinfo.EmailValidator(v); err != nil { return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "UserInfo.email": %w`, err)} } } if v, ok := _u.mutation.Username(); ok { if err := userinfo.UsernameValidator(v); err != nil { return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "UserInfo.username": %w`, err)} } } if v, ok := _u.mutation.Password(); ok { if err := userinfo.PasswordValidator(v); err != nil { return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "UserInfo.password": %w`, err)} } } if v, ok := _u.mutation.Account(); ok { if err := userinfo.AccountValidator(v); err != nil { return &ValidationError{Name: "account", err: fmt.Errorf(`ent: validator failed for field "UserInfo.account": %w`, err)} } } return nil } func (_u *UserInfoUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(userinfo.Table, userinfo.Columns, sqlgraph.NewFieldSpec(userinfo.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.SeqNo(); ok { _spec.SetField(userinfo.FieldSeqNo, field.TypeInt64, value) } if value, ok := _u.mutation.AddedSeqNo(); ok { _spec.AddField(userinfo.FieldSeqNo, field.TypeInt64, value) } if value, ok := _u.mutation.Email(); ok { _spec.SetField(userinfo.FieldEmail, field.TypeString, value) } if value, ok := _u.mutation.Username(); ok { _spec.SetField(userinfo.FieldUsername, field.TypeString, value) } if value, ok := _u.mutation.Password(); ok { _spec.SetField(userinfo.FieldPassword, field.TypeString, value) } if value, ok := _u.mutation.Gender(); ok { _spec.SetField(userinfo.FieldGender, field.TypeInt64, value) } if value, ok := _u.mutation.AddedGender(); ok { _spec.AddField(userinfo.FieldGender, field.TypeInt64, value) } if value, ok := _u.mutation.Account(); ok { _spec.SetField(userinfo.FieldAccount, field.TypeString, value) } if value, ok := _u.mutation.UpdateTime(); ok { _spec.SetField(userinfo.FieldUpdateTime, field.TypeTime, value) } if value, ok := _u.mutation.LastLoginTime(); ok { _spec.SetField(userinfo.FieldLastLoginTime, field.TypeTime, value) } if _u.mutation.LastLoginTimeCleared() { _spec.ClearField(userinfo.FieldLastLoginTime, field.TypeTime) } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{userinfo.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // UserInfoUpdateOne is the builder for updating a single UserInfo entity. type UserInfoUpdateOne struct { config fields []string hooks []Hook mutation *UserInfoMutation } // SetSeqNo sets the "seq_no" field. func (_u *UserInfoUpdateOne) SetSeqNo(v int64) *UserInfoUpdateOne { _u.mutation.ResetSeqNo() _u.mutation.SetSeqNo(v) return _u } // SetNillableSeqNo sets the "seq_no" field if the given value is not nil. func (_u *UserInfoUpdateOne) SetNillableSeqNo(v *int64) *UserInfoUpdateOne { if v != nil { _u.SetSeqNo(*v) } return _u } // AddSeqNo adds value to the "seq_no" field. func (_u *UserInfoUpdateOne) AddSeqNo(v int64) *UserInfoUpdateOne { _u.mutation.AddSeqNo(v) return _u } // SetEmail sets the "email" field. func (_u *UserInfoUpdateOne) SetEmail(v string) *UserInfoUpdateOne { _u.mutation.SetEmail(v) return _u } // SetNillableEmail sets the "email" field if the given value is not nil. func (_u *UserInfoUpdateOne) SetNillableEmail(v *string) *UserInfoUpdateOne { if v != nil { _u.SetEmail(*v) } return _u } // SetUsername sets the "username" field. func (_u *UserInfoUpdateOne) SetUsername(v string) *UserInfoUpdateOne { _u.mutation.SetUsername(v) return _u } // SetNillableUsername sets the "username" field if the given value is not nil. func (_u *UserInfoUpdateOne) SetNillableUsername(v *string) *UserInfoUpdateOne { if v != nil { _u.SetUsername(*v) } return _u } // SetPassword sets the "password" field. func (_u *UserInfoUpdateOne) SetPassword(v string) *UserInfoUpdateOne { _u.mutation.SetPassword(v) return _u } // SetNillablePassword sets the "password" field if the given value is not nil. func (_u *UserInfoUpdateOne) SetNillablePassword(v *string) *UserInfoUpdateOne { if v != nil { _u.SetPassword(*v) } return _u } // SetGender sets the "gender" field. func (_u *UserInfoUpdateOne) SetGender(v int64) *UserInfoUpdateOne { _u.mutation.ResetGender() _u.mutation.SetGender(v) return _u } // SetNillableGender sets the "gender" field if the given value is not nil. func (_u *UserInfoUpdateOne) SetNillableGender(v *int64) *UserInfoUpdateOne { if v != nil { _u.SetGender(*v) } return _u } // AddGender adds value to the "gender" field. func (_u *UserInfoUpdateOne) AddGender(v int64) *UserInfoUpdateOne { _u.mutation.AddGender(v) return _u } // SetAccount sets the "account" field. func (_u *UserInfoUpdateOne) SetAccount(v string) *UserInfoUpdateOne { _u.mutation.SetAccount(v) return _u } // SetNillableAccount sets the "account" field if the given value is not nil. func (_u *UserInfoUpdateOne) SetNillableAccount(v *string) *UserInfoUpdateOne { if v != nil { _u.SetAccount(*v) } return _u } // SetUpdateTime sets the "update_time" field. func (_u *UserInfoUpdateOne) SetUpdateTime(v time.Time) *UserInfoUpdateOne { _u.mutation.SetUpdateTime(v) return _u } // SetLastLoginTime sets the "last_login_time" field. func (_u *UserInfoUpdateOne) SetLastLoginTime(v time.Time) *UserInfoUpdateOne { _u.mutation.SetLastLoginTime(v) return _u } // SetNillableLastLoginTime sets the "last_login_time" field if the given value is not nil. func (_u *UserInfoUpdateOne) SetNillableLastLoginTime(v *time.Time) *UserInfoUpdateOne { if v != nil { _u.SetLastLoginTime(*v) } return _u } // ClearLastLoginTime clears the value of the "last_login_time" field. func (_u *UserInfoUpdateOne) ClearLastLoginTime() *UserInfoUpdateOne { _u.mutation.ClearLastLoginTime() return _u } // Mutation returns the UserInfoMutation object of the builder. func (_u *UserInfoUpdateOne) Mutation() *UserInfoMutation { return _u.mutation } // Where appends a list predicates to the UserInfoUpdate builder. func (_u *UserInfoUpdateOne) Where(ps ...predicate.UserInfo) *UserInfoUpdateOne { _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 *UserInfoUpdateOne) Select(field string, fields ...string) *UserInfoUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated UserInfo entity. func (_u *UserInfoUpdateOne) Save(ctx context.Context) (*UserInfo, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *UserInfoUpdateOne) SaveX(ctx context.Context) *UserInfo { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *UserInfoUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *UserInfoUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_u *UserInfoUpdateOne) defaults() { if _, ok := _u.mutation.UpdateTime(); !ok { v := userinfo.UpdateDefaultUpdateTime() _u.mutation.SetUpdateTime(v) } } // check runs all checks and user-defined validators on the builder. func (_u *UserInfoUpdateOne) check() error { if v, ok := _u.mutation.Email(); ok { if err := userinfo.EmailValidator(v); err != nil { return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "UserInfo.email": %w`, err)} } } if v, ok := _u.mutation.Username(); ok { if err := userinfo.UsernameValidator(v); err != nil { return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "UserInfo.username": %w`, err)} } } if v, ok := _u.mutation.Password(); ok { if err := userinfo.PasswordValidator(v); err != nil { return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "UserInfo.password": %w`, err)} } } if v, ok := _u.mutation.Account(); ok { if err := userinfo.AccountValidator(v); err != nil { return &ValidationError{Name: "account", err: fmt.Errorf(`ent: validator failed for field "UserInfo.account": %w`, err)} } } return nil } func (_u *UserInfoUpdateOne) sqlSave(ctx context.Context) (_node *UserInfo, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(userinfo.Table, userinfo.Columns, sqlgraph.NewFieldSpec(userinfo.FieldID, field.TypeInt64)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserInfo.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, userinfo.FieldID) for _, f := range fields { if !userinfo.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != userinfo.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.SeqNo(); ok { _spec.SetField(userinfo.FieldSeqNo, field.TypeInt64, value) } if value, ok := _u.mutation.AddedSeqNo(); ok { _spec.AddField(userinfo.FieldSeqNo, field.TypeInt64, value) } if value, ok := _u.mutation.Email(); ok { _spec.SetField(userinfo.FieldEmail, field.TypeString, value) } if value, ok := _u.mutation.Username(); ok { _spec.SetField(userinfo.FieldUsername, field.TypeString, value) } if value, ok := _u.mutation.Password(); ok { _spec.SetField(userinfo.FieldPassword, field.TypeString, value) } if value, ok := _u.mutation.Gender(); ok { _spec.SetField(userinfo.FieldGender, field.TypeInt64, value) } if value, ok := _u.mutation.AddedGender(); ok { _spec.AddField(userinfo.FieldGender, field.TypeInt64, value) } if value, ok := _u.mutation.Account(); ok { _spec.SetField(userinfo.FieldAccount, field.TypeString, value) } if value, ok := _u.mutation.UpdateTime(); ok { _spec.SetField(userinfo.FieldUpdateTime, field.TypeTime, value) } if value, ok := _u.mutation.LastLoginTime(); ok { _spec.SetField(userinfo.FieldLastLoginTime, field.TypeTime, value) } if _u.mutation.LastLoginTimeCleared() { _spec.ClearField(userinfo.FieldLastLoginTime, field.TypeTime) } _node = &UserInfo{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{userinfo.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }