// 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" "git.dotya.ml/mirre-mt/pcmt/ent/agekey" "git.dotya.ml/mirre-mt/pcmt/ent/predicate" ) // AgeKeyUpdate is the builder for updating AgeKey entities. type AgeKeyUpdate struct { config hooks []Hook mutation *AgeKeyMutation } // Where appends a list predicates to the AgeKeyUpdate builder. func (aku *AgeKeyUpdate) Where(ps ...predicate.AgeKey) *AgeKeyUpdate { aku.mutation.Where(ps...) return aku } // SetKey sets the "key" field. func (aku *AgeKeyUpdate) SetKey(b []byte) *AgeKeyUpdate { aku.mutation.SetKey(b) return aku } // SetUpdated sets the "updated" field. func (aku *AgeKeyUpdate) SetUpdated(t time.Time) *AgeKeyUpdate { aku.mutation.SetUpdated(t) return aku } // SetNillableUpdated sets the "updated" field if the given value is not nil. func (aku *AgeKeyUpdate) SetNillableUpdated(t *time.Time) *AgeKeyUpdate { if t != nil { aku.SetUpdated(*t) } return aku } // Mutation returns the AgeKeyMutation object of the builder. func (aku *AgeKeyUpdate) Mutation() *AgeKeyMutation { return aku.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (aku *AgeKeyUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, aku.sqlSave, aku.mutation, aku.hooks) } // SaveX is like Save, but panics if an error occurs. func (aku *AgeKeyUpdate) SaveX(ctx context.Context) int { affected, err := aku.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (aku *AgeKeyUpdate) Exec(ctx context.Context) error { _, err := aku.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (aku *AgeKeyUpdate) ExecX(ctx context.Context) { if err := aku.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (aku *AgeKeyUpdate) check() error { if v, ok := aku.mutation.Key(); ok { if err := agekey.KeyValidator(v); err != nil { return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "AgeKey.key": %w`, err)} } } if _, ok := aku.mutation.UserID(); aku.mutation.UserCleared() && !ok { return errors.New(`ent: clearing a required unique edge "AgeKey.user"`) } return nil } func (aku *AgeKeyUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := aku.check(); err != nil { return n, err } _spec := sqlgraph.NewUpdateSpec(agekey.Table, agekey.Columns, sqlgraph.NewFieldSpec(agekey.FieldID, field.TypeUUID)) if ps := aku.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := aku.mutation.Key(); ok { _spec.SetField(agekey.FieldKey, field.TypeBytes, value) } if value, ok := aku.mutation.Updated(); ok { _spec.SetField(agekey.FieldUpdated, field.TypeTime, value) } if n, err = sqlgraph.UpdateNodes(ctx, aku.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{agekey.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } aku.mutation.done = true return n, nil } // AgeKeyUpdateOne is the builder for updating a single AgeKey entity. type AgeKeyUpdateOne struct { config fields []string hooks []Hook mutation *AgeKeyMutation } // SetKey sets the "key" field. func (akuo *AgeKeyUpdateOne) SetKey(b []byte) *AgeKeyUpdateOne { akuo.mutation.SetKey(b) return akuo } // SetUpdated sets the "updated" field. func (akuo *AgeKeyUpdateOne) SetUpdated(t time.Time) *AgeKeyUpdateOne { akuo.mutation.SetUpdated(t) return akuo } // SetNillableUpdated sets the "updated" field if the given value is not nil. func (akuo *AgeKeyUpdateOne) SetNillableUpdated(t *time.Time) *AgeKeyUpdateOne { if t != nil { akuo.SetUpdated(*t) } return akuo } // Mutation returns the AgeKeyMutation object of the builder. func (akuo *AgeKeyUpdateOne) Mutation() *AgeKeyMutation { return akuo.mutation } // Where appends a list predicates to the AgeKeyUpdate builder. func (akuo *AgeKeyUpdateOne) Where(ps ...predicate.AgeKey) *AgeKeyUpdateOne { akuo.mutation.Where(ps...) return akuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (akuo *AgeKeyUpdateOne) Select(field string, fields ...string) *AgeKeyUpdateOne { akuo.fields = append([]string{field}, fields...) return akuo } // Save executes the query and returns the updated AgeKey entity. func (akuo *AgeKeyUpdateOne) Save(ctx context.Context) (*AgeKey, error) { return withHooks(ctx, akuo.sqlSave, akuo.mutation, akuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (akuo *AgeKeyUpdateOne) SaveX(ctx context.Context) *AgeKey { node, err := akuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (akuo *AgeKeyUpdateOne) Exec(ctx context.Context) error { _, err := akuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (akuo *AgeKeyUpdateOne) ExecX(ctx context.Context) { if err := akuo.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (akuo *AgeKeyUpdateOne) check() error { if v, ok := akuo.mutation.Key(); ok { if err := agekey.KeyValidator(v); err != nil { return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "AgeKey.key": %w`, err)} } } if _, ok := akuo.mutation.UserID(); akuo.mutation.UserCleared() && !ok { return errors.New(`ent: clearing a required unique edge "AgeKey.user"`) } return nil } func (akuo *AgeKeyUpdateOne) sqlSave(ctx context.Context) (_node *AgeKey, err error) { if err := akuo.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(agekey.Table, agekey.Columns, sqlgraph.NewFieldSpec(agekey.FieldID, field.TypeUUID)) id, ok := akuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AgeKey.id" for update`)} } _spec.Node.ID.Value = id if fields := akuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, agekey.FieldID) for _, f := range fields { if !agekey.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != agekey.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := akuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := akuo.mutation.Key(); ok { _spec.SetField(agekey.FieldKey, field.TypeBytes, value) } if value, ok := akuo.mutation.Updated(); ok { _spec.SetField(agekey.FieldUpdated, field.TypeTime, value) } _node = &AgeKey{config: akuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, akuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{agekey.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } akuo.mutation.done = true return _node, nil }