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