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