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