// 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/google/uuid" "github.com/in-toto/archivista/ent/dsse" "github.com/in-toto/archivista/ent/payloaddigest" "github.com/in-toto/archivista/ent/predicate" ) // PayloadDigestUpdate is the builder for updating PayloadDigest entities. type PayloadDigestUpdate struct { config hooks []Hook mutation *PayloadDigestMutation } // Where appends a list predicates to the PayloadDigestUpdate builder. func (_u *PayloadDigestUpdate) Where(ps ...predicate.PayloadDigest) *PayloadDigestUpdate { _u.mutation.Where(ps...) return _u } // SetAlgorithm sets the "algorithm" field. func (_u *PayloadDigestUpdate) SetAlgorithm(v string) *PayloadDigestUpdate { _u.mutation.SetAlgorithm(v) return _u } // SetNillableAlgorithm sets the "algorithm" field if the given value is not nil. func (_u *PayloadDigestUpdate) SetNillableAlgorithm(v *string) *PayloadDigestUpdate { if v != nil { _u.SetAlgorithm(*v) } return _u } // SetValue sets the "value" field. func (_u *PayloadDigestUpdate) SetValue(v string) *PayloadDigestUpdate { _u.mutation.SetValue(v) return _u } // SetNillableValue sets the "value" field if the given value is not nil. func (_u *PayloadDigestUpdate) SetNillableValue(v *string) *PayloadDigestUpdate { if v != nil { _u.SetValue(*v) } return _u } // SetDsseID sets the "dsse" edge to the Dsse entity by ID. func (_u *PayloadDigestUpdate) SetDsseID(id uuid.UUID) *PayloadDigestUpdate { _u.mutation.SetDsseID(id) return _u } // SetNillableDsseID sets the "dsse" edge to the Dsse entity by ID if the given value is not nil. func (_u *PayloadDigestUpdate) SetNillableDsseID(id *uuid.UUID) *PayloadDigestUpdate { if id != nil { _u = _u.SetDsseID(*id) } return _u } // SetDsse sets the "dsse" edge to the Dsse entity. func (_u *PayloadDigestUpdate) SetDsse(v *Dsse) *PayloadDigestUpdate { return _u.SetDsseID(v.ID) } // Mutation returns the PayloadDigestMutation object of the builder. func (_u *PayloadDigestUpdate) Mutation() *PayloadDigestMutation { return _u.mutation } // ClearDsse clears the "dsse" edge to the Dsse entity. func (_u *PayloadDigestUpdate) ClearDsse() *PayloadDigestUpdate { _u.mutation.ClearDsse() return _u } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *PayloadDigestUpdate) 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 *PayloadDigestUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *PayloadDigestUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *PayloadDigestUpdate) 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 *PayloadDigestUpdate) check() error { if v, ok := _u.mutation.Algorithm(); ok { if err := payloaddigest.AlgorithmValidator(v); err != nil { return &ValidationError{Name: "algorithm", err: fmt.Errorf(`ent: validator failed for field "PayloadDigest.algorithm": %w`, err)} } } if v, ok := _u.mutation.Value(); ok { if err := payloaddigest.ValueValidator(v); err != nil { return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "PayloadDigest.value": %w`, err)} } } return nil } func (_u *PayloadDigestUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(payloaddigest.Table, payloaddigest.Columns, sqlgraph.NewFieldSpec(payloaddigest.FieldID, field.TypeUUID)) 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.Algorithm(); ok { _spec.SetField(payloaddigest.FieldAlgorithm, field.TypeString, value) } if value, ok := _u.mutation.Value(); ok { _spec.SetField(payloaddigest.FieldValue, field.TypeString, value) } if _u.mutation.DsseCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: payloaddigest.DsseTable, Columns: []string{payloaddigest.DsseColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.DsseIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: payloaddigest.DsseTable, Columns: []string{payloaddigest.DsseColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{payloaddigest.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // PayloadDigestUpdateOne is the builder for updating a single PayloadDigest entity. type PayloadDigestUpdateOne struct { config fields []string hooks []Hook mutation *PayloadDigestMutation } // SetAlgorithm sets the "algorithm" field. func (_u *PayloadDigestUpdateOne) SetAlgorithm(v string) *PayloadDigestUpdateOne { _u.mutation.SetAlgorithm(v) return _u } // SetNillableAlgorithm sets the "algorithm" field if the given value is not nil. func (_u *PayloadDigestUpdateOne) SetNillableAlgorithm(v *string) *PayloadDigestUpdateOne { if v != nil { _u.SetAlgorithm(*v) } return _u } // SetValue sets the "value" field. func (_u *PayloadDigestUpdateOne) SetValue(v string) *PayloadDigestUpdateOne { _u.mutation.SetValue(v) return _u } // SetNillableValue sets the "value" field if the given value is not nil. func (_u *PayloadDigestUpdateOne) SetNillableValue(v *string) *PayloadDigestUpdateOne { if v != nil { _u.SetValue(*v) } return _u } // SetDsseID sets the "dsse" edge to the Dsse entity by ID. func (_u *PayloadDigestUpdateOne) SetDsseID(id uuid.UUID) *PayloadDigestUpdateOne { _u.mutation.SetDsseID(id) return _u } // SetNillableDsseID sets the "dsse" edge to the Dsse entity by ID if the given value is not nil. func (_u *PayloadDigestUpdateOne) SetNillableDsseID(id *uuid.UUID) *PayloadDigestUpdateOne { if id != nil { _u = _u.SetDsseID(*id) } return _u } // SetDsse sets the "dsse" edge to the Dsse entity. func (_u *PayloadDigestUpdateOne) SetDsse(v *Dsse) *PayloadDigestUpdateOne { return _u.SetDsseID(v.ID) } // Mutation returns the PayloadDigestMutation object of the builder. func (_u *PayloadDigestUpdateOne) Mutation() *PayloadDigestMutation { return _u.mutation } // ClearDsse clears the "dsse" edge to the Dsse entity. func (_u *PayloadDigestUpdateOne) ClearDsse() *PayloadDigestUpdateOne { _u.mutation.ClearDsse() return _u } // Where appends a list predicates to the PayloadDigestUpdate builder. func (_u *PayloadDigestUpdateOne) Where(ps ...predicate.PayloadDigest) *PayloadDigestUpdateOne { _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 *PayloadDigestUpdateOne) Select(field string, fields ...string) *PayloadDigestUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated PayloadDigest entity. func (_u *PayloadDigestUpdateOne) Save(ctx context.Context) (*PayloadDigest, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *PayloadDigestUpdateOne) SaveX(ctx context.Context) *PayloadDigest { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *PayloadDigestUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *PayloadDigestUpdateOne) 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 *PayloadDigestUpdateOne) check() error { if v, ok := _u.mutation.Algorithm(); ok { if err := payloaddigest.AlgorithmValidator(v); err != nil { return &ValidationError{Name: "algorithm", err: fmt.Errorf(`ent: validator failed for field "PayloadDigest.algorithm": %w`, err)} } } if v, ok := _u.mutation.Value(); ok { if err := payloaddigest.ValueValidator(v); err != nil { return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "PayloadDigest.value": %w`, err)} } } return nil } func (_u *PayloadDigestUpdateOne) sqlSave(ctx context.Context) (_node *PayloadDigest, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(payloaddigest.Table, payloaddigest.Columns, sqlgraph.NewFieldSpec(payloaddigest.FieldID, field.TypeUUID)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PayloadDigest.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, payloaddigest.FieldID) for _, f := range fields { if !payloaddigest.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != payloaddigest.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.Algorithm(); ok { _spec.SetField(payloaddigest.FieldAlgorithm, field.TypeString, value) } if value, ok := _u.mutation.Value(); ok { _spec.SetField(payloaddigest.FieldValue, field.TypeString, value) } if _u.mutation.DsseCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: payloaddigest.DsseTable, Columns: []string{payloaddigest.DsseColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.DsseIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: payloaddigest.DsseTable, Columns: []string{payloaddigest.DsseColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &PayloadDigest{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{payloaddigest.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }