| 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/predicate" |
| 15 |
"github.com/in-toto/archivista/ent/subject" |
| 16 |
"github.com/in-toto/archivista/ent/subjectdigest" |
| 17 |
) |
| 18 |
|
| 19 |
// SubjectDigestUpdate is the builder for updating SubjectDigest entities. |
| 20 |
type SubjectDigestUpdate struct { |
| 21 |
config |
| 22 |
hooks []Hook |
| 23 |
mutation *SubjectDigestMutation |
| 24 |
} |
| 25 |
|
| 26 |
// Where appends a list predicates to the SubjectDigestUpdate builder. |
| 27 |
func (_u *SubjectDigestUpdate) Where(ps ...predicate.SubjectDigest) *SubjectDigestUpdate { |
| 28 |
_u.mutation.Where(ps...) |
| 29 |
return _u |
| 30 |
} |
| 31 |
|
| 32 |
// SetAlgorithm sets the "algorithm" field. |
| 33 |
func (_u *SubjectDigestUpdate) SetAlgorithm(v string) *SubjectDigestUpdate { |
| 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 *SubjectDigestUpdate) SetNillableAlgorithm(v *string) *SubjectDigestUpdate { |
| 40 |
if v != nil { |
| 41 |
_u.SetAlgorithm(*v) |
| 42 |
} |
| 43 |
return _u |
| 44 |
} |
| 45 |
|
| 46 |
// SetValue sets the "value" field. |
| 47 |
func (_u *SubjectDigestUpdate) SetValue(v string) *SubjectDigestUpdate { |
| 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 *SubjectDigestUpdate) SetNillableValue(v *string) *SubjectDigestUpdate { |
| 54 |
if v != nil { |
| 55 |
_u.SetValue(*v) |
| 56 |
} |
| 57 |
return _u |
| 58 |
} |
| 59 |
|
| 60 |
// SetSubjectID sets the "subject" edge to the Subject entity by ID. |
| 61 |
func (_u *SubjectDigestUpdate) SetSubjectID(id uuid.UUID) *SubjectDigestUpdate { |
| 62 |
_u.mutation.SetSubjectID(id) |
| 63 |
return _u |
| 64 |
} |
| 65 |
|
| 66 |
// SetNillableSubjectID sets the "subject" edge to the Subject entity by ID if the given value is not nil. |
| 67 |
func (_u *SubjectDigestUpdate) SetNillableSubjectID(id *uuid.UUID) *SubjectDigestUpdate { |
| 68 |
if id != nil { |
| 69 |
_u = _u.SetSubjectID(*id) |
| 70 |
} |
| 71 |
return _u |
| 72 |
} |
| 73 |
|
| 74 |
// SetSubject sets the "subject" edge to the Subject entity. |
| 75 |
func (_u *SubjectDigestUpdate) SetSubject(v *Subject) *SubjectDigestUpdate { |
| 76 |
return _u.SetSubjectID(v.ID) |
| 77 |
} |
| 78 |
|
| 79 |
// Mutation returns the SubjectDigestMutation object of the builder. |
| 80 |
func (_u *SubjectDigestUpdate) Mutation() *SubjectDigestMutation { |
| 81 |
return _u.mutation |
| 82 |
} |
| 83 |
|
| 84 |
// ClearSubject clears the "subject" edge to the Subject entity. |
| 85 |
func (_u *SubjectDigestUpdate) ClearSubject() *SubjectDigestUpdate { |
| 86 |
_u.mutation.ClearSubject() |
| 87 |
return _u |
| 88 |
} |
| 89 |
|
| 90 |
// Save executes the query and returns the number of nodes affected by the update operation. |
| 91 |
func (_u *SubjectDigestUpdate) 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 *SubjectDigestUpdate) 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 *SubjectDigestUpdate) 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 *SubjectDigestUpdate) 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 *SubjectDigestUpdate) check() error { |
| 119 |
if v, ok := _u.mutation.Algorithm(); ok { |
| 120 |
if err := subjectdigest.AlgorithmValidator(v); err != nil { |
| 121 |
return &ValidationError{Name: "algorithm", err: fmt.Errorf(`ent: validator failed for field "SubjectDigest.algorithm": %w`, err)} |
| 122 |
} |
| 123 |
} |
| 124 |
if v, ok := _u.mutation.Value(); ok { |
| 125 |
if err := subjectdigest.ValueValidator(v); err != nil { |
| 126 |
return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "SubjectDigest.value": %w`, err)} |
| 127 |
} |
| 128 |
} |
| 129 |
return nil |
| 130 |
} |
| 131 |
|
| 132 |
func (_u *SubjectDigestUpdate) sqlSave(ctx context.Context) (_node int, err error) { |
| 133 |
if err := _u.check(); err != nil { |
| 134 |
return _node, err |
| 135 |
} |
| 136 |
_spec := sqlgraph.NewUpdateSpec(subjectdigest.Table, subjectdigest.Columns, sqlgraph.NewFieldSpec(subjectdigest.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(subjectdigest.FieldAlgorithm, field.TypeString, value) |
| 146 |
} |
| 147 |
if value, ok := _u.mutation.Value(); ok { |
| 148 |
_spec.SetField(subjectdigest.FieldValue, field.TypeString, value) |
| 149 |
} |
| 150 |
if _u.mutation.SubjectCleared() { |
| 151 |
edge := &sqlgraph.EdgeSpec{ |
| 152 |
Rel: sqlgraph.M2O, |
| 153 |
Inverse: true, |
| 154 |
Table: subjectdigest.SubjectTable, |
| 155 |
Columns: []string{subjectdigest.SubjectColumn}, |
| 156 |
Bidi: false, |
| 157 |
Target: &sqlgraph.EdgeTarget{ |
| 158 |
IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID), |
| 159 |
}, |
| 160 |
} |
| 161 |
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
| 162 |
} |
| 163 |
if nodes := _u.mutation.SubjectIDs(); len(nodes) > 0 { |
| 164 |
edge := &sqlgraph.EdgeSpec{ |
| 165 |
Rel: sqlgraph.M2O, |
| 166 |
Inverse: true, |
| 167 |
Table: subjectdigest.SubjectTable, |
| 168 |
Columns: []string{subjectdigest.SubjectColumn}, |
| 169 |
Bidi: false, |
| 170 |
Target: &sqlgraph.EdgeTarget{ |
| 171 |
IDSpec: sqlgraph.NewFieldSpec(subject.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{subjectdigest.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 |
// SubjectDigestUpdateOne is the builder for updating a single SubjectDigest entity. |
| 192 |
type SubjectDigestUpdateOne struct { |
| 193 |
config |
| 194 |
fields []string |
| 195 |
hooks []Hook |
| 196 |
mutation *SubjectDigestMutation |
| 197 |
} |
| 198 |
|
| 199 |
// SetAlgorithm sets the "algorithm" field. |
| 200 |
func (_u *SubjectDigestUpdateOne) SetAlgorithm(v string) *SubjectDigestUpdateOne { |
| 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 *SubjectDigestUpdateOne) SetNillableAlgorithm(v *string) *SubjectDigestUpdateOne { |
| 207 |
if v != nil { |
| 208 |
_u.SetAlgorithm(*v) |
| 209 |
} |
| 210 |
return _u |
| 211 |
} |
| 212 |
|
| 213 |
// SetValue sets the "value" field. |
| 214 |
func (_u *SubjectDigestUpdateOne) SetValue(v string) *SubjectDigestUpdateOne { |
| 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 *SubjectDigestUpdateOne) SetNillableValue(v *string) *SubjectDigestUpdateOne { |
| 221 |
if v != nil { |
| 222 |
_u.SetValue(*v) |
| 223 |
} |
| 224 |
return _u |
| 225 |
} |
| 226 |
|
| 227 |
// SetSubjectID sets the "subject" edge to the Subject entity by ID. |
| 228 |
func (_u *SubjectDigestUpdateOne) SetSubjectID(id uuid.UUID) *SubjectDigestUpdateOne { |
| 229 |
_u.mutation.SetSubjectID(id) |
| 230 |
return _u |
| 231 |
} |
| 232 |
|
| 233 |
// SetNillableSubjectID sets the "subject" edge to the Subject entity by ID if the given value is not nil. |
| 234 |
func (_u *SubjectDigestUpdateOne) SetNillableSubjectID(id *uuid.UUID) *SubjectDigestUpdateOne { |
| 235 |
if id != nil { |
| 236 |
_u = _u.SetSubjectID(*id) |
| 237 |
} |
| 238 |
return _u |
| 239 |
} |
| 240 |
|
| 241 |
// SetSubject sets the "subject" edge to the Subject entity. |
| 242 |
func (_u *SubjectDigestUpdateOne) SetSubject(v *Subject) *SubjectDigestUpdateOne { |
| 243 |
return _u.SetSubjectID(v.ID) |
| 244 |
} |
| 245 |
|
| 246 |
// Mutation returns the SubjectDigestMutation object of the builder. |
| 247 |
func (_u *SubjectDigestUpdateOne) Mutation() *SubjectDigestMutation { |
| 248 |
return _u.mutation |
| 249 |
} |
| 250 |
|
| 251 |
// ClearSubject clears the "subject" edge to the Subject entity. |
| 252 |
func (_u *SubjectDigestUpdateOne) ClearSubject() *SubjectDigestUpdateOne { |
| 253 |
_u.mutation.ClearSubject() |
| 254 |
return _u |
| 255 |
} |
| 256 |
|
| 257 |
// Where appends a list predicates to the SubjectDigestUpdate builder. |
| 258 |
func (_u *SubjectDigestUpdateOne) Where(ps ...predicate.SubjectDigest) *SubjectDigestUpdateOne { |
| 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 *SubjectDigestUpdateOne) Select(field string, fields ...string) *SubjectDigestUpdateOne { |
| 266 |
_u.fields = append([]string{field}, fields...) |
| 267 |
return _u |
| 268 |
} |
| 269 |
|
| 270 |
// Save executes the query and returns the updated SubjectDigest entity. |
| 271 |
func (_u *SubjectDigestUpdateOne) Save(ctx context.Context) (*SubjectDigest, 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 *SubjectDigestUpdateOne) SaveX(ctx context.Context) *SubjectDigest { |
| 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 *SubjectDigestUpdateOne) 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 *SubjectDigestUpdateOne) 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 *SubjectDigestUpdateOne) check() error { |
| 299 |
if v, ok := _u.mutation.Algorithm(); ok { |
| 300 |
if err := subjectdigest.AlgorithmValidator(v); err != nil { |
| 301 |
return &ValidationError{Name: "algorithm", err: fmt.Errorf(`ent: validator failed for field "SubjectDigest.algorithm": %w`, err)} |
| 302 |
} |
| 303 |
} |
| 304 |
if v, ok := _u.mutation.Value(); ok { |
| 305 |
if err := subjectdigest.ValueValidator(v); err != nil { |
| 306 |
return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "SubjectDigest.value": %w`, err)} |
| 307 |
} |
| 308 |
} |
| 309 |
return nil |
| 310 |
} |
| 311 |
|
| 312 |
func (_u *SubjectDigestUpdateOne) sqlSave(ctx context.Context) (_node *SubjectDigest, err error) { |
| 313 |
if err := _u.check(); err != nil { |
| 314 |
return _node, err |
| 315 |
} |
| 316 |
_spec := sqlgraph.NewUpdateSpec(subjectdigest.Table, subjectdigest.Columns, sqlgraph.NewFieldSpec(subjectdigest.FieldID, field.TypeUUID)) |
| 317 |
id, ok := _u.mutation.ID() |
| 318 |
if !ok { |
| 319 |
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SubjectDigest.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, subjectdigest.FieldID) |
| 325 |
for _, f := range fields { |
| 326 |
if !subjectdigest.ValidColumn(f) { |
| 327 |
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} |
| 328 |
} |
| 329 |
if f != subjectdigest.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(subjectdigest.FieldAlgorithm, field.TypeString, value) |
| 343 |
} |
| 344 |
if value, ok := _u.mutation.Value(); ok { |
| 345 |
_spec.SetField(subjectdigest.FieldValue, field.TypeString, value) |
| 346 |
} |
| 347 |
if _u.mutation.SubjectCleared() { |
| 348 |
edge := &sqlgraph.EdgeSpec{ |
| 349 |
Rel: sqlgraph.M2O, |
| 350 |
Inverse: true, |
| 351 |
Table: subjectdigest.SubjectTable, |
| 352 |
Columns: []string{subjectdigest.SubjectColumn}, |
| 353 |
Bidi: false, |
| 354 |
Target: &sqlgraph.EdgeTarget{ |
| 355 |
IDSpec: sqlgraph.NewFieldSpec(subject.FieldID, field.TypeUUID), |
| 356 |
}, |
| 357 |
} |
| 358 |
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
| 359 |
} |
| 360 |
if nodes := _u.mutation.SubjectIDs(); len(nodes) > 0 { |
| 361 |
edge := &sqlgraph.EdgeSpec{ |
| 362 |
Rel: sqlgraph.M2O, |
| 363 |
Inverse: true, |
| 364 |
Table: subjectdigest.SubjectTable, |
| 365 |
Columns: []string{subjectdigest.SubjectColumn}, |
| 366 |
Bidi: false, |
| 367 |
Target: &sqlgraph.EdgeTarget{ |
| 368 |
IDSpec: sqlgraph.NewFieldSpec(subject.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 = &SubjectDigest{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{subjectdigest.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 |
} |