Debian Codegraph @

ent/payloaddigest_update.go

raw
1 // Code generated by ent, DO NOT EDIT.
2
3 package ent
4
5 import (
6 "context"
7 "errors"
8 "fmt"
9
10 "entgo.io/ent/dialect/sql"
11 "entgo.io/ent/dialect/sql/sqlgraph"
12 "entgo.io/ent/schema/field"
13 "github.com/google/uuid"
14 "github.com/in-toto/archivista/ent/dsse"
15 "github.com/in-toto/archivista/ent/payloaddigest"
16 "github.com/in-toto/archivista/ent/predicate"
17 )
18
19 // PayloadDigestUpdate is the builder for updating PayloadDigest entities.
20 type PayloadDigestUpdate struct {
21 config
22 hooks []Hook
23 mutation *PayloadDigestMutation
24 }
25
26 // Where appends a list predicates to the PayloadDigestUpdate builder.
27 func (_u *PayloadDigestUpdate) Where(ps ...predicate.PayloadDigest) *PayloadDigestUpdate {
28 _u.mutation.Where(ps...)
29 return _u
30 }
31
32 // SetAlgorithm sets the "algorithm" field.
33 func (_u *PayloadDigestUpdate) SetAlgorithm(v string) *PayloadDigestUpdate {
34 _u.mutation.SetAlgorithm(v)
35 return _u
36 }
37
38 // SetNillableAlgorithm sets the "algorithm" field if the given value is not nil.
39 func (_u *PayloadDigestUpdate) SetNillableAlgorithm(v *string) *PayloadDigestUpdate {
40 if v != nil {
41 _u.SetAlgorithm(*v)
42 }
43 return _u
44 }
45
46 // SetValue sets the "value" field.
47 func (_u *PayloadDigestUpdate) SetValue(v string) *PayloadDigestUpdate {
48 _u.mutation.SetValue(v)
49 return _u
50 }
51
52 // SetNillableValue sets the "value" field if the given value is not nil.
53 func (_u *PayloadDigestUpdate) SetNillableValue(v *string) *PayloadDigestUpdate {
54 if v != nil {
55 _u.SetValue(*v)
56 }
57 return _u
58 }
59
60 // SetDsseID sets the "dsse" edge to the Dsse entity by ID.
61 func (_u *PayloadDigestUpdate) SetDsseID(id uuid.UUID) *PayloadDigestUpdate {
62 _u.mutation.SetDsseID(id)
63 return _u
64 }
65
66 // SetNillableDsseID sets the "dsse" edge to the Dsse entity by ID if the given value is not nil.
67 func (_u *PayloadDigestUpdate) SetNillableDsseID(id *uuid.UUID) *PayloadDigestUpdate {
68 if id != nil {
69 _u = _u.SetDsseID(*id)
70 }
71 return _u
72 }
73
74 // SetDsse sets the "dsse" edge to the Dsse entity.
75 func (_u *PayloadDigestUpdate) SetDsse(v *Dsse) *PayloadDigestUpdate {
76 return _u.SetDsseID(v.ID)
77 }
78
79 // Mutation returns the PayloadDigestMutation object of the builder.
80 func (_u *PayloadDigestUpdate) Mutation() *PayloadDigestMutation {
81 return _u.mutation
82 }
83
84 // ClearDsse clears the "dsse" edge to the Dsse entity.
85 func (_u *PayloadDigestUpdate) ClearDsse() *PayloadDigestUpdate {
86 _u.mutation.ClearDsse()
87 return _u
88 }
89
90 // Save executes the query and returns the number of nodes affected by the update operation.
91 func (_u *PayloadDigestUpdate) Save(ctx context.Context) (int, error) {
92 return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
93 }
94
95 // SaveX is like Save, but panics if an error occurs.
96 func (_u *PayloadDigestUpdate) SaveX(ctx context.Context) int {
97 affected, err := _u.Save(ctx)
98 if err != nil {
99 panic(err)
100 }
101 return affected
102 }
103
104 // Exec executes the query.
105 func (_u *PayloadDigestUpdate) Exec(ctx context.Context) error {
106 _, err := _u.Save(ctx)
107 return err
108 }
109
110 // ExecX is like Exec, but panics if an error occurs.
111 func (_u *PayloadDigestUpdate) ExecX(ctx context.Context) {
112 if err := _u.Exec(ctx); err != nil {
113 panic(err)
114 }
115 }
116
117 // check runs all checks and user-defined validators on the builder.
118 func (_u *PayloadDigestUpdate) check() error {
119 if v, ok := _u.mutation.Algorithm(); ok {
120 if err := payloaddigest.AlgorithmValidator(v); err != nil {
121 return &ValidationError{Name: "algorithm", err: fmt.Errorf(`ent: validator failed for field "PayloadDigest.algorithm": %w`, err)}
122 }
123 }
124 if v, ok := _u.mutation.Value(); ok {
125 if err := payloaddigest.ValueValidator(v); err != nil {
126 return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "PayloadDigest.value": %w`, err)}
127 }
128 }
129 return nil
130 }
131
132 func (_u *PayloadDigestUpdate) sqlSave(ctx context.Context) (_node int, err error) {
133 if err := _u.check(); err != nil {
134 return _node, err
135 }
136 _spec := sqlgraph.NewUpdateSpec(payloaddigest.Table, payloaddigest.Columns, sqlgraph.NewFieldSpec(payloaddigest.FieldID, field.TypeUUID))
137 if ps := _u.mutation.predicates; len(ps) > 0 {
138 _spec.Predicate = func(selector *sql.Selector) {
139 for i := range ps {
140 ps[i](selector)
141 }
142 }
143 }
144 if value, ok := _u.mutation.Algorithm(); ok {
145 _spec.SetField(payloaddigest.FieldAlgorithm, field.TypeString, value)
146 }
147 if value, ok := _u.mutation.Value(); ok {
148 _spec.SetField(payloaddigest.FieldValue, field.TypeString, value)
149 }
150 if _u.mutation.DsseCleared() {
151 edge := &sqlgraph.EdgeSpec{
152 Rel: sqlgraph.M2O,
153 Inverse: true,
154 Table: payloaddigest.DsseTable,
155 Columns: []string{payloaddigest.DsseColumn},
156 Bidi: false,
157 Target: &sqlgraph.EdgeTarget{
158 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
159 },
160 }
161 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
162 }
163 if nodes := _u.mutation.DsseIDs(); len(nodes) > 0 {
164 edge := &sqlgraph.EdgeSpec{
165 Rel: sqlgraph.M2O,
166 Inverse: true,
167 Table: payloaddigest.DsseTable,
168 Columns: []string{payloaddigest.DsseColumn},
169 Bidi: false,
170 Target: &sqlgraph.EdgeTarget{
171 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
172 },
173 }
174 for _, k := range nodes {
175 edge.Target.Nodes = append(edge.Target.Nodes, k)
176 }
177 _spec.Edges.Add = append(_spec.Edges.Add, edge)
178 }
179 if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
180 if _, ok := err.(*sqlgraph.NotFoundError); ok {
181 err = &NotFoundError{payloaddigest.Label}
182 } else if sqlgraph.IsConstraintError(err) {
183 err = &ConstraintError{msg: err.Error(), wrap: err}
184 }
185 return 0, err
186 }
187 _u.mutation.done = true
188 return _node, nil
189 }
190
191 // PayloadDigestUpdateOne is the builder for updating a single PayloadDigest entity.
192 type PayloadDigestUpdateOne struct {
193 config
194 fields []string
195 hooks []Hook
196 mutation *PayloadDigestMutation
197 }
198
199 // SetAlgorithm sets the "algorithm" field.
200 func (_u *PayloadDigestUpdateOne) SetAlgorithm(v string) *PayloadDigestUpdateOne {
201 _u.mutation.SetAlgorithm(v)
202 return _u
203 }
204
205 // SetNillableAlgorithm sets the "algorithm" field if the given value is not nil.
206 func (_u *PayloadDigestUpdateOne) SetNillableAlgorithm(v *string) *PayloadDigestUpdateOne {
207 if v != nil {
208 _u.SetAlgorithm(*v)
209 }
210 return _u
211 }
212
213 // SetValue sets the "value" field.
214 func (_u *PayloadDigestUpdateOne) SetValue(v string) *PayloadDigestUpdateOne {
215 _u.mutation.SetValue(v)
216 return _u
217 }
218
219 // SetNillableValue sets the "value" field if the given value is not nil.
220 func (_u *PayloadDigestUpdateOne) SetNillableValue(v *string) *PayloadDigestUpdateOne {
221 if v != nil {
222 _u.SetValue(*v)
223 }
224 return _u
225 }
226
227 // SetDsseID sets the "dsse" edge to the Dsse entity by ID.
228 func (_u *PayloadDigestUpdateOne) SetDsseID(id uuid.UUID) *PayloadDigestUpdateOne {
229 _u.mutation.SetDsseID(id)
230 return _u
231 }
232
233 // SetNillableDsseID sets the "dsse" edge to the Dsse entity by ID if the given value is not nil.
234 func (_u *PayloadDigestUpdateOne) SetNillableDsseID(id *uuid.UUID) *PayloadDigestUpdateOne {
235 if id != nil {
236 _u = _u.SetDsseID(*id)
237 }
238 return _u
239 }
240
241 // SetDsse sets the "dsse" edge to the Dsse entity.
242 func (_u *PayloadDigestUpdateOne) SetDsse(v *Dsse) *PayloadDigestUpdateOne {
243 return _u.SetDsseID(v.ID)
244 }
245
246 // Mutation returns the PayloadDigestMutation object of the builder.
247 func (_u *PayloadDigestUpdateOne) Mutation() *PayloadDigestMutation {
248 return _u.mutation
249 }
250
251 // ClearDsse clears the "dsse" edge to the Dsse entity.
252 func (_u *PayloadDigestUpdateOne) ClearDsse() *PayloadDigestUpdateOne {
253 _u.mutation.ClearDsse()
254 return _u
255 }
256
257 // Where appends a list predicates to the PayloadDigestUpdate builder.
258 func (_u *PayloadDigestUpdateOne) Where(ps ...predicate.PayloadDigest) *PayloadDigestUpdateOne {
259 _u.mutation.Where(ps...)
260 return _u
261 }
262
263 // Select allows selecting one or more fields (columns) of the returned entity.
264 // The default is selecting all fields defined in the entity schema.
265 func (_u *PayloadDigestUpdateOne) Select(field string, fields ...string) *PayloadDigestUpdateOne {
266 _u.fields = append([]string{field}, fields...)
267 return _u
268 }
269
270 // Save executes the query and returns the updated PayloadDigest entity.
271 func (_u *PayloadDigestUpdateOne) Save(ctx context.Context) (*PayloadDigest, error) {
272 return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
273 }
274
275 // SaveX is like Save, but panics if an error occurs.
276 func (_u *PayloadDigestUpdateOne) SaveX(ctx context.Context) *PayloadDigest {
277 node, err := _u.Save(ctx)
278 if err != nil {
279 panic(err)
280 }
281 return node
282 }
283
284 // Exec executes the query on the entity.
285 func (_u *PayloadDigestUpdateOne) Exec(ctx context.Context) error {
286 _, err := _u.Save(ctx)
287 return err
288 }
289
290 // ExecX is like Exec, but panics if an error occurs.
291 func (_u *PayloadDigestUpdateOne) ExecX(ctx context.Context) {
292 if err := _u.Exec(ctx); err != nil {
293 panic(err)
294 }
295 }
296
297 // check runs all checks and user-defined validators on the builder.
298 func (_u *PayloadDigestUpdateOne) check() error {
299 if v, ok := _u.mutation.Algorithm(); ok {
300 if err := payloaddigest.AlgorithmValidator(v); err != nil {
301 return &ValidationError{Name: "algorithm", err: fmt.Errorf(`ent: validator failed for field "PayloadDigest.algorithm": %w`, err)}
302 }
303 }
304 if v, ok := _u.mutation.Value(); ok {
305 if err := payloaddigest.ValueValidator(v); err != nil {
306 return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "PayloadDigest.value": %w`, err)}
307 }
308 }
309 return nil
310 }
311
312 func (_u *PayloadDigestUpdateOne) sqlSave(ctx context.Context) (_node *PayloadDigest, err error) {
313 if err := _u.check(); err != nil {
314 return _node, err
315 }
316 _spec := sqlgraph.NewUpdateSpec(payloaddigest.Table, payloaddigest.Columns, sqlgraph.NewFieldSpec(payloaddigest.FieldID, field.TypeUUID))
317 id, ok := _u.mutation.ID()
318 if !ok {
319 return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PayloadDigest.id" for update`)}
320 }
321 _spec.Node.ID.Value = id
322 if fields := _u.fields; len(fields) > 0 {
323 _spec.Node.Columns = make([]string, 0, len(fields))
324 _spec.Node.Columns = append(_spec.Node.Columns, payloaddigest.FieldID)
325 for _, f := range fields {
326 if !payloaddigest.ValidColumn(f) {
327 return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
328 }
329 if f != payloaddigest.FieldID {
330 _spec.Node.Columns = append(_spec.Node.Columns, f)
331 }
332 }
333 }
334 if ps := _u.mutation.predicates; len(ps) > 0 {
335 _spec.Predicate = func(selector *sql.Selector) {
336 for i := range ps {
337 ps[i](selector)
338 }
339 }
340 }
341 if value, ok := _u.mutation.Algorithm(); ok {
342 _spec.SetField(payloaddigest.FieldAlgorithm, field.TypeString, value)
343 }
344 if value, ok := _u.mutation.Value(); ok {
345 _spec.SetField(payloaddigest.FieldValue, field.TypeString, value)
346 }
347 if _u.mutation.DsseCleared() {
348 edge := &sqlgraph.EdgeSpec{
349 Rel: sqlgraph.M2O,
350 Inverse: true,
351 Table: payloaddigest.DsseTable,
352 Columns: []string{payloaddigest.DsseColumn},
353 Bidi: false,
354 Target: &sqlgraph.EdgeTarget{
355 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
356 },
357 }
358 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
359 }
360 if nodes := _u.mutation.DsseIDs(); len(nodes) > 0 {
361 edge := &sqlgraph.EdgeSpec{
362 Rel: sqlgraph.M2O,
363 Inverse: true,
364 Table: payloaddigest.DsseTable,
365 Columns: []string{payloaddigest.DsseColumn},
366 Bidi: false,
367 Target: &sqlgraph.EdgeTarget{
368 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
369 },
370 }
371 for _, k := range nodes {
372 edge.Target.Nodes = append(edge.Target.Nodes, k)
373 }
374 _spec.Edges.Add = append(_spec.Edges.Add, edge)
375 }
376 _node = &PayloadDigest{config: _u.config}
377 _spec.Assign = _node.assignValues
378 _spec.ScanValues = _node.scanValues
379 if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
380 if _, ok := err.(*sqlgraph.NotFoundError); ok {
381 err = &NotFoundError{payloaddigest.Label}
382 } else if sqlgraph.IsConstraintError(err) {
383 err = &ConstraintError{msg: err.Error(), wrap: err}
384 }
385 return nil, err
386 }
387 _u.mutation.done = true
388 return _node, nil
389 }