bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/ent/machine_update.go (about) 1 // Code generated by entc, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "fmt" 8 "time" 9 10 "entgo.io/ent/dialect/sql" 11 "entgo.io/ent/dialect/sql/sqlgraph" 12 "entgo.io/ent/schema/field" 13 "bitbucket.org/Aishee/synsec/pkg/database/ent/alert" 14 "bitbucket.org/Aishee/synsec/pkg/database/ent/machine" 15 "bitbucket.org/Aishee/synsec/pkg/database/ent/predicate" 16 ) 17 18 // MachineUpdate is the builder for updating Machine entities. 19 type MachineUpdate struct { 20 config 21 hooks []Hook 22 mutation *MachineMutation 23 } 24 25 // Where adds a new predicate for the MachineUpdate builder. 26 func (mu *MachineUpdate) Where(ps ...predicate.Machine) *MachineUpdate { 27 mu.mutation.predicates = append(mu.mutation.predicates, ps...) 28 return mu 29 } 30 31 // SetCreatedAt sets the "created_at" field. 32 func (mu *MachineUpdate) SetCreatedAt(t time.Time) *MachineUpdate { 33 mu.mutation.SetCreatedAt(t) 34 return mu 35 } 36 37 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 38 func (mu *MachineUpdate) SetNillableCreatedAt(t *time.Time) *MachineUpdate { 39 if t != nil { 40 mu.SetCreatedAt(*t) 41 } 42 return mu 43 } 44 45 // SetUpdatedAt sets the "updated_at" field. 46 func (mu *MachineUpdate) SetUpdatedAt(t time.Time) *MachineUpdate { 47 mu.mutation.SetUpdatedAt(t) 48 return mu 49 } 50 51 // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. 52 func (mu *MachineUpdate) SetNillableUpdatedAt(t *time.Time) *MachineUpdate { 53 if t != nil { 54 mu.SetUpdatedAt(*t) 55 } 56 return mu 57 } 58 59 // SetMachineId sets the "machineId" field. 60 func (mu *MachineUpdate) SetMachineId(s string) *MachineUpdate { 61 mu.mutation.SetMachineId(s) 62 return mu 63 } 64 65 // SetPassword sets the "password" field. 66 func (mu *MachineUpdate) SetPassword(s string) *MachineUpdate { 67 mu.mutation.SetPassword(s) 68 return mu 69 } 70 71 // SetIpAddress sets the "ipAddress" field. 72 func (mu *MachineUpdate) SetIpAddress(s string) *MachineUpdate { 73 mu.mutation.SetIpAddress(s) 74 return mu 75 } 76 77 // SetScenarios sets the "scenarios" field. 78 func (mu *MachineUpdate) SetScenarios(s string) *MachineUpdate { 79 mu.mutation.SetScenarios(s) 80 return mu 81 } 82 83 // SetNillableScenarios sets the "scenarios" field if the given value is not nil. 84 func (mu *MachineUpdate) SetNillableScenarios(s *string) *MachineUpdate { 85 if s != nil { 86 mu.SetScenarios(*s) 87 } 88 return mu 89 } 90 91 // ClearScenarios clears the value of the "scenarios" field. 92 func (mu *MachineUpdate) ClearScenarios() *MachineUpdate { 93 mu.mutation.ClearScenarios() 94 return mu 95 } 96 97 // SetVersion sets the "version" field. 98 func (mu *MachineUpdate) SetVersion(s string) *MachineUpdate { 99 mu.mutation.SetVersion(s) 100 return mu 101 } 102 103 // SetNillableVersion sets the "version" field if the given value is not nil. 104 func (mu *MachineUpdate) SetNillableVersion(s *string) *MachineUpdate { 105 if s != nil { 106 mu.SetVersion(*s) 107 } 108 return mu 109 } 110 111 // ClearVersion clears the value of the "version" field. 112 func (mu *MachineUpdate) ClearVersion() *MachineUpdate { 113 mu.mutation.ClearVersion() 114 return mu 115 } 116 117 // SetIsValidated sets the "isValidated" field. 118 func (mu *MachineUpdate) SetIsValidated(b bool) *MachineUpdate { 119 mu.mutation.SetIsValidated(b) 120 return mu 121 } 122 123 // SetNillableIsValidated sets the "isValidated" field if the given value is not nil. 124 func (mu *MachineUpdate) SetNillableIsValidated(b *bool) *MachineUpdate { 125 if b != nil { 126 mu.SetIsValidated(*b) 127 } 128 return mu 129 } 130 131 // SetStatus sets the "status" field. 132 func (mu *MachineUpdate) SetStatus(s string) *MachineUpdate { 133 mu.mutation.SetStatus(s) 134 return mu 135 } 136 137 // SetNillableStatus sets the "status" field if the given value is not nil. 138 func (mu *MachineUpdate) SetNillableStatus(s *string) *MachineUpdate { 139 if s != nil { 140 mu.SetStatus(*s) 141 } 142 return mu 143 } 144 145 // ClearStatus clears the value of the "status" field. 146 func (mu *MachineUpdate) ClearStatus() *MachineUpdate { 147 mu.mutation.ClearStatus() 148 return mu 149 } 150 151 // AddAlertIDs adds the "alerts" edge to the Alert entity by IDs. 152 func (mu *MachineUpdate) AddAlertIDs(ids ...int) *MachineUpdate { 153 mu.mutation.AddAlertIDs(ids...) 154 return mu 155 } 156 157 // AddAlerts adds the "alerts" edges to the Alert entity. 158 func (mu *MachineUpdate) AddAlerts(a ...*Alert) *MachineUpdate { 159 ids := make([]int, len(a)) 160 for i := range a { 161 ids[i] = a[i].ID 162 } 163 return mu.AddAlertIDs(ids...) 164 } 165 166 // Mutation returns the MachineMutation object of the builder. 167 func (mu *MachineUpdate) Mutation() *MachineMutation { 168 return mu.mutation 169 } 170 171 // ClearAlerts clears all "alerts" edges to the Alert entity. 172 func (mu *MachineUpdate) ClearAlerts() *MachineUpdate { 173 mu.mutation.ClearAlerts() 174 return mu 175 } 176 177 // RemoveAlertIDs removes the "alerts" edge to Alert entities by IDs. 178 func (mu *MachineUpdate) RemoveAlertIDs(ids ...int) *MachineUpdate { 179 mu.mutation.RemoveAlertIDs(ids...) 180 return mu 181 } 182 183 // RemoveAlerts removes "alerts" edges to Alert entities. 184 func (mu *MachineUpdate) RemoveAlerts(a ...*Alert) *MachineUpdate { 185 ids := make([]int, len(a)) 186 for i := range a { 187 ids[i] = a[i].ID 188 } 189 return mu.RemoveAlertIDs(ids...) 190 } 191 192 // Save executes the query and returns the number of nodes affected by the update operation. 193 func (mu *MachineUpdate) Save(ctx context.Context) (int, error) { 194 var ( 195 err error 196 affected int 197 ) 198 if len(mu.hooks) == 0 { 199 if err = mu.check(); err != nil { 200 return 0, err 201 } 202 affected, err = mu.sqlSave(ctx) 203 } else { 204 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 205 mutation, ok := m.(*MachineMutation) 206 if !ok { 207 return nil, fmt.Errorf("unexpected mutation type %T", m) 208 } 209 if err = mu.check(); err != nil { 210 return 0, err 211 } 212 mu.mutation = mutation 213 affected, err = mu.sqlSave(ctx) 214 mutation.done = true 215 return affected, err 216 }) 217 for i := len(mu.hooks) - 1; i >= 0; i-- { 218 mut = mu.hooks[i](mut) 219 } 220 if _, err := mut.Mutate(ctx, mu.mutation); err != nil { 221 return 0, err 222 } 223 } 224 return affected, err 225 } 226 227 // SaveX is like Save, but panics if an error occurs. 228 func (mu *MachineUpdate) SaveX(ctx context.Context) int { 229 affected, err := mu.Save(ctx) 230 if err != nil { 231 panic(err) 232 } 233 return affected 234 } 235 236 // Exec executes the query. 237 func (mu *MachineUpdate) Exec(ctx context.Context) error { 238 _, err := mu.Save(ctx) 239 return err 240 } 241 242 // ExecX is like Exec, but panics if an error occurs. 243 func (mu *MachineUpdate) ExecX(ctx context.Context) { 244 if err := mu.Exec(ctx); err != nil { 245 panic(err) 246 } 247 } 248 249 // check runs all checks and user-defined validators on the builder. 250 func (mu *MachineUpdate) check() error { 251 if v, ok := mu.mutation.Scenarios(); ok { 252 if err := machine.ScenariosValidator(v); err != nil { 253 return &ValidationError{Name: "scenarios", err: fmt.Errorf("ent: validator failed for field \"scenarios\": %w", err)} 254 } 255 } 256 return nil 257 } 258 259 func (mu *MachineUpdate) sqlSave(ctx context.Context) (n int, err error) { 260 _spec := &sqlgraph.UpdateSpec{ 261 Node: &sqlgraph.NodeSpec{ 262 Table: machine.Table, 263 Columns: machine.Columns, 264 ID: &sqlgraph.FieldSpec{ 265 Type: field.TypeInt, 266 Column: machine.FieldID, 267 }, 268 }, 269 } 270 if ps := mu.mutation.predicates; len(ps) > 0 { 271 _spec.Predicate = func(selector *sql.Selector) { 272 for i := range ps { 273 ps[i](selector) 274 } 275 } 276 } 277 if value, ok := mu.mutation.CreatedAt(); ok { 278 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 279 Type: field.TypeTime, 280 Value: value, 281 Column: machine.FieldCreatedAt, 282 }) 283 } 284 if value, ok := mu.mutation.UpdatedAt(); ok { 285 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 286 Type: field.TypeTime, 287 Value: value, 288 Column: machine.FieldUpdatedAt, 289 }) 290 } 291 if value, ok := mu.mutation.MachineId(); ok { 292 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 293 Type: field.TypeString, 294 Value: value, 295 Column: machine.FieldMachineId, 296 }) 297 } 298 if value, ok := mu.mutation.Password(); ok { 299 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 300 Type: field.TypeString, 301 Value: value, 302 Column: machine.FieldPassword, 303 }) 304 } 305 if value, ok := mu.mutation.IpAddress(); ok { 306 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 307 Type: field.TypeString, 308 Value: value, 309 Column: machine.FieldIpAddress, 310 }) 311 } 312 if value, ok := mu.mutation.Scenarios(); ok { 313 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 314 Type: field.TypeString, 315 Value: value, 316 Column: machine.FieldScenarios, 317 }) 318 } 319 if mu.mutation.ScenariosCleared() { 320 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 321 Type: field.TypeString, 322 Column: machine.FieldScenarios, 323 }) 324 } 325 if value, ok := mu.mutation.Version(); ok { 326 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 327 Type: field.TypeString, 328 Value: value, 329 Column: machine.FieldVersion, 330 }) 331 } 332 if mu.mutation.VersionCleared() { 333 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 334 Type: field.TypeString, 335 Column: machine.FieldVersion, 336 }) 337 } 338 if value, ok := mu.mutation.IsValidated(); ok { 339 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 340 Type: field.TypeBool, 341 Value: value, 342 Column: machine.FieldIsValidated, 343 }) 344 } 345 if value, ok := mu.mutation.Status(); ok { 346 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 347 Type: field.TypeString, 348 Value: value, 349 Column: machine.FieldStatus, 350 }) 351 } 352 if mu.mutation.StatusCleared() { 353 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 354 Type: field.TypeString, 355 Column: machine.FieldStatus, 356 }) 357 } 358 if mu.mutation.AlertsCleared() { 359 edge := &sqlgraph.EdgeSpec{ 360 Rel: sqlgraph.O2M, 361 Inverse: false, 362 Table: machine.AlertsTable, 363 Columns: []string{machine.AlertsColumn}, 364 Bidi: false, 365 Target: &sqlgraph.EdgeTarget{ 366 IDSpec: &sqlgraph.FieldSpec{ 367 Type: field.TypeInt, 368 Column: alert.FieldID, 369 }, 370 }, 371 } 372 _spec.Edges.Clear = append(_spec.Edges.Clear, edge) 373 } 374 if nodes := mu.mutation.RemovedAlertsIDs(); len(nodes) > 0 && !mu.mutation.AlertsCleared() { 375 edge := &sqlgraph.EdgeSpec{ 376 Rel: sqlgraph.O2M, 377 Inverse: false, 378 Table: machine.AlertsTable, 379 Columns: []string{machine.AlertsColumn}, 380 Bidi: false, 381 Target: &sqlgraph.EdgeTarget{ 382 IDSpec: &sqlgraph.FieldSpec{ 383 Type: field.TypeInt, 384 Column: alert.FieldID, 385 }, 386 }, 387 } 388 for _, k := range nodes { 389 edge.Target.Nodes = append(edge.Target.Nodes, k) 390 } 391 _spec.Edges.Clear = append(_spec.Edges.Clear, edge) 392 } 393 if nodes := mu.mutation.AlertsIDs(); len(nodes) > 0 { 394 edge := &sqlgraph.EdgeSpec{ 395 Rel: sqlgraph.O2M, 396 Inverse: false, 397 Table: machine.AlertsTable, 398 Columns: []string{machine.AlertsColumn}, 399 Bidi: false, 400 Target: &sqlgraph.EdgeTarget{ 401 IDSpec: &sqlgraph.FieldSpec{ 402 Type: field.TypeInt, 403 Column: alert.FieldID, 404 }, 405 }, 406 } 407 for _, k := range nodes { 408 edge.Target.Nodes = append(edge.Target.Nodes, k) 409 } 410 _spec.Edges.Add = append(_spec.Edges.Add, edge) 411 } 412 if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil { 413 if _, ok := err.(*sqlgraph.NotFoundError); ok { 414 err = &NotFoundError{machine.Label} 415 } else if cerr, ok := isSQLConstraintError(err); ok { 416 err = cerr 417 } 418 return 0, err 419 } 420 return n, nil 421 } 422 423 // MachineUpdateOne is the builder for updating a single Machine entity. 424 type MachineUpdateOne struct { 425 config 426 hooks []Hook 427 mutation *MachineMutation 428 } 429 430 // SetCreatedAt sets the "created_at" field. 431 func (muo *MachineUpdateOne) SetCreatedAt(t time.Time) *MachineUpdateOne { 432 muo.mutation.SetCreatedAt(t) 433 return muo 434 } 435 436 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 437 func (muo *MachineUpdateOne) SetNillableCreatedAt(t *time.Time) *MachineUpdateOne { 438 if t != nil { 439 muo.SetCreatedAt(*t) 440 } 441 return muo 442 } 443 444 // SetUpdatedAt sets the "updated_at" field. 445 func (muo *MachineUpdateOne) SetUpdatedAt(t time.Time) *MachineUpdateOne { 446 muo.mutation.SetUpdatedAt(t) 447 return muo 448 } 449 450 // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. 451 func (muo *MachineUpdateOne) SetNillableUpdatedAt(t *time.Time) *MachineUpdateOne { 452 if t != nil { 453 muo.SetUpdatedAt(*t) 454 } 455 return muo 456 } 457 458 // SetMachineId sets the "machineId" field. 459 func (muo *MachineUpdateOne) SetMachineId(s string) *MachineUpdateOne { 460 muo.mutation.SetMachineId(s) 461 return muo 462 } 463 464 // SetPassword sets the "password" field. 465 func (muo *MachineUpdateOne) SetPassword(s string) *MachineUpdateOne { 466 muo.mutation.SetPassword(s) 467 return muo 468 } 469 470 // SetIpAddress sets the "ipAddress" field. 471 func (muo *MachineUpdateOne) SetIpAddress(s string) *MachineUpdateOne { 472 muo.mutation.SetIpAddress(s) 473 return muo 474 } 475 476 // SetScenarios sets the "scenarios" field. 477 func (muo *MachineUpdateOne) SetScenarios(s string) *MachineUpdateOne { 478 muo.mutation.SetScenarios(s) 479 return muo 480 } 481 482 // SetNillableScenarios sets the "scenarios" field if the given value is not nil. 483 func (muo *MachineUpdateOne) SetNillableScenarios(s *string) *MachineUpdateOne { 484 if s != nil { 485 muo.SetScenarios(*s) 486 } 487 return muo 488 } 489 490 // ClearScenarios clears the value of the "scenarios" field. 491 func (muo *MachineUpdateOne) ClearScenarios() *MachineUpdateOne { 492 muo.mutation.ClearScenarios() 493 return muo 494 } 495 496 // SetVersion sets the "version" field. 497 func (muo *MachineUpdateOne) SetVersion(s string) *MachineUpdateOne { 498 muo.mutation.SetVersion(s) 499 return muo 500 } 501 502 // SetNillableVersion sets the "version" field if the given value is not nil. 503 func (muo *MachineUpdateOne) SetNillableVersion(s *string) *MachineUpdateOne { 504 if s != nil { 505 muo.SetVersion(*s) 506 } 507 return muo 508 } 509 510 // ClearVersion clears the value of the "version" field. 511 func (muo *MachineUpdateOne) ClearVersion() *MachineUpdateOne { 512 muo.mutation.ClearVersion() 513 return muo 514 } 515 516 // SetIsValidated sets the "isValidated" field. 517 func (muo *MachineUpdateOne) SetIsValidated(b bool) *MachineUpdateOne { 518 muo.mutation.SetIsValidated(b) 519 return muo 520 } 521 522 // SetNillableIsValidated sets the "isValidated" field if the given value is not nil. 523 func (muo *MachineUpdateOne) SetNillableIsValidated(b *bool) *MachineUpdateOne { 524 if b != nil { 525 muo.SetIsValidated(*b) 526 } 527 return muo 528 } 529 530 // SetStatus sets the "status" field. 531 func (muo *MachineUpdateOne) SetStatus(s string) *MachineUpdateOne { 532 muo.mutation.SetStatus(s) 533 return muo 534 } 535 536 // SetNillableStatus sets the "status" field if the given value is not nil. 537 func (muo *MachineUpdateOne) SetNillableStatus(s *string) *MachineUpdateOne { 538 if s != nil { 539 muo.SetStatus(*s) 540 } 541 return muo 542 } 543 544 // ClearStatus clears the value of the "status" field. 545 func (muo *MachineUpdateOne) ClearStatus() *MachineUpdateOne { 546 muo.mutation.ClearStatus() 547 return muo 548 } 549 550 // AddAlertIDs adds the "alerts" edge to the Alert entity by IDs. 551 func (muo *MachineUpdateOne) AddAlertIDs(ids ...int) *MachineUpdateOne { 552 muo.mutation.AddAlertIDs(ids...) 553 return muo 554 } 555 556 // AddAlerts adds the "alerts" edges to the Alert entity. 557 func (muo *MachineUpdateOne) AddAlerts(a ...*Alert) *MachineUpdateOne { 558 ids := make([]int, len(a)) 559 for i := range a { 560 ids[i] = a[i].ID 561 } 562 return muo.AddAlertIDs(ids...) 563 } 564 565 // Mutation returns the MachineMutation object of the builder. 566 func (muo *MachineUpdateOne) Mutation() *MachineMutation { 567 return muo.mutation 568 } 569 570 // ClearAlerts clears all "alerts" edges to the Alert entity. 571 func (muo *MachineUpdateOne) ClearAlerts() *MachineUpdateOne { 572 muo.mutation.ClearAlerts() 573 return muo 574 } 575 576 // RemoveAlertIDs removes the "alerts" edge to Alert entities by IDs. 577 func (muo *MachineUpdateOne) RemoveAlertIDs(ids ...int) *MachineUpdateOne { 578 muo.mutation.RemoveAlertIDs(ids...) 579 return muo 580 } 581 582 // RemoveAlerts removes "alerts" edges to Alert entities. 583 func (muo *MachineUpdateOne) RemoveAlerts(a ...*Alert) *MachineUpdateOne { 584 ids := make([]int, len(a)) 585 for i := range a { 586 ids[i] = a[i].ID 587 } 588 return muo.RemoveAlertIDs(ids...) 589 } 590 591 // Save executes the query and returns the updated Machine entity. 592 func (muo *MachineUpdateOne) Save(ctx context.Context) (*Machine, error) { 593 var ( 594 err error 595 node *Machine 596 ) 597 if len(muo.hooks) == 0 { 598 if err = muo.check(); err != nil { 599 return nil, err 600 } 601 node, err = muo.sqlSave(ctx) 602 } else { 603 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 604 mutation, ok := m.(*MachineMutation) 605 if !ok { 606 return nil, fmt.Errorf("unexpected mutation type %T", m) 607 } 608 if err = muo.check(); err != nil { 609 return nil, err 610 } 611 muo.mutation = mutation 612 node, err = muo.sqlSave(ctx) 613 mutation.done = true 614 return node, err 615 }) 616 for i := len(muo.hooks) - 1; i >= 0; i-- { 617 mut = muo.hooks[i](mut) 618 } 619 if _, err := mut.Mutate(ctx, muo.mutation); err != nil { 620 return nil, err 621 } 622 } 623 return node, err 624 } 625 626 // SaveX is like Save, but panics if an error occurs. 627 func (muo *MachineUpdateOne) SaveX(ctx context.Context) *Machine { 628 node, err := muo.Save(ctx) 629 if err != nil { 630 panic(err) 631 } 632 return node 633 } 634 635 // Exec executes the query on the entity. 636 func (muo *MachineUpdateOne) Exec(ctx context.Context) error { 637 _, err := muo.Save(ctx) 638 return err 639 } 640 641 // ExecX is like Exec, but panics if an error occurs. 642 func (muo *MachineUpdateOne) ExecX(ctx context.Context) { 643 if err := muo.Exec(ctx); err != nil { 644 panic(err) 645 } 646 } 647 648 // check runs all checks and user-defined validators on the builder. 649 func (muo *MachineUpdateOne) check() error { 650 if v, ok := muo.mutation.Scenarios(); ok { 651 if err := machine.ScenariosValidator(v); err != nil { 652 return &ValidationError{Name: "scenarios", err: fmt.Errorf("ent: validator failed for field \"scenarios\": %w", err)} 653 } 654 } 655 return nil 656 } 657 658 func (muo *MachineUpdateOne) sqlSave(ctx context.Context) (_node *Machine, err error) { 659 _spec := &sqlgraph.UpdateSpec{ 660 Node: &sqlgraph.NodeSpec{ 661 Table: machine.Table, 662 Columns: machine.Columns, 663 ID: &sqlgraph.FieldSpec{ 664 Type: field.TypeInt, 665 Column: machine.FieldID, 666 }, 667 }, 668 } 669 id, ok := muo.mutation.ID() 670 if !ok { 671 return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Machine.ID for update")} 672 } 673 _spec.Node.ID.Value = id 674 if ps := muo.mutation.predicates; len(ps) > 0 { 675 _spec.Predicate = func(selector *sql.Selector) { 676 for i := range ps { 677 ps[i](selector) 678 } 679 } 680 } 681 if value, ok := muo.mutation.CreatedAt(); ok { 682 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 683 Type: field.TypeTime, 684 Value: value, 685 Column: machine.FieldCreatedAt, 686 }) 687 } 688 if value, ok := muo.mutation.UpdatedAt(); ok { 689 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 690 Type: field.TypeTime, 691 Value: value, 692 Column: machine.FieldUpdatedAt, 693 }) 694 } 695 if value, ok := muo.mutation.MachineId(); ok { 696 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 697 Type: field.TypeString, 698 Value: value, 699 Column: machine.FieldMachineId, 700 }) 701 } 702 if value, ok := muo.mutation.Password(); ok { 703 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 704 Type: field.TypeString, 705 Value: value, 706 Column: machine.FieldPassword, 707 }) 708 } 709 if value, ok := muo.mutation.IpAddress(); ok { 710 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 711 Type: field.TypeString, 712 Value: value, 713 Column: machine.FieldIpAddress, 714 }) 715 } 716 if value, ok := muo.mutation.Scenarios(); ok { 717 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 718 Type: field.TypeString, 719 Value: value, 720 Column: machine.FieldScenarios, 721 }) 722 } 723 if muo.mutation.ScenariosCleared() { 724 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 725 Type: field.TypeString, 726 Column: machine.FieldScenarios, 727 }) 728 } 729 if value, ok := muo.mutation.Version(); ok { 730 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 731 Type: field.TypeString, 732 Value: value, 733 Column: machine.FieldVersion, 734 }) 735 } 736 if muo.mutation.VersionCleared() { 737 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 738 Type: field.TypeString, 739 Column: machine.FieldVersion, 740 }) 741 } 742 if value, ok := muo.mutation.IsValidated(); ok { 743 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 744 Type: field.TypeBool, 745 Value: value, 746 Column: machine.FieldIsValidated, 747 }) 748 } 749 if value, ok := muo.mutation.Status(); ok { 750 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 751 Type: field.TypeString, 752 Value: value, 753 Column: machine.FieldStatus, 754 }) 755 } 756 if muo.mutation.StatusCleared() { 757 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 758 Type: field.TypeString, 759 Column: machine.FieldStatus, 760 }) 761 } 762 if muo.mutation.AlertsCleared() { 763 edge := &sqlgraph.EdgeSpec{ 764 Rel: sqlgraph.O2M, 765 Inverse: false, 766 Table: machine.AlertsTable, 767 Columns: []string{machine.AlertsColumn}, 768 Bidi: false, 769 Target: &sqlgraph.EdgeTarget{ 770 IDSpec: &sqlgraph.FieldSpec{ 771 Type: field.TypeInt, 772 Column: alert.FieldID, 773 }, 774 }, 775 } 776 _spec.Edges.Clear = append(_spec.Edges.Clear, edge) 777 } 778 if nodes := muo.mutation.RemovedAlertsIDs(); len(nodes) > 0 && !muo.mutation.AlertsCleared() { 779 edge := &sqlgraph.EdgeSpec{ 780 Rel: sqlgraph.O2M, 781 Inverse: false, 782 Table: machine.AlertsTable, 783 Columns: []string{machine.AlertsColumn}, 784 Bidi: false, 785 Target: &sqlgraph.EdgeTarget{ 786 IDSpec: &sqlgraph.FieldSpec{ 787 Type: field.TypeInt, 788 Column: alert.FieldID, 789 }, 790 }, 791 } 792 for _, k := range nodes { 793 edge.Target.Nodes = append(edge.Target.Nodes, k) 794 } 795 _spec.Edges.Clear = append(_spec.Edges.Clear, edge) 796 } 797 if nodes := muo.mutation.AlertsIDs(); len(nodes) > 0 { 798 edge := &sqlgraph.EdgeSpec{ 799 Rel: sqlgraph.O2M, 800 Inverse: false, 801 Table: machine.AlertsTable, 802 Columns: []string{machine.AlertsColumn}, 803 Bidi: false, 804 Target: &sqlgraph.EdgeTarget{ 805 IDSpec: &sqlgraph.FieldSpec{ 806 Type: field.TypeInt, 807 Column: alert.FieldID, 808 }, 809 }, 810 } 811 for _, k := range nodes { 812 edge.Target.Nodes = append(edge.Target.Nodes, k) 813 } 814 _spec.Edges.Add = append(_spec.Edges.Add, edge) 815 } 816 _node = &Machine{config: muo.config} 817 _spec.Assign = _node.assignValues 818 _spec.ScanValues = _node.scanValues 819 if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil { 820 if _, ok := err.(*sqlgraph.NotFoundError); ok { 821 err = &NotFoundError{machine.Label} 822 } else if cerr, ok := isSQLConstraintError(err); ok { 823 err = cerr 824 } 825 return nil, err 826 } 827 return _node, nil 828 }