Debian Codegraph @

ent/statement_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/attestationcollection"
15 "github.com/in-toto/archivista/ent/attestationpolicy"
16 "github.com/in-toto/archivista/ent/dsse"
17 "github.com/in-toto/archivista/ent/predicate"
18 "github.com/in-toto/archivista/ent/statement"
19 "github.com/in-toto/archivista/ent/subject"
20 )
21
22 // StatementUpdate is the builder for updating Statement entities.
23 type StatementUpdate struct {
24 config
25 hooks []Hook
26 mutation *StatementMutation
27 }
28
29 // Where appends a list predicates to the StatementUpdate builder.
30 func (_u *StatementUpdate) Where(ps ...predicate.Statement) *StatementUpdate {
31 _u.mutation.Where(ps...)
32 return _u
33 }
34
35 // SetPredicate sets the "predicate" field.
36 func (_u *StatementUpdate) SetPredicate(v string) *StatementUpdate {
37 _u.mutation.SetPredicate(v)
38 return _u
39 }
40
41 // SetNillablePredicate sets the "predicate" field if the given value is not nil.
42 func (_u *StatementUpdate) SetNillablePredicate(v *string) *StatementUpdate {
43 if v != nil {
44 _u.SetPredicate(*v)
45 }
46 return _u
47 }
48
49 // AddSubjectIDs adds the "subjects" edge to the Subject entity by IDs.
50 func (_u *StatementUpdate) AddSubjectIDs(ids ...uuid.UUID) *StatementUpdate {
51 _u.mutation.AddSubjectIDs(ids...)
52 return _u
53 }
54
55 // AddSubjects adds the "subjects" edges to the Subject entity.
56 func (_u *StatementUpdate) AddSubjects(v ...*Subject) *StatementUpdate {
57 ids := make([]uuid.UUID, len(v))
58 for i := range v {
59 ids[i] = v[i].ID
60 }
61 return _u.AddSubjectIDs(ids...)
62 }
63
64 // SetPolicyID sets the "policy" edge to the AttestationPolicy entity by ID.
65 func (_u *StatementUpdate) SetPolicyID(id uuid.UUID) *StatementUpdate {
66 _u.mutation.SetPolicyID(id)
67 return _u
68 }
69
70 // SetNillablePolicyID sets the "policy" edge to the AttestationPolicy entity by ID if the given value is not nil.
71 func (_u *StatementUpdate) SetNillablePolicyID(id *uuid.UUID) *StatementUpdate {
72 if id != nil {
73 _u = _u.SetPolicyID(*id)
74 }
75 return _u
76 }
77
78 // SetPolicy sets the "policy" edge to the AttestationPolicy entity.
79 func (_u *StatementUpdate) SetPolicy(v *AttestationPolicy) *StatementUpdate {
80 return _u.SetPolicyID(v.ID)
81 }
82
83 // SetAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by ID.
84 func (_u *StatementUpdate) SetAttestationCollectionsID(id uuid.UUID) *StatementUpdate {
85 _u.mutation.SetAttestationCollectionsID(id)
86 return _u
87 }
88
89 // SetNillableAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by ID if the given value is not nil.
90 func (_u *StatementUpdate) SetNillableAttestationCollectionsID(id *uuid.UUID) *StatementUpdate {
91 if id != nil {
92 _u = _u.SetAttestationCollectionsID(*id)
93 }
94 return _u
95 }
96
97 // SetAttestationCollections sets the "attestation_collections" edge to the AttestationCollection entity.
98 func (_u *StatementUpdate) SetAttestationCollections(v *AttestationCollection) *StatementUpdate {
99 return _u.SetAttestationCollectionsID(v.ID)
100 }
101
102 // AddDsseIDs adds the "dsse" edge to the Dsse entity by IDs.
103 func (_u *StatementUpdate) AddDsseIDs(ids ...uuid.UUID) *StatementUpdate {
104 _u.mutation.AddDsseIDs(ids...)
105 return _u
106 }
107
108 // AddDsse adds the "dsse" edges to the Dsse entity.
109 func (_u *StatementUpdate) AddDsse(v ...*Dsse) *StatementUpdate {
110 ids := make([]uuid.UUID, len(v))
111 for i := range v {
112 ids[i] = v[i].ID
113 }
114 return _u.AddDsseIDs(ids...)
115 }
116
117 // Mutation returns the StatementMutation object of the builder.
118 func (_u *StatementUpdate) Mutation() *StatementMutation {
119 return _u.mutation
120 }
121
122 // ClearSubjects clears all "subjects" edges to the Subject entity.
123 func (_u *StatementUpdate) ClearSubjects() *StatementUpdate {
124 _u.mutation.ClearSubjects()
125 return _u
126 }
127
128 // RemoveSubjectIDs removes the "subjects" edge to Subject entities by IDs.
129 func (_u *StatementUpdate) RemoveSubjectIDs(ids ...uuid.UUID) *StatementUpdate {
130 _u.mutation.RemoveSubjectIDs(ids...)
131 return _u
132 }
133
134 // RemoveSubjects removes "subjects" edges to Subject entities.
135 func (_u *StatementUpdate) RemoveSubjects(v ...*Subject) *StatementUpdate {
136 ids := make([]uuid.UUID, len(v))
137 for i := range v {
138 ids[i] = v[i].ID
139 }
140 return _u.RemoveSubjectIDs(ids...)
141 }
142
143 // ClearPolicy clears the "policy" edge to the AttestationPolicy entity.
144 func (_u *StatementUpdate) ClearPolicy() *StatementUpdate {
145 _u.mutation.ClearPolicy()
146 return _u
147 }
148
149 // ClearAttestationCollections clears the "attestation_collections" edge to the AttestationCollection entity.
150 func (_u *StatementUpdate) ClearAttestationCollections() *StatementUpdate {
151 _u.mutation.ClearAttestationCollections()
152 return _u
153 }
154
155 // ClearDsse clears all "dsse" edges to the Dsse entity.
156 func (_u *StatementUpdate) ClearDsse() *StatementUpdate {
157 _u.mutation.ClearDsse()
158 return _u
159 }
160
161 // RemoveDsseIDs removes the "dsse" edge to Dsse entities by IDs.
162 func (_u *StatementUpdate) RemoveDsseIDs(ids ...uuid.UUID) *StatementUpdate {
163 _u.mutation.RemoveDsseIDs(ids...)
164 return _u
165 }
166
167 // RemoveDsse removes "dsse" edges to Dsse entities.
168 func (_u *StatementUpdate) RemoveDsse(v ...*Dsse) *StatementUpdate {
169 ids := make([]uuid.UUID, len(v))
170 for i := range v {
171 ids[i] = v[i].ID
172 }
173 return _u.RemoveDsseIDs(ids...)
174 }
175
176 // Save executes the query and returns the number of nodes affected by the update operation.
177 func (_u *StatementUpdate) Save(ctx context.Context) (int, error) {
178 return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
179 }
180
181 // SaveX is like Save, but panics if an error occurs.
182 func (_u *StatementUpdate) SaveX(ctx context.Context) int {
183 affected, err := _u.Save(ctx)
184 if err != nil {
185 panic(err)
186 }
187 return affected
188 }
189
190 // Exec executes the query.
191 func (_u *StatementUpdate) Exec(ctx context.Context) error {
192 _, err := _u.Save(ctx)
193 return err
194 }
195
196 // ExecX is like Exec, but panics if an error occurs.
197 func (_u *StatementUpdate) ExecX(ctx context.Context) {
198 if err := _u.Exec(ctx); err != nil {
199 panic(err)
200 }
201 }
202
203 // check runs all checks and user-defined validators on the builder.
204 func (_u *StatementUpdate) check() error {
205 if v, ok := _u.mutation.Predicate(); ok {
206 if err := statement.PredicateValidator(v); err != nil {
207 return &ValidationError{Name: "predicate", err: fmt.Errorf(`ent: validator failed for field "Statement.predicate": %w`, err)}
208 }
209 }
210 return nil
211 }
212
213 func (_u *StatementUpdate) sqlSave(ctx context.Context) (_node int, err error) {
214 if err := _u.check(); err != nil {
215 return _node, err
216 }
217 _spec := sqlgraph.NewUpdateSpec(statement.Table, statement.Columns, sqlgraph.NewFieldSpec(statement.FieldID, field.TypeUUID))
218 if ps := _u.mutation.predicates; len(ps) > 0 {
219 _spec.Predicate = func(selector *sql.Selector) {
220 for i := range ps {
221 ps[i](selector)
222 }
223 }
224 }
225 if value, ok := _u.mutation.Predicate(); ok {
226 _spec.SetField(statement.FieldPredicate, field.TypeString, value)
227 }
228 if _u.mutation.SubjectsCleared() {
229 edge := &sqlgraph.EdgeSpec{
230 Rel: sqlgraph.O2M,
231 Inverse: false,
232 Table: statement.SubjectsTable,
233 Columns: []string{statement.SubjectsColumn},
234 Bidi: false,
235 Target: &sqlgraph.EdgeTarget{
236 IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
237 },
238 }
239 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
240 }
241 if nodes := _u.mutation.RemovedSubjectsIDs(); len(nodes) > 0 && !_u.mutation.SubjectsCleared() {
242 edge := &sqlgraph.EdgeSpec{
243 Rel: sqlgraph.O2M,
244 Inverse: false,
245 Table: statement.SubjectsTable,
246 Columns: []string{statement.SubjectsColumn},
247 Bidi: false,
248 Target: &sqlgraph.EdgeTarget{
249 IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
250 },
251 }
252 for _, k := range nodes {
253 edge.Target.Nodes = append(edge.Target.Nodes, k)
254 }
255 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
256 }
257 if nodes := _u.mutation.SubjectsIDs(); len(nodes) > 0 {
258 edge := &sqlgraph.EdgeSpec{
259 Rel: sqlgraph.O2M,
260 Inverse: false,
261 Table: statement.SubjectsTable,
262 Columns: []string{statement.SubjectsColumn},
263 Bidi: false,
264 Target: &sqlgraph.EdgeTarget{
265 IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
266 },
267 }
268 for _, k := range nodes {
269 edge.Target.Nodes = append(edge.Target.Nodes, k)
270 }
271 _spec.Edges.Add = append(_spec.Edges.Add, edge)
272 }
273 if _u.mutation.PolicyCleared() {
274 edge := &sqlgraph.EdgeSpec{
275 Rel: sqlgraph.O2O,
276 Inverse: false,
277 Table: statement.PolicyTable,
278 Columns: []string{statement.PolicyColumn},
279 Bidi: false,
280 Target: &sqlgraph.EdgeTarget{
281 IDSpec: sqlgraph.NewFieldSpec(attestationpolicy.FieldID, field.TypeUUID),
282 },
283 }
284 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
285 }
286 if nodes := _u.mutation.PolicyIDs(); len(nodes) > 0 {
287 edge := &sqlgraph.EdgeSpec{
288 Rel: sqlgraph.O2O,
289 Inverse: false,
290 Table: statement.PolicyTable,
291 Columns: []string{statement.PolicyColumn},
292 Bidi: false,
293 Target: &sqlgraph.EdgeTarget{
294 IDSpec: sqlgraph.NewFieldSpec(attestationpolicy.FieldID, field.TypeUUID),
295 },
296 }
297 for _, k := range nodes {
298 edge.Target.Nodes = append(edge.Target.Nodes, k)
299 }
300 _spec.Edges.Add = append(_spec.Edges.Add, edge)
301 }
302 if _u.mutation.AttestationCollectionsCleared() {
303 edge := &sqlgraph.EdgeSpec{
304 Rel: sqlgraph.O2O,
305 Inverse: false,
306 Table: statement.AttestationCollectionsTable,
307 Columns: []string{statement.AttestationCollectionsColumn},
308 Bidi: false,
309 Target: &sqlgraph.EdgeTarget{
310 IDSpec: sqlgraph.NewFieldSpec(attestationcollection.FieldID, field.TypeUUID),
311 },
312 }
313 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
314 }
315 if nodes := _u.mutation.AttestationCollectionsIDs(); len(nodes) > 0 {
316 edge := &sqlgraph.EdgeSpec{
317 Rel: sqlgraph.O2O,
318 Inverse: false,
319 Table: statement.AttestationCollectionsTable,
320 Columns: []string{statement.AttestationCollectionsColumn},
321 Bidi: false,
322 Target: &sqlgraph.EdgeTarget{
323 IDSpec: sqlgraph.NewFieldSpec(attestationcollection.FieldID, field.TypeUUID),
324 },
325 }
326 for _, k := range nodes {
327 edge.Target.Nodes = append(edge.Target.Nodes, k)
328 }
329 _spec.Edges.Add = append(_spec.Edges.Add, edge)
330 }
331 if _u.mutation.DsseCleared() {
332 edge := &sqlgraph.EdgeSpec{
333 Rel: sqlgraph.O2M,
334 Inverse: true,
335 Table: statement.DsseTable,
336 Columns: []string{statement.DsseColumn},
337 Bidi: false,
338 Target: &sqlgraph.EdgeTarget{
339 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
340 },
341 }
342 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
343 }
344 if nodes := _u.mutation.RemovedDsseIDs(); len(nodes) > 0 && !_u.mutation.DsseCleared() {
345 edge := &sqlgraph.EdgeSpec{
346 Rel: sqlgraph.O2M,
347 Inverse: true,
348 Table: statement.DsseTable,
349 Columns: []string{statement.DsseColumn},
350 Bidi: false,
351 Target: &sqlgraph.EdgeTarget{
352 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
353 },
354 }
355 for _, k := range nodes {
356 edge.Target.Nodes = append(edge.Target.Nodes, k)
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.O2M,
363 Inverse: true,
364 Table: statement.DsseTable,
365 Columns: []string{statement.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 if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
377 if _, ok := err.(*sqlgraph.NotFoundError); ok {
378 err = &NotFoundError{statement.Label}
379 } else if sqlgraph.IsConstraintError(err) {
380 err = &ConstraintError{msg: err.Error(), wrap: err}
381 }
382 return 0, err
383 }
384 _u.mutation.done = true
385 return _node, nil
386 }
387
388 // StatementUpdateOne is the builder for updating a single Statement entity.
389 type StatementUpdateOne struct {
390 config
391 fields []string
392 hooks []Hook
393 mutation *StatementMutation
394 }
395
396 // SetPredicate sets the "predicate" field.
397 func (_u *StatementUpdateOne) SetPredicate(v string) *StatementUpdateOne {
398 _u.mutation.SetPredicate(v)
399 return _u
400 }
401
402 // SetNillablePredicate sets the "predicate" field if the given value is not nil.
403 func (_u *StatementUpdateOne) SetNillablePredicate(v *string) *StatementUpdateOne {
404 if v != nil {
405 _u.SetPredicate(*v)
406 }
407 return _u
408 }
409
410 // AddSubjectIDs adds the "subjects" edge to the Subject entity by IDs.
411 func (_u *StatementUpdateOne) AddSubjectIDs(ids ...uuid.UUID) *StatementUpdateOne {
412 _u.mutation.AddSubjectIDs(ids...)
413 return _u
414 }
415
416 // AddSubjects adds the "subjects" edges to the Subject entity.
417 func (_u *StatementUpdateOne) AddSubjects(v ...*Subject) *StatementUpdateOne {
418 ids := make([]uuid.UUID, len(v))
419 for i := range v {
420 ids[i] = v[i].ID
421 }
422 return _u.AddSubjectIDs(ids...)
423 }
424
425 // SetPolicyID sets the "policy" edge to the AttestationPolicy entity by ID.
426 func (_u *StatementUpdateOne) SetPolicyID(id uuid.UUID) *StatementUpdateOne {
427 _u.mutation.SetPolicyID(id)
428 return _u
429 }
430
431 // SetNillablePolicyID sets the "policy" edge to the AttestationPolicy entity by ID if the given value is not nil.
432 func (_u *StatementUpdateOne) SetNillablePolicyID(id *uuid.UUID) *StatementUpdateOne {
433 if id != nil {
434 _u = _u.SetPolicyID(*id)
435 }
436 return _u
437 }
438
439 // SetPolicy sets the "policy" edge to the AttestationPolicy entity.
440 func (_u *StatementUpdateOne) SetPolicy(v *AttestationPolicy) *StatementUpdateOne {
441 return _u.SetPolicyID(v.ID)
442 }
443
444 // SetAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by ID.
445 func (_u *StatementUpdateOne) SetAttestationCollectionsID(id uuid.UUID) *StatementUpdateOne {
446 _u.mutation.SetAttestationCollectionsID(id)
447 return _u
448 }
449
450 // SetNillableAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by ID if the given value is not nil.
451 func (_u *StatementUpdateOne) SetNillableAttestationCollectionsID(id *uuid.UUID) *StatementUpdateOne {
452 if id != nil {
453 _u = _u.SetAttestationCollectionsID(*id)
454 }
455 return _u
456 }
457
458 // SetAttestationCollections sets the "attestation_collections" edge to the AttestationCollection entity.
459 func (_u *StatementUpdateOne) SetAttestationCollections(v *AttestationCollection) *StatementUpdateOne {
460 return _u.SetAttestationCollectionsID(v.ID)
461 }
462
463 // AddDsseIDs adds the "dsse" edge to the Dsse entity by IDs.
464 func (_u *StatementUpdateOne) AddDsseIDs(ids ...uuid.UUID) *StatementUpdateOne {
465 _u.mutation.AddDsseIDs(ids...)
466 return _u
467 }
468
469 // AddDsse adds the "dsse" edges to the Dsse entity.
470 func (_u *StatementUpdateOne) AddDsse(v ...*Dsse) *StatementUpdateOne {
471 ids := make([]uuid.UUID, len(v))
472 for i := range v {
473 ids[i] = v[i].ID
474 }
475 return _u.AddDsseIDs(ids...)
476 }
477
478 // Mutation returns the StatementMutation object of the builder.
479 func (_u *StatementUpdateOne) Mutation() *StatementMutation {
480 return _u.mutation
481 }
482
483 // ClearSubjects clears all "subjects" edges to the Subject entity.
484 func (_u *StatementUpdateOne) ClearSubjects() *StatementUpdateOne {
485 _u.mutation.ClearSubjects()
486 return _u
487 }
488
489 // RemoveSubjectIDs removes the "subjects" edge to Subject entities by IDs.
490 func (_u *StatementUpdateOne) RemoveSubjectIDs(ids ...uuid.UUID) *StatementUpdateOne {
491 _u.mutation.RemoveSubjectIDs(ids...)
492 return _u
493 }
494
495 // RemoveSubjects removes "subjects" edges to Subject entities.
496 func (_u *StatementUpdateOne) RemoveSubjects(v ...*Subject) *StatementUpdateOne {
497 ids := make([]uuid.UUID, len(v))
498 for i := range v {
499 ids[i] = v[i].ID
500 }
501 return _u.RemoveSubjectIDs(ids...)
502 }
503
504 // ClearPolicy clears the "policy" edge to the AttestationPolicy entity.
505 func (_u *StatementUpdateOne) ClearPolicy() *StatementUpdateOne {
506 _u.mutation.ClearPolicy()
507 return _u
508 }
509
510 // ClearAttestationCollections clears the "attestation_collections" edge to the AttestationCollection entity.
511 func (_u *StatementUpdateOne) ClearAttestationCollections() *StatementUpdateOne {
512 _u.mutation.ClearAttestationCollections()
513 return _u
514 }
515
516 // ClearDsse clears all "dsse" edges to the Dsse entity.
517 func (_u *StatementUpdateOne) ClearDsse() *StatementUpdateOne {
518 _u.mutation.ClearDsse()
519 return _u
520 }
521
522 // RemoveDsseIDs removes the "dsse" edge to Dsse entities by IDs.
523 func (_u *StatementUpdateOne) RemoveDsseIDs(ids ...uuid.UUID) *StatementUpdateOne {
524 _u.mutation.RemoveDsseIDs(ids...)
525 return _u
526 }
527
528 // RemoveDsse removes "dsse" edges to Dsse entities.
529 func (_u *StatementUpdateOne) RemoveDsse(v ...*Dsse) *StatementUpdateOne {
530 ids := make([]uuid.UUID, len(v))
531 for i := range v {
532 ids[i] = v[i].ID
533 }
534 return _u.RemoveDsseIDs(ids...)
535 }
536
537 // Where appends a list predicates to the StatementUpdate builder.
538 func (_u *StatementUpdateOne) Where(ps ...predicate.Statement) *StatementUpdateOne {
539 _u.mutation.Where(ps...)
540 return _u
541 }
542
543 // Select allows selecting one or more fields (columns) of the returned entity.
544 // The default is selecting all fields defined in the entity schema.
545 func (_u *StatementUpdateOne) Select(field string, fields ...string) *StatementUpdateOne {
546 _u.fields = append([]string{field}, fields...)
547 return _u
548 }
549
550 // Save executes the query and returns the updated Statement entity.
551 func (_u *StatementUpdateOne) Save(ctx context.Context) (*Statement, error) {
552 return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
553 }
554
555 // SaveX is like Save, but panics if an error occurs.
556 func (_u *StatementUpdateOne) SaveX(ctx context.Context) *Statement {
557 node, err := _u.Save(ctx)
558 if err != nil {
559 panic(err)
560 }
561 return node
562 }
563
564 // Exec executes the query on the entity.
565 func (_u *StatementUpdateOne) Exec(ctx context.Context) error {
566 _, err := _u.Save(ctx)
567 return err
568 }
569
570 // ExecX is like Exec, but panics if an error occurs.
571 func (_u *StatementUpdateOne) ExecX(ctx context.Context) {
572 if err := _u.Exec(ctx); err != nil {
573 panic(err)
574 }
575 }
576
577 // check runs all checks and user-defined validators on the builder.
578 func (_u *StatementUpdateOne) check() error {
579 if v, ok := _u.mutation.Predicate(); ok {
580 if err := statement.PredicateValidator(v); err != nil {
581 return &ValidationError{Name: "predicate", err: fmt.Errorf(`ent: validator failed for field "Statement.predicate": %w`, err)}
582 }
583 }
584 return nil
585 }
586
587 func (_u *StatementUpdateOne) sqlSave(ctx context.Context) (_node *Statement, err error) {
588 if err := _u.check(); err != nil {
589 return _node, err
590 }
591 _spec := sqlgraph.NewUpdateSpec(statement.Table, statement.Columns, sqlgraph.NewFieldSpec(statement.FieldID, field.TypeUUID))
592 id, ok := _u.mutation.ID()
593 if !ok {
594 return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Statement.id" for update`)}
595 }
596 _spec.Node.ID.Value = id
597 if fields := _u.fields; len(fields) > 0 {
598 _spec.Node.Columns = make([]string, 0, len(fields))
599 _spec.Node.Columns = append(_spec.Node.Columns, statement.FieldID)
600 for _, f := range fields {
601 if !statement.ValidColumn(f) {
602 return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
603 }
604 if f != statement.FieldID {
605 _spec.Node.Columns = append(_spec.Node.Columns, f)
606 }
607 }
608 }
609 if ps := _u.mutation.predicates; len(ps) > 0 {
610 _spec.Predicate = func(selector *sql.Selector) {
611 for i := range ps {
612 ps[i](selector)
613 }
614 }
615 }
616 if value, ok := _u.mutation.Predicate(); ok {
617 _spec.SetField(statement.FieldPredicate, field.TypeString, value)
618 }
619 if _u.mutation.SubjectsCleared() {
620 edge := &sqlgraph.EdgeSpec{
621 Rel: sqlgraph.O2M,
622 Inverse: false,
623 Table: statement.SubjectsTable,
624 Columns: []string{statement.SubjectsColumn},
625 Bidi: false,
626 Target: &sqlgraph.EdgeTarget{
627 IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
628 },
629 }
630 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
631 }
632 if nodes := _u.mutation.RemovedSubjectsIDs(); len(nodes) > 0 && !_u.mutation.SubjectsCleared() {
633 edge := &sqlgraph.EdgeSpec{
634 Rel: sqlgraph.O2M,
635 Inverse: false,
636 Table: statement.SubjectsTable,
637 Columns: []string{statement.SubjectsColumn},
638 Bidi: false,
639 Target: &sqlgraph.EdgeTarget{
640 IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
641 },
642 }
643 for _, k := range nodes {
644 edge.Target.Nodes = append(edge.Target.Nodes, k)
645 }
646 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
647 }
648 if nodes := _u.mutation.SubjectsIDs(); len(nodes) > 0 {
649 edge := &sqlgraph.EdgeSpec{
650 Rel: sqlgraph.O2M,
651 Inverse: false,
652 Table: statement.SubjectsTable,
653 Columns: []string{statement.SubjectsColumn},
654 Bidi: false,
655 Target: &sqlgraph.EdgeTarget{
656 IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID),
657 },
658 }
659 for _, k := range nodes {
660 edge.Target.Nodes = append(edge.Target.Nodes, k)
661 }
662 _spec.Edges.Add = append(_spec.Edges.Add, edge)
663 }
664 if _u.mutation.PolicyCleared() {
665 edge := &sqlgraph.EdgeSpec{
666 Rel: sqlgraph.O2O,
667 Inverse: false,
668 Table: statement.PolicyTable,
669 Columns: []string{statement.PolicyColumn},
670 Bidi: false,
671 Target: &sqlgraph.EdgeTarget{
672 IDSpec: sqlgraph.NewFieldSpec(attestationpolicy.FieldID, field.TypeUUID),
673 },
674 }
675 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
676 }
677 if nodes := _u.mutation.PolicyIDs(); len(nodes) > 0 {
678 edge := &sqlgraph.EdgeSpec{
679 Rel: sqlgraph.O2O,
680 Inverse: false,
681 Table: statement.PolicyTable,
682 Columns: []string{statement.PolicyColumn},
683 Bidi: false,
684 Target: &sqlgraph.EdgeTarget{
685 IDSpec: sqlgraph.NewFieldSpec(attestationpolicy.FieldID, field.TypeUUID),
686 },
687 }
688 for _, k := range nodes {
689 edge.Target.Nodes = append(edge.Target.Nodes, k)
690 }
691 _spec.Edges.Add = append(_spec.Edges.Add, edge)
692 }
693 if _u.mutation.AttestationCollectionsCleared() {
694 edge := &sqlgraph.EdgeSpec{
695 Rel: sqlgraph.O2O,
696 Inverse: false,
697 Table: statement.AttestationCollectionsTable,
698 Columns: []string{statement.AttestationCollectionsColumn},
699 Bidi: false,
700 Target: &sqlgraph.EdgeTarget{
701 IDSpec: sqlgraph.NewFieldSpec(attestationcollection.FieldID, field.TypeUUID),
702 },
703 }
704 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
705 }
706 if nodes := _u.mutation.AttestationCollectionsIDs(); len(nodes) > 0 {
707 edge := &sqlgraph.EdgeSpec{
708 Rel: sqlgraph.O2O,
709 Inverse: false,
710 Table: statement.AttestationCollectionsTable,
711 Columns: []string{statement.AttestationCollectionsColumn},
712 Bidi: false,
713 Target: &sqlgraph.EdgeTarget{
714 IDSpec: sqlgraph.NewFieldSpec(attestationcollection.FieldID, field.TypeUUID),
715 },
716 }
717 for _, k := range nodes {
718 edge.Target.Nodes = append(edge.Target.Nodes, k)
719 }
720 _spec.Edges.Add = append(_spec.Edges.Add, edge)
721 }
722 if _u.mutation.DsseCleared() {
723 edge := &sqlgraph.EdgeSpec{
724 Rel: sqlgraph.O2M,
725 Inverse: true,
726 Table: statement.DsseTable,
727 Columns: []string{statement.DsseColumn},
728 Bidi: false,
729 Target: &sqlgraph.EdgeTarget{
730 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
731 },
732 }
733 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
734 }
735 if nodes := _u.mutation.RemovedDsseIDs(); len(nodes) > 0 && !_u.mutation.DsseCleared() {
736 edge := &sqlgraph.EdgeSpec{
737 Rel: sqlgraph.O2M,
738 Inverse: true,
739 Table: statement.DsseTable,
740 Columns: []string{statement.DsseColumn},
741 Bidi: false,
742 Target: &sqlgraph.EdgeTarget{
743 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
744 },
745 }
746 for _, k := range nodes {
747 edge.Target.Nodes = append(edge.Target.Nodes, k)
748 }
749 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
750 }
751 if nodes := _u.mutation.DsseIDs(); len(nodes) > 0 {
752 edge := &sqlgraph.EdgeSpec{
753 Rel: sqlgraph.O2M,
754 Inverse: true,
755 Table: statement.DsseTable,
756 Columns: []string{statement.DsseColumn},
757 Bidi: false,
758 Target: &sqlgraph.EdgeTarget{
759 IDSpec: sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID),
760 },
761 }
762 for _, k := range nodes {
763 edge.Target.Nodes = append(edge.Target.Nodes, k)
764 }
765 _spec.Edges.Add = append(_spec.Edges.Add, edge)
766 }
767 _node = &Statement{config: _u.config}
768 _spec.Assign = _node.assignValues
769 _spec.ScanValues = _node.scanValues
770 if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
771 if _, ok := err.(*sqlgraph.NotFoundError); ok {
772 err = &NotFoundError{statement.Label}
773 } else if sqlgraph.IsConstraintError(err) {
774 err = &ConstraintError{msg: err.Error(), wrap: err}
775 }
776 return nil, err
777 }
778 _u.mutation.done = true
779 return _node, nil
780 }