github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/coinusedfor_update.go (about) 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/NpoolPlatform/chain-middleware/pkg/db/ent/coinusedfor" 14 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/predicate" 15 "github.com/google/uuid" 16 ) 17 18 // CoinUsedForUpdate is the builder for updating CoinUsedFor entities. 19 type CoinUsedForUpdate struct { 20 config 21 hooks []Hook 22 mutation *CoinUsedForMutation 23 modifiers []func(*sql.UpdateBuilder) 24 } 25 26 // Where appends a list predicates to the CoinUsedForUpdate builder. 27 func (cufu *CoinUsedForUpdate) Where(ps ...predicate.CoinUsedFor) *CoinUsedForUpdate { 28 cufu.mutation.Where(ps...) 29 return cufu 30 } 31 32 // SetCreatedAt sets the "created_at" field. 33 func (cufu *CoinUsedForUpdate) SetCreatedAt(u uint32) *CoinUsedForUpdate { 34 cufu.mutation.ResetCreatedAt() 35 cufu.mutation.SetCreatedAt(u) 36 return cufu 37 } 38 39 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 40 func (cufu *CoinUsedForUpdate) SetNillableCreatedAt(u *uint32) *CoinUsedForUpdate { 41 if u != nil { 42 cufu.SetCreatedAt(*u) 43 } 44 return cufu 45 } 46 47 // AddCreatedAt adds u to the "created_at" field. 48 func (cufu *CoinUsedForUpdate) AddCreatedAt(u int32) *CoinUsedForUpdate { 49 cufu.mutation.AddCreatedAt(u) 50 return cufu 51 } 52 53 // SetUpdatedAt sets the "updated_at" field. 54 func (cufu *CoinUsedForUpdate) SetUpdatedAt(u uint32) *CoinUsedForUpdate { 55 cufu.mutation.ResetUpdatedAt() 56 cufu.mutation.SetUpdatedAt(u) 57 return cufu 58 } 59 60 // AddUpdatedAt adds u to the "updated_at" field. 61 func (cufu *CoinUsedForUpdate) AddUpdatedAt(u int32) *CoinUsedForUpdate { 62 cufu.mutation.AddUpdatedAt(u) 63 return cufu 64 } 65 66 // SetDeletedAt sets the "deleted_at" field. 67 func (cufu *CoinUsedForUpdate) SetDeletedAt(u uint32) *CoinUsedForUpdate { 68 cufu.mutation.ResetDeletedAt() 69 cufu.mutation.SetDeletedAt(u) 70 return cufu 71 } 72 73 // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. 74 func (cufu *CoinUsedForUpdate) SetNillableDeletedAt(u *uint32) *CoinUsedForUpdate { 75 if u != nil { 76 cufu.SetDeletedAt(*u) 77 } 78 return cufu 79 } 80 81 // AddDeletedAt adds u to the "deleted_at" field. 82 func (cufu *CoinUsedForUpdate) AddDeletedAt(u int32) *CoinUsedForUpdate { 83 cufu.mutation.AddDeletedAt(u) 84 return cufu 85 } 86 87 // SetEntID sets the "ent_id" field. 88 func (cufu *CoinUsedForUpdate) SetEntID(u uuid.UUID) *CoinUsedForUpdate { 89 cufu.mutation.SetEntID(u) 90 return cufu 91 } 92 93 // SetNillableEntID sets the "ent_id" field if the given value is not nil. 94 func (cufu *CoinUsedForUpdate) SetNillableEntID(u *uuid.UUID) *CoinUsedForUpdate { 95 if u != nil { 96 cufu.SetEntID(*u) 97 } 98 return cufu 99 } 100 101 // SetCoinTypeID sets the "coin_type_id" field. 102 func (cufu *CoinUsedForUpdate) SetCoinTypeID(u uuid.UUID) *CoinUsedForUpdate { 103 cufu.mutation.SetCoinTypeID(u) 104 return cufu 105 } 106 107 // SetNillableCoinTypeID sets the "coin_type_id" field if the given value is not nil. 108 func (cufu *CoinUsedForUpdate) SetNillableCoinTypeID(u *uuid.UUID) *CoinUsedForUpdate { 109 if u != nil { 110 cufu.SetCoinTypeID(*u) 111 } 112 return cufu 113 } 114 115 // ClearCoinTypeID clears the value of the "coin_type_id" field. 116 func (cufu *CoinUsedForUpdate) ClearCoinTypeID() *CoinUsedForUpdate { 117 cufu.mutation.ClearCoinTypeID() 118 return cufu 119 } 120 121 // SetUsedFor sets the "used_for" field. 122 func (cufu *CoinUsedForUpdate) SetUsedFor(s string) *CoinUsedForUpdate { 123 cufu.mutation.SetUsedFor(s) 124 return cufu 125 } 126 127 // SetNillableUsedFor sets the "used_for" field if the given value is not nil. 128 func (cufu *CoinUsedForUpdate) SetNillableUsedFor(s *string) *CoinUsedForUpdate { 129 if s != nil { 130 cufu.SetUsedFor(*s) 131 } 132 return cufu 133 } 134 135 // ClearUsedFor clears the value of the "used_for" field. 136 func (cufu *CoinUsedForUpdate) ClearUsedFor() *CoinUsedForUpdate { 137 cufu.mutation.ClearUsedFor() 138 return cufu 139 } 140 141 // SetPriority sets the "priority" field. 142 func (cufu *CoinUsedForUpdate) SetPriority(u uint32) *CoinUsedForUpdate { 143 cufu.mutation.ResetPriority() 144 cufu.mutation.SetPriority(u) 145 return cufu 146 } 147 148 // SetNillablePriority sets the "priority" field if the given value is not nil. 149 func (cufu *CoinUsedForUpdate) SetNillablePriority(u *uint32) *CoinUsedForUpdate { 150 if u != nil { 151 cufu.SetPriority(*u) 152 } 153 return cufu 154 } 155 156 // AddPriority adds u to the "priority" field. 157 func (cufu *CoinUsedForUpdate) AddPriority(u int32) *CoinUsedForUpdate { 158 cufu.mutation.AddPriority(u) 159 return cufu 160 } 161 162 // ClearPriority clears the value of the "priority" field. 163 func (cufu *CoinUsedForUpdate) ClearPriority() *CoinUsedForUpdate { 164 cufu.mutation.ClearPriority() 165 return cufu 166 } 167 168 // Mutation returns the CoinUsedForMutation object of the builder. 169 func (cufu *CoinUsedForUpdate) Mutation() *CoinUsedForMutation { 170 return cufu.mutation 171 } 172 173 // Save executes the query and returns the number of nodes affected by the update operation. 174 func (cufu *CoinUsedForUpdate) Save(ctx context.Context) (int, error) { 175 var ( 176 err error 177 affected int 178 ) 179 if err := cufu.defaults(); err != nil { 180 return 0, err 181 } 182 if len(cufu.hooks) == 0 { 183 affected, err = cufu.sqlSave(ctx) 184 } else { 185 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 186 mutation, ok := m.(*CoinUsedForMutation) 187 if !ok { 188 return nil, fmt.Errorf("unexpected mutation type %T", m) 189 } 190 cufu.mutation = mutation 191 affected, err = cufu.sqlSave(ctx) 192 mutation.done = true 193 return affected, err 194 }) 195 for i := len(cufu.hooks) - 1; i >= 0; i-- { 196 if cufu.hooks[i] == nil { 197 return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 198 } 199 mut = cufu.hooks[i](mut) 200 } 201 if _, err := mut.Mutate(ctx, cufu.mutation); err != nil { 202 return 0, err 203 } 204 } 205 return affected, err 206 } 207 208 // SaveX is like Save, but panics if an error occurs. 209 func (cufu *CoinUsedForUpdate) SaveX(ctx context.Context) int { 210 affected, err := cufu.Save(ctx) 211 if err != nil { 212 panic(err) 213 } 214 return affected 215 } 216 217 // Exec executes the query. 218 func (cufu *CoinUsedForUpdate) Exec(ctx context.Context) error { 219 _, err := cufu.Save(ctx) 220 return err 221 } 222 223 // ExecX is like Exec, but panics if an error occurs. 224 func (cufu *CoinUsedForUpdate) ExecX(ctx context.Context) { 225 if err := cufu.Exec(ctx); err != nil { 226 panic(err) 227 } 228 } 229 230 // defaults sets the default values of the builder before save. 231 func (cufu *CoinUsedForUpdate) defaults() error { 232 if _, ok := cufu.mutation.UpdatedAt(); !ok { 233 if coinusedfor.UpdateDefaultUpdatedAt == nil { 234 return fmt.Errorf("ent: uninitialized coinusedfor.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") 235 } 236 v := coinusedfor.UpdateDefaultUpdatedAt() 237 cufu.mutation.SetUpdatedAt(v) 238 } 239 return nil 240 } 241 242 // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. 243 func (cufu *CoinUsedForUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CoinUsedForUpdate { 244 cufu.modifiers = append(cufu.modifiers, modifiers...) 245 return cufu 246 } 247 248 func (cufu *CoinUsedForUpdate) sqlSave(ctx context.Context) (n int, err error) { 249 _spec := &sqlgraph.UpdateSpec{ 250 Node: &sqlgraph.NodeSpec{ 251 Table: coinusedfor.Table, 252 Columns: coinusedfor.Columns, 253 ID: &sqlgraph.FieldSpec{ 254 Type: field.TypeUint32, 255 Column: coinusedfor.FieldID, 256 }, 257 }, 258 } 259 if ps := cufu.mutation.predicates; len(ps) > 0 { 260 _spec.Predicate = func(selector *sql.Selector) { 261 for i := range ps { 262 ps[i](selector) 263 } 264 } 265 } 266 if value, ok := cufu.mutation.CreatedAt(); ok { 267 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 268 Type: field.TypeUint32, 269 Value: value, 270 Column: coinusedfor.FieldCreatedAt, 271 }) 272 } 273 if value, ok := cufu.mutation.AddedCreatedAt(); ok { 274 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 275 Type: field.TypeUint32, 276 Value: value, 277 Column: coinusedfor.FieldCreatedAt, 278 }) 279 } 280 if value, ok := cufu.mutation.UpdatedAt(); ok { 281 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 282 Type: field.TypeUint32, 283 Value: value, 284 Column: coinusedfor.FieldUpdatedAt, 285 }) 286 } 287 if value, ok := cufu.mutation.AddedUpdatedAt(); ok { 288 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 289 Type: field.TypeUint32, 290 Value: value, 291 Column: coinusedfor.FieldUpdatedAt, 292 }) 293 } 294 if value, ok := cufu.mutation.DeletedAt(); ok { 295 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 296 Type: field.TypeUint32, 297 Value: value, 298 Column: coinusedfor.FieldDeletedAt, 299 }) 300 } 301 if value, ok := cufu.mutation.AddedDeletedAt(); ok { 302 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 303 Type: field.TypeUint32, 304 Value: value, 305 Column: coinusedfor.FieldDeletedAt, 306 }) 307 } 308 if value, ok := cufu.mutation.EntID(); ok { 309 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 310 Type: field.TypeUUID, 311 Value: value, 312 Column: coinusedfor.FieldEntID, 313 }) 314 } 315 if value, ok := cufu.mutation.CoinTypeID(); ok { 316 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 317 Type: field.TypeUUID, 318 Value: value, 319 Column: coinusedfor.FieldCoinTypeID, 320 }) 321 } 322 if cufu.mutation.CoinTypeIDCleared() { 323 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 324 Type: field.TypeUUID, 325 Column: coinusedfor.FieldCoinTypeID, 326 }) 327 } 328 if value, ok := cufu.mutation.UsedFor(); ok { 329 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 330 Type: field.TypeString, 331 Value: value, 332 Column: coinusedfor.FieldUsedFor, 333 }) 334 } 335 if cufu.mutation.UsedForCleared() { 336 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 337 Type: field.TypeString, 338 Column: coinusedfor.FieldUsedFor, 339 }) 340 } 341 if value, ok := cufu.mutation.Priority(); ok { 342 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 343 Type: field.TypeUint32, 344 Value: value, 345 Column: coinusedfor.FieldPriority, 346 }) 347 } 348 if value, ok := cufu.mutation.AddedPriority(); ok { 349 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 350 Type: field.TypeUint32, 351 Value: value, 352 Column: coinusedfor.FieldPriority, 353 }) 354 } 355 if cufu.mutation.PriorityCleared() { 356 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 357 Type: field.TypeUint32, 358 Column: coinusedfor.FieldPriority, 359 }) 360 } 361 _spec.Modifiers = cufu.modifiers 362 if n, err = sqlgraph.UpdateNodes(ctx, cufu.driver, _spec); err != nil { 363 if _, ok := err.(*sqlgraph.NotFoundError); ok { 364 err = &NotFoundError{coinusedfor.Label} 365 } else if sqlgraph.IsConstraintError(err) { 366 err = &ConstraintError{msg: err.Error(), wrap: err} 367 } 368 return 0, err 369 } 370 return n, nil 371 } 372 373 // CoinUsedForUpdateOne is the builder for updating a single CoinUsedFor entity. 374 type CoinUsedForUpdateOne struct { 375 config 376 fields []string 377 hooks []Hook 378 mutation *CoinUsedForMutation 379 modifiers []func(*sql.UpdateBuilder) 380 } 381 382 // SetCreatedAt sets the "created_at" field. 383 func (cufuo *CoinUsedForUpdateOne) SetCreatedAt(u uint32) *CoinUsedForUpdateOne { 384 cufuo.mutation.ResetCreatedAt() 385 cufuo.mutation.SetCreatedAt(u) 386 return cufuo 387 } 388 389 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 390 func (cufuo *CoinUsedForUpdateOne) SetNillableCreatedAt(u *uint32) *CoinUsedForUpdateOne { 391 if u != nil { 392 cufuo.SetCreatedAt(*u) 393 } 394 return cufuo 395 } 396 397 // AddCreatedAt adds u to the "created_at" field. 398 func (cufuo *CoinUsedForUpdateOne) AddCreatedAt(u int32) *CoinUsedForUpdateOne { 399 cufuo.mutation.AddCreatedAt(u) 400 return cufuo 401 } 402 403 // SetUpdatedAt sets the "updated_at" field. 404 func (cufuo *CoinUsedForUpdateOne) SetUpdatedAt(u uint32) *CoinUsedForUpdateOne { 405 cufuo.mutation.ResetUpdatedAt() 406 cufuo.mutation.SetUpdatedAt(u) 407 return cufuo 408 } 409 410 // AddUpdatedAt adds u to the "updated_at" field. 411 func (cufuo *CoinUsedForUpdateOne) AddUpdatedAt(u int32) *CoinUsedForUpdateOne { 412 cufuo.mutation.AddUpdatedAt(u) 413 return cufuo 414 } 415 416 // SetDeletedAt sets the "deleted_at" field. 417 func (cufuo *CoinUsedForUpdateOne) SetDeletedAt(u uint32) *CoinUsedForUpdateOne { 418 cufuo.mutation.ResetDeletedAt() 419 cufuo.mutation.SetDeletedAt(u) 420 return cufuo 421 } 422 423 // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. 424 func (cufuo *CoinUsedForUpdateOne) SetNillableDeletedAt(u *uint32) *CoinUsedForUpdateOne { 425 if u != nil { 426 cufuo.SetDeletedAt(*u) 427 } 428 return cufuo 429 } 430 431 // AddDeletedAt adds u to the "deleted_at" field. 432 func (cufuo *CoinUsedForUpdateOne) AddDeletedAt(u int32) *CoinUsedForUpdateOne { 433 cufuo.mutation.AddDeletedAt(u) 434 return cufuo 435 } 436 437 // SetEntID sets the "ent_id" field. 438 func (cufuo *CoinUsedForUpdateOne) SetEntID(u uuid.UUID) *CoinUsedForUpdateOne { 439 cufuo.mutation.SetEntID(u) 440 return cufuo 441 } 442 443 // SetNillableEntID sets the "ent_id" field if the given value is not nil. 444 func (cufuo *CoinUsedForUpdateOne) SetNillableEntID(u *uuid.UUID) *CoinUsedForUpdateOne { 445 if u != nil { 446 cufuo.SetEntID(*u) 447 } 448 return cufuo 449 } 450 451 // SetCoinTypeID sets the "coin_type_id" field. 452 func (cufuo *CoinUsedForUpdateOne) SetCoinTypeID(u uuid.UUID) *CoinUsedForUpdateOne { 453 cufuo.mutation.SetCoinTypeID(u) 454 return cufuo 455 } 456 457 // SetNillableCoinTypeID sets the "coin_type_id" field if the given value is not nil. 458 func (cufuo *CoinUsedForUpdateOne) SetNillableCoinTypeID(u *uuid.UUID) *CoinUsedForUpdateOne { 459 if u != nil { 460 cufuo.SetCoinTypeID(*u) 461 } 462 return cufuo 463 } 464 465 // ClearCoinTypeID clears the value of the "coin_type_id" field. 466 func (cufuo *CoinUsedForUpdateOne) ClearCoinTypeID() *CoinUsedForUpdateOne { 467 cufuo.mutation.ClearCoinTypeID() 468 return cufuo 469 } 470 471 // SetUsedFor sets the "used_for" field. 472 func (cufuo *CoinUsedForUpdateOne) SetUsedFor(s string) *CoinUsedForUpdateOne { 473 cufuo.mutation.SetUsedFor(s) 474 return cufuo 475 } 476 477 // SetNillableUsedFor sets the "used_for" field if the given value is not nil. 478 func (cufuo *CoinUsedForUpdateOne) SetNillableUsedFor(s *string) *CoinUsedForUpdateOne { 479 if s != nil { 480 cufuo.SetUsedFor(*s) 481 } 482 return cufuo 483 } 484 485 // ClearUsedFor clears the value of the "used_for" field. 486 func (cufuo *CoinUsedForUpdateOne) ClearUsedFor() *CoinUsedForUpdateOne { 487 cufuo.mutation.ClearUsedFor() 488 return cufuo 489 } 490 491 // SetPriority sets the "priority" field. 492 func (cufuo *CoinUsedForUpdateOne) SetPriority(u uint32) *CoinUsedForUpdateOne { 493 cufuo.mutation.ResetPriority() 494 cufuo.mutation.SetPriority(u) 495 return cufuo 496 } 497 498 // SetNillablePriority sets the "priority" field if the given value is not nil. 499 func (cufuo *CoinUsedForUpdateOne) SetNillablePriority(u *uint32) *CoinUsedForUpdateOne { 500 if u != nil { 501 cufuo.SetPriority(*u) 502 } 503 return cufuo 504 } 505 506 // AddPriority adds u to the "priority" field. 507 func (cufuo *CoinUsedForUpdateOne) AddPriority(u int32) *CoinUsedForUpdateOne { 508 cufuo.mutation.AddPriority(u) 509 return cufuo 510 } 511 512 // ClearPriority clears the value of the "priority" field. 513 func (cufuo *CoinUsedForUpdateOne) ClearPriority() *CoinUsedForUpdateOne { 514 cufuo.mutation.ClearPriority() 515 return cufuo 516 } 517 518 // Mutation returns the CoinUsedForMutation object of the builder. 519 func (cufuo *CoinUsedForUpdateOne) Mutation() *CoinUsedForMutation { 520 return cufuo.mutation 521 } 522 523 // Select allows selecting one or more fields (columns) of the returned entity. 524 // The default is selecting all fields defined in the entity schema. 525 func (cufuo *CoinUsedForUpdateOne) Select(field string, fields ...string) *CoinUsedForUpdateOne { 526 cufuo.fields = append([]string{field}, fields...) 527 return cufuo 528 } 529 530 // Save executes the query and returns the updated CoinUsedFor entity. 531 func (cufuo *CoinUsedForUpdateOne) Save(ctx context.Context) (*CoinUsedFor, error) { 532 var ( 533 err error 534 node *CoinUsedFor 535 ) 536 if err := cufuo.defaults(); err != nil { 537 return nil, err 538 } 539 if len(cufuo.hooks) == 0 { 540 node, err = cufuo.sqlSave(ctx) 541 } else { 542 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 543 mutation, ok := m.(*CoinUsedForMutation) 544 if !ok { 545 return nil, fmt.Errorf("unexpected mutation type %T", m) 546 } 547 cufuo.mutation = mutation 548 node, err = cufuo.sqlSave(ctx) 549 mutation.done = true 550 return node, err 551 }) 552 for i := len(cufuo.hooks) - 1; i >= 0; i-- { 553 if cufuo.hooks[i] == nil { 554 return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 555 } 556 mut = cufuo.hooks[i](mut) 557 } 558 v, err := mut.Mutate(ctx, cufuo.mutation) 559 if err != nil { 560 return nil, err 561 } 562 nv, ok := v.(*CoinUsedFor) 563 if !ok { 564 return nil, fmt.Errorf("unexpected node type %T returned from CoinUsedForMutation", v) 565 } 566 node = nv 567 } 568 return node, err 569 } 570 571 // SaveX is like Save, but panics if an error occurs. 572 func (cufuo *CoinUsedForUpdateOne) SaveX(ctx context.Context) *CoinUsedFor { 573 node, err := cufuo.Save(ctx) 574 if err != nil { 575 panic(err) 576 } 577 return node 578 } 579 580 // Exec executes the query on the entity. 581 func (cufuo *CoinUsedForUpdateOne) Exec(ctx context.Context) error { 582 _, err := cufuo.Save(ctx) 583 return err 584 } 585 586 // ExecX is like Exec, but panics if an error occurs. 587 func (cufuo *CoinUsedForUpdateOne) ExecX(ctx context.Context) { 588 if err := cufuo.Exec(ctx); err != nil { 589 panic(err) 590 } 591 } 592 593 // defaults sets the default values of the builder before save. 594 func (cufuo *CoinUsedForUpdateOne) defaults() error { 595 if _, ok := cufuo.mutation.UpdatedAt(); !ok { 596 if coinusedfor.UpdateDefaultUpdatedAt == nil { 597 return fmt.Errorf("ent: uninitialized coinusedfor.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") 598 } 599 v := coinusedfor.UpdateDefaultUpdatedAt() 600 cufuo.mutation.SetUpdatedAt(v) 601 } 602 return nil 603 } 604 605 // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. 606 func (cufuo *CoinUsedForUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CoinUsedForUpdateOne { 607 cufuo.modifiers = append(cufuo.modifiers, modifiers...) 608 return cufuo 609 } 610 611 func (cufuo *CoinUsedForUpdateOne) sqlSave(ctx context.Context) (_node *CoinUsedFor, err error) { 612 _spec := &sqlgraph.UpdateSpec{ 613 Node: &sqlgraph.NodeSpec{ 614 Table: coinusedfor.Table, 615 Columns: coinusedfor.Columns, 616 ID: &sqlgraph.FieldSpec{ 617 Type: field.TypeUint32, 618 Column: coinusedfor.FieldID, 619 }, 620 }, 621 } 622 id, ok := cufuo.mutation.ID() 623 if !ok { 624 return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CoinUsedFor.id" for update`)} 625 } 626 _spec.Node.ID.Value = id 627 if fields := cufuo.fields; len(fields) > 0 { 628 _spec.Node.Columns = make([]string, 0, len(fields)) 629 _spec.Node.Columns = append(_spec.Node.Columns, coinusedfor.FieldID) 630 for _, f := range fields { 631 if !coinusedfor.ValidColumn(f) { 632 return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} 633 } 634 if f != coinusedfor.FieldID { 635 _spec.Node.Columns = append(_spec.Node.Columns, f) 636 } 637 } 638 } 639 if ps := cufuo.mutation.predicates; len(ps) > 0 { 640 _spec.Predicate = func(selector *sql.Selector) { 641 for i := range ps { 642 ps[i](selector) 643 } 644 } 645 } 646 if value, ok := cufuo.mutation.CreatedAt(); ok { 647 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 648 Type: field.TypeUint32, 649 Value: value, 650 Column: coinusedfor.FieldCreatedAt, 651 }) 652 } 653 if value, ok := cufuo.mutation.AddedCreatedAt(); ok { 654 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 655 Type: field.TypeUint32, 656 Value: value, 657 Column: coinusedfor.FieldCreatedAt, 658 }) 659 } 660 if value, ok := cufuo.mutation.UpdatedAt(); ok { 661 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 662 Type: field.TypeUint32, 663 Value: value, 664 Column: coinusedfor.FieldUpdatedAt, 665 }) 666 } 667 if value, ok := cufuo.mutation.AddedUpdatedAt(); ok { 668 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 669 Type: field.TypeUint32, 670 Value: value, 671 Column: coinusedfor.FieldUpdatedAt, 672 }) 673 } 674 if value, ok := cufuo.mutation.DeletedAt(); ok { 675 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 676 Type: field.TypeUint32, 677 Value: value, 678 Column: coinusedfor.FieldDeletedAt, 679 }) 680 } 681 if value, ok := cufuo.mutation.AddedDeletedAt(); ok { 682 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 683 Type: field.TypeUint32, 684 Value: value, 685 Column: coinusedfor.FieldDeletedAt, 686 }) 687 } 688 if value, ok := cufuo.mutation.EntID(); ok { 689 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 690 Type: field.TypeUUID, 691 Value: value, 692 Column: coinusedfor.FieldEntID, 693 }) 694 } 695 if value, ok := cufuo.mutation.CoinTypeID(); ok { 696 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 697 Type: field.TypeUUID, 698 Value: value, 699 Column: coinusedfor.FieldCoinTypeID, 700 }) 701 } 702 if cufuo.mutation.CoinTypeIDCleared() { 703 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 704 Type: field.TypeUUID, 705 Column: coinusedfor.FieldCoinTypeID, 706 }) 707 } 708 if value, ok := cufuo.mutation.UsedFor(); ok { 709 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 710 Type: field.TypeString, 711 Value: value, 712 Column: coinusedfor.FieldUsedFor, 713 }) 714 } 715 if cufuo.mutation.UsedForCleared() { 716 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 717 Type: field.TypeString, 718 Column: coinusedfor.FieldUsedFor, 719 }) 720 } 721 if value, ok := cufuo.mutation.Priority(); ok { 722 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 723 Type: field.TypeUint32, 724 Value: value, 725 Column: coinusedfor.FieldPriority, 726 }) 727 } 728 if value, ok := cufuo.mutation.AddedPriority(); ok { 729 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 730 Type: field.TypeUint32, 731 Value: value, 732 Column: coinusedfor.FieldPriority, 733 }) 734 } 735 if cufuo.mutation.PriorityCleared() { 736 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 737 Type: field.TypeUint32, 738 Column: coinusedfor.FieldPriority, 739 }) 740 } 741 _spec.Modifiers = cufuo.modifiers 742 _node = &CoinUsedFor{config: cufuo.config} 743 _spec.Assign = _node.assignValues 744 _spec.ScanValues = _node.scanValues 745 if err = sqlgraph.UpdateNode(ctx, cufuo.driver, _spec); err != nil { 746 if _, ok := err.(*sqlgraph.NotFoundError); ok { 747 err = &NotFoundError{coinusedfor.Label} 748 } else if sqlgraph.IsConstraintError(err) { 749 err = &ConstraintError{msg: err.Error(), wrap: err} 750 } 751 return nil, err 752 } 753 return _node, nil 754 }