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