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