// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/FrankenBotDev/FrankenAPI/ent/actions" "github.com/FrankenBotDev/FrankenAPI/ent/predicate" ) // ActionsUpdate is the builder for updating Actions entities. type ActionsUpdate struct { config hooks []Hook mutation *ActionsMutation } // Where appends a list predicates to the ActionsUpdate builder. func (au *ActionsUpdate) Where(ps ...predicate.Actions) *ActionsUpdate { au.mutation.Where(ps...) return au } // SetRefid sets the "refid" field. func (au *ActionsUpdate) SetRefid(s string) *ActionsUpdate { au.mutation.SetRefid(s) return au } // SetCommiter sets the "commiter" field. func (au *ActionsUpdate) SetCommiter(s string) *ActionsUpdate { au.mutation.SetCommiter(s) return au } // SetServerid sets the "serverid" field. func (au *ActionsUpdate) SetServerid(s string) *ActionsUpdate { au.mutation.SetServerid(s) return au } // SetTarget sets the "target" field. func (au *ActionsUpdate) SetTarget(s string) *ActionsUpdate { au.mutation.SetTarget(s) return au } // SetType sets the "type" field. func (au *ActionsUpdate) SetType(s string) *ActionsUpdate { au.mutation.SetType(s) return au } // SetDuration sets the "duration" field. func (au *ActionsUpdate) SetDuration(s string) *ActionsUpdate { au.mutation.SetDuration(s) return au } // SetReason sets the "reason" field. func (au *ActionsUpdate) SetReason(s string) *ActionsUpdate { au.mutation.SetReason(s) return au } // SetTemp sets the "temp" field. func (au *ActionsUpdate) SetTemp(b bool) *ActionsUpdate { au.mutation.SetTemp(b) return au } // SetNillableTemp sets the "temp" field if the given value is not nil. func (au *ActionsUpdate) SetNillableTemp(b *bool) *ActionsUpdate { if b != nil { au.SetTemp(*b) } return au } // Mutation returns the ActionsMutation object of the builder. func (au *ActionsUpdate) Mutation() *ActionsMutation { return au.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (au *ActionsUpdate) Save(ctx context.Context) (int, error) { var ( err error affected int ) if len(au.hooks) == 0 { affected, err = au.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*ActionsMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } au.mutation = mutation affected, err = au.sqlSave(ctx) mutation.done = true return affected, err }) for i := len(au.hooks) - 1; i >= 0; i-- { if au.hooks[i] == nil { return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } mut = au.hooks[i](mut) } if _, err := mut.Mutate(ctx, au.mutation); err != nil { return 0, err } } return affected, err } // SaveX is like Save, but panics if an error occurs. func (au *ActionsUpdate) SaveX(ctx context.Context) int { affected, err := au.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (au *ActionsUpdate) Exec(ctx context.Context) error { _, err := au.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (au *ActionsUpdate) ExecX(ctx context.Context) { if err := au.Exec(ctx); err != nil { panic(err) } } func (au *ActionsUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: actions.Table, Columns: actions.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: actions.FieldID, }, }, } if ps := au.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := au.mutation.Refid(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldRefid, }) } if value, ok := au.mutation.Commiter(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldCommiter, }) } if value, ok := au.mutation.Serverid(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldServerid, }) } if value, ok := au.mutation.Target(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldTarget, }) } if value, ok := au.mutation.GetType(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldType, }) } if value, ok := au.mutation.Duration(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldDuration, }) } if value, ok := au.mutation.Reason(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldReason, }) } if value, ok := au.mutation.Temp(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: actions.FieldTemp, }) } if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{actions.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } return n, nil } // ActionsUpdateOne is the builder for updating a single Actions entity. type ActionsUpdateOne struct { config fields []string hooks []Hook mutation *ActionsMutation } // SetRefid sets the "refid" field. func (auo *ActionsUpdateOne) SetRefid(s string) *ActionsUpdateOne { auo.mutation.SetRefid(s) return auo } // SetCommiter sets the "commiter" field. func (auo *ActionsUpdateOne) SetCommiter(s string) *ActionsUpdateOne { auo.mutation.SetCommiter(s) return auo } // SetServerid sets the "serverid" field. func (auo *ActionsUpdateOne) SetServerid(s string) *ActionsUpdateOne { auo.mutation.SetServerid(s) return auo } // SetTarget sets the "target" field. func (auo *ActionsUpdateOne) SetTarget(s string) *ActionsUpdateOne { auo.mutation.SetTarget(s) return auo } // SetType sets the "type" field. func (auo *ActionsUpdateOne) SetType(s string) *ActionsUpdateOne { auo.mutation.SetType(s) return auo } // SetDuration sets the "duration" field. func (auo *ActionsUpdateOne) SetDuration(s string) *ActionsUpdateOne { auo.mutation.SetDuration(s) return auo } // SetReason sets the "reason" field. func (auo *ActionsUpdateOne) SetReason(s string) *ActionsUpdateOne { auo.mutation.SetReason(s) return auo } // SetTemp sets the "temp" field. func (auo *ActionsUpdateOne) SetTemp(b bool) *ActionsUpdateOne { auo.mutation.SetTemp(b) return auo } // SetNillableTemp sets the "temp" field if the given value is not nil. func (auo *ActionsUpdateOne) SetNillableTemp(b *bool) *ActionsUpdateOne { if b != nil { auo.SetTemp(*b) } return auo } // Mutation returns the ActionsMutation object of the builder. func (auo *ActionsUpdateOne) Mutation() *ActionsMutation { return auo.mutation } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (auo *ActionsUpdateOne) Select(field string, fields ...string) *ActionsUpdateOne { auo.fields = append([]string{field}, fields...) return auo } // Save executes the query and returns the updated Actions entity. func (auo *ActionsUpdateOne) Save(ctx context.Context) (*Actions, error) { var ( err error node *Actions ) if len(auo.hooks) == 0 { node, err = auo.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*ActionsMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } auo.mutation = mutation node, err = auo.sqlSave(ctx) mutation.done = true return node, err }) for i := len(auo.hooks) - 1; i >= 0; i-- { if auo.hooks[i] == nil { return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } mut = auo.hooks[i](mut) } v, err := mut.Mutate(ctx, auo.mutation) if err != nil { return nil, err } nv, ok := v.(*Actions) if !ok { return nil, fmt.Errorf("unexpected node type %T returned from ActionsMutation", v) } node = nv } return node, err } // SaveX is like Save, but panics if an error occurs. func (auo *ActionsUpdateOne) SaveX(ctx context.Context) *Actions { node, err := auo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (auo *ActionsUpdateOne) Exec(ctx context.Context) error { _, err := auo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (auo *ActionsUpdateOne) ExecX(ctx context.Context) { if err := auo.Exec(ctx); err != nil { panic(err) } } func (auo *ActionsUpdateOne) sqlSave(ctx context.Context) (_node *Actions, err error) { _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: actions.Table, Columns: actions.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: actions.FieldID, }, }, } id, ok := auo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Actions.id" for update`)} } _spec.Node.ID.Value = id if fields := auo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, actions.FieldID) for _, f := range fields { if !actions.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != actions.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := auo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := auo.mutation.Refid(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldRefid, }) } if value, ok := auo.mutation.Commiter(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldCommiter, }) } if value, ok := auo.mutation.Serverid(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldServerid, }) } if value, ok := auo.mutation.Target(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldTarget, }) } if value, ok := auo.mutation.GetType(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldType, }) } if value, ok := auo.mutation.Duration(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldDuration, }) } if value, ok := auo.mutation.Reason(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: actions.FieldReason, }) } if value, ok := auo.mutation.Temp(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: actions.FieldTemp, }) } _node = &Actions{config: auo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{actions.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } return _node, nil }