// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "kra/internal/data/ent/admin" "kra/internal/data/ent/predicate" ) // AdminUpdate is the builder for updating Admin entities. type AdminUpdate struct { config hooks []Hook mutation *AdminMutation } // Where appends a list predicates to the AdminUpdate builder. func (_u *AdminUpdate) Where(ps ...predicate.Admin) *AdminUpdate { _u.mutation.Where(ps...) return _u } // SetName sets the "name" field. func (_u *AdminUpdate) SetName(v string) *AdminUpdate { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *AdminUpdate) SetNillableName(v *string) *AdminUpdate { if v != nil { _u.SetName(*v) } return _u } // SetEmail sets the "email" field. func (_u *AdminUpdate) SetEmail(v string) *AdminUpdate { _u.mutation.SetEmail(v) return _u } // SetNillableEmail sets the "email" field if the given value is not nil. func (_u *AdminUpdate) SetNillableEmail(v *string) *AdminUpdate { if v != nil { _u.SetEmail(*v) } return _u } // SetAvatar sets the "avatar" field. func (_u *AdminUpdate) SetAvatar(v string) *AdminUpdate { _u.mutation.SetAvatar(v) return _u } // SetNillableAvatar sets the "avatar" field if the given value is not nil. func (_u *AdminUpdate) SetNillableAvatar(v *string) *AdminUpdate { if v != nil { _u.SetAvatar(*v) } return _u } // SetAccess sets the "access" field. func (_u *AdminUpdate) SetAccess(v string) *AdminUpdate { _u.mutation.SetAccess(v) return _u } // SetNillableAccess sets the "access" field if the given value is not nil. func (_u *AdminUpdate) SetNillableAccess(v *string) *AdminUpdate { if v != nil { _u.SetAccess(*v) } return _u } // SetPassword sets the "password" field. func (_u *AdminUpdate) SetPassword(v string) *AdminUpdate { _u.mutation.SetPassword(v) return _u } // SetNillablePassword sets the "password" field if the given value is not nil. func (_u *AdminUpdate) SetNillablePassword(v *string) *AdminUpdate { if v != nil { _u.SetPassword(*v) } return _u } // SetUpdateTime sets the "update_time" field. func (_u *AdminUpdate) SetUpdateTime(v time.Time) *AdminUpdate { _u.mutation.SetUpdateTime(v) return _u } // Mutation returns the AdminMutation object of the builder. func (_u *AdminUpdate) Mutation() *AdminMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *AdminUpdate) 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 *AdminUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *AdminUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *AdminUpdate) 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 *AdminUpdate) defaults() { if _, ok := _u.mutation.UpdateTime(); !ok { v := admin.UpdateDefaultUpdateTime() _u.mutation.SetUpdateTime(v) } } func (_u *AdminUpdate) sqlSave(ctx context.Context) (_node int, err error) { _spec := sqlgraph.NewUpdateSpec(admin.Table, admin.Columns, sqlgraph.NewFieldSpec(admin.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.Name(); ok { _spec.SetField(admin.FieldName, field.TypeString, value) } if value, ok := _u.mutation.Email(); ok { _spec.SetField(admin.FieldEmail, field.TypeString, value) } if value, ok := _u.mutation.Avatar(); ok { _spec.SetField(admin.FieldAvatar, field.TypeString, value) } if value, ok := _u.mutation.Access(); ok { _spec.SetField(admin.FieldAccess, field.TypeString, value) } if value, ok := _u.mutation.Password(); ok { _spec.SetField(admin.FieldPassword, field.TypeString, value) } if value, ok := _u.mutation.UpdateTime(); ok { _spec.SetField(admin.FieldUpdateTime, field.TypeTime, value) } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{admin.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // AdminUpdateOne is the builder for updating a single Admin entity. type AdminUpdateOne struct { config fields []string hooks []Hook mutation *AdminMutation } // SetName sets the "name" field. func (_u *AdminUpdateOne) SetName(v string) *AdminUpdateOne { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *AdminUpdateOne) SetNillableName(v *string) *AdminUpdateOne { if v != nil { _u.SetName(*v) } return _u } // SetEmail sets the "email" field. func (_u *AdminUpdateOne) SetEmail(v string) *AdminUpdateOne { _u.mutation.SetEmail(v) return _u } // SetNillableEmail sets the "email" field if the given value is not nil. func (_u *AdminUpdateOne) SetNillableEmail(v *string) *AdminUpdateOne { if v != nil { _u.SetEmail(*v) } return _u } // SetAvatar sets the "avatar" field. func (_u *AdminUpdateOne) SetAvatar(v string) *AdminUpdateOne { _u.mutation.SetAvatar(v) return _u } // SetNillableAvatar sets the "avatar" field if the given value is not nil. func (_u *AdminUpdateOne) SetNillableAvatar(v *string) *AdminUpdateOne { if v != nil { _u.SetAvatar(*v) } return _u } // SetAccess sets the "access" field. func (_u *AdminUpdateOne) SetAccess(v string) *AdminUpdateOne { _u.mutation.SetAccess(v) return _u } // SetNillableAccess sets the "access" field if the given value is not nil. func (_u *AdminUpdateOne) SetNillableAccess(v *string) *AdminUpdateOne { if v != nil { _u.SetAccess(*v) } return _u } // SetPassword sets the "password" field. func (_u *AdminUpdateOne) SetPassword(v string) *AdminUpdateOne { _u.mutation.SetPassword(v) return _u } // SetNillablePassword sets the "password" field if the given value is not nil. func (_u *AdminUpdateOne) SetNillablePassword(v *string) *AdminUpdateOne { if v != nil { _u.SetPassword(*v) } return _u } // SetUpdateTime sets the "update_time" field. func (_u *AdminUpdateOne) SetUpdateTime(v time.Time) *AdminUpdateOne { _u.mutation.SetUpdateTime(v) return _u } // Mutation returns the AdminMutation object of the builder. func (_u *AdminUpdateOne) Mutation() *AdminMutation { return _u.mutation } // Where appends a list predicates to the AdminUpdate builder. func (_u *AdminUpdateOne) Where(ps ...predicate.Admin) *AdminUpdateOne { _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 *AdminUpdateOne) Select(field string, fields ...string) *AdminUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated Admin entity. func (_u *AdminUpdateOne) Save(ctx context.Context) (*Admin, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *AdminUpdateOne) SaveX(ctx context.Context) *Admin { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *AdminUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *AdminUpdateOne) 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 *AdminUpdateOne) defaults() { if _, ok := _u.mutation.UpdateTime(); !ok { v := admin.UpdateDefaultUpdateTime() _u.mutation.SetUpdateTime(v) } } func (_u *AdminUpdateOne) sqlSave(ctx context.Context) (_node *Admin, err error) { _spec := sqlgraph.NewUpdateSpec(admin.Table, admin.Columns, sqlgraph.NewFieldSpec(admin.FieldID, field.TypeInt64)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Admin.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, admin.FieldID) for _, f := range fields { if !admin.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != admin.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.Name(); ok { _spec.SetField(admin.FieldName, field.TypeString, value) } if value, ok := _u.mutation.Email(); ok { _spec.SetField(admin.FieldEmail, field.TypeString, value) } if value, ok := _u.mutation.Avatar(); ok { _spec.SetField(admin.FieldAvatar, field.TypeString, value) } if value, ok := _u.mutation.Access(); ok { _spec.SetField(admin.FieldAccess, field.TypeString, value) } if value, ok := _u.mutation.Password(); ok { _spec.SetField(admin.FieldPassword, field.TypeString, value) } if value, ok := _u.mutation.UpdateTime(); ok { _spec.SetField(admin.FieldUpdateTime, field.TypeTime, value) } _node = &Admin{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{admin.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }