github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/coinfiat_create.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/coinfiat" 14 "github.com/google/uuid" 15 ) 16 17 // CoinFiatCreate is the builder for creating a CoinFiat entity. 18 type CoinFiatCreate struct { 19 config 20 mutation *CoinFiatMutation 21 hooks []Hook 22 conflict []sql.ConflictOption 23 } 24 25 // SetCreatedAt sets the "created_at" field. 26 func (cfc *CoinFiatCreate) SetCreatedAt(u uint32) *CoinFiatCreate { 27 cfc.mutation.SetCreatedAt(u) 28 return cfc 29 } 30 31 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 32 func (cfc *CoinFiatCreate) SetNillableCreatedAt(u *uint32) *CoinFiatCreate { 33 if u != nil { 34 cfc.SetCreatedAt(*u) 35 } 36 return cfc 37 } 38 39 // SetUpdatedAt sets the "updated_at" field. 40 func (cfc *CoinFiatCreate) SetUpdatedAt(u uint32) *CoinFiatCreate { 41 cfc.mutation.SetUpdatedAt(u) 42 return cfc 43 } 44 45 // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. 46 func (cfc *CoinFiatCreate) SetNillableUpdatedAt(u *uint32) *CoinFiatCreate { 47 if u != nil { 48 cfc.SetUpdatedAt(*u) 49 } 50 return cfc 51 } 52 53 // SetDeletedAt sets the "deleted_at" field. 54 func (cfc *CoinFiatCreate) SetDeletedAt(u uint32) *CoinFiatCreate { 55 cfc.mutation.SetDeletedAt(u) 56 return cfc 57 } 58 59 // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. 60 func (cfc *CoinFiatCreate) SetNillableDeletedAt(u *uint32) *CoinFiatCreate { 61 if u != nil { 62 cfc.SetDeletedAt(*u) 63 } 64 return cfc 65 } 66 67 // SetEntID sets the "ent_id" field. 68 func (cfc *CoinFiatCreate) SetEntID(u uuid.UUID) *CoinFiatCreate { 69 cfc.mutation.SetEntID(u) 70 return cfc 71 } 72 73 // SetNillableEntID sets the "ent_id" field if the given value is not nil. 74 func (cfc *CoinFiatCreate) SetNillableEntID(u *uuid.UUID) *CoinFiatCreate { 75 if u != nil { 76 cfc.SetEntID(*u) 77 } 78 return cfc 79 } 80 81 // SetCoinTypeID sets the "coin_type_id" field. 82 func (cfc *CoinFiatCreate) SetCoinTypeID(u uuid.UUID) *CoinFiatCreate { 83 cfc.mutation.SetCoinTypeID(u) 84 return cfc 85 } 86 87 // SetNillableCoinTypeID sets the "coin_type_id" field if the given value is not nil. 88 func (cfc *CoinFiatCreate) SetNillableCoinTypeID(u *uuid.UUID) *CoinFiatCreate { 89 if u != nil { 90 cfc.SetCoinTypeID(*u) 91 } 92 return cfc 93 } 94 95 // SetFiatID sets the "fiat_id" field. 96 func (cfc *CoinFiatCreate) SetFiatID(u uuid.UUID) *CoinFiatCreate { 97 cfc.mutation.SetFiatID(u) 98 return cfc 99 } 100 101 // SetNillableFiatID sets the "fiat_id" field if the given value is not nil. 102 func (cfc *CoinFiatCreate) SetNillableFiatID(u *uuid.UUID) *CoinFiatCreate { 103 if u != nil { 104 cfc.SetFiatID(*u) 105 } 106 return cfc 107 } 108 109 // SetFeedType sets the "feed_type" field. 110 func (cfc *CoinFiatCreate) SetFeedType(s string) *CoinFiatCreate { 111 cfc.mutation.SetFeedType(s) 112 return cfc 113 } 114 115 // SetNillableFeedType sets the "feed_type" field if the given value is not nil. 116 func (cfc *CoinFiatCreate) SetNillableFeedType(s *string) *CoinFiatCreate { 117 if s != nil { 118 cfc.SetFeedType(*s) 119 } 120 return cfc 121 } 122 123 // SetID sets the "id" field. 124 func (cfc *CoinFiatCreate) SetID(u uint32) *CoinFiatCreate { 125 cfc.mutation.SetID(u) 126 return cfc 127 } 128 129 // Mutation returns the CoinFiatMutation object of the builder. 130 func (cfc *CoinFiatCreate) Mutation() *CoinFiatMutation { 131 return cfc.mutation 132 } 133 134 // Save creates the CoinFiat in the database. 135 func (cfc *CoinFiatCreate) Save(ctx context.Context) (*CoinFiat, error) { 136 var ( 137 err error 138 node *CoinFiat 139 ) 140 if err := cfc.defaults(); err != nil { 141 return nil, err 142 } 143 if len(cfc.hooks) == 0 { 144 if err = cfc.check(); err != nil { 145 return nil, err 146 } 147 node, err = cfc.sqlSave(ctx) 148 } else { 149 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 150 mutation, ok := m.(*CoinFiatMutation) 151 if !ok { 152 return nil, fmt.Errorf("unexpected mutation type %T", m) 153 } 154 if err = cfc.check(); err != nil { 155 return nil, err 156 } 157 cfc.mutation = mutation 158 if node, err = cfc.sqlSave(ctx); err != nil { 159 return nil, err 160 } 161 mutation.id = &node.ID 162 mutation.done = true 163 return node, err 164 }) 165 for i := len(cfc.hooks) - 1; i >= 0; i-- { 166 if cfc.hooks[i] == nil { 167 return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 168 } 169 mut = cfc.hooks[i](mut) 170 } 171 v, err := mut.Mutate(ctx, cfc.mutation) 172 if err != nil { 173 return nil, err 174 } 175 nv, ok := v.(*CoinFiat) 176 if !ok { 177 return nil, fmt.Errorf("unexpected node type %T returned from CoinFiatMutation", v) 178 } 179 node = nv 180 } 181 return node, err 182 } 183 184 // SaveX calls Save and panics if Save returns an error. 185 func (cfc *CoinFiatCreate) SaveX(ctx context.Context) *CoinFiat { 186 v, err := cfc.Save(ctx) 187 if err != nil { 188 panic(err) 189 } 190 return v 191 } 192 193 // Exec executes the query. 194 func (cfc *CoinFiatCreate) Exec(ctx context.Context) error { 195 _, err := cfc.Save(ctx) 196 return err 197 } 198 199 // ExecX is like Exec, but panics if an error occurs. 200 func (cfc *CoinFiatCreate) ExecX(ctx context.Context) { 201 if err := cfc.Exec(ctx); err != nil { 202 panic(err) 203 } 204 } 205 206 // defaults sets the default values of the builder before save. 207 func (cfc *CoinFiatCreate) defaults() error { 208 if _, ok := cfc.mutation.CreatedAt(); !ok { 209 if coinfiat.DefaultCreatedAt == nil { 210 return fmt.Errorf("ent: uninitialized coinfiat.DefaultCreatedAt (forgotten import ent/runtime?)") 211 } 212 v := coinfiat.DefaultCreatedAt() 213 cfc.mutation.SetCreatedAt(v) 214 } 215 if _, ok := cfc.mutation.UpdatedAt(); !ok { 216 if coinfiat.DefaultUpdatedAt == nil { 217 return fmt.Errorf("ent: uninitialized coinfiat.DefaultUpdatedAt (forgotten import ent/runtime?)") 218 } 219 v := coinfiat.DefaultUpdatedAt() 220 cfc.mutation.SetUpdatedAt(v) 221 } 222 if _, ok := cfc.mutation.DeletedAt(); !ok { 223 if coinfiat.DefaultDeletedAt == nil { 224 return fmt.Errorf("ent: uninitialized coinfiat.DefaultDeletedAt (forgotten import ent/runtime?)") 225 } 226 v := coinfiat.DefaultDeletedAt() 227 cfc.mutation.SetDeletedAt(v) 228 } 229 if _, ok := cfc.mutation.EntID(); !ok { 230 if coinfiat.DefaultEntID == nil { 231 return fmt.Errorf("ent: uninitialized coinfiat.DefaultEntID (forgotten import ent/runtime?)") 232 } 233 v := coinfiat.DefaultEntID() 234 cfc.mutation.SetEntID(v) 235 } 236 if _, ok := cfc.mutation.CoinTypeID(); !ok { 237 if coinfiat.DefaultCoinTypeID == nil { 238 return fmt.Errorf("ent: uninitialized coinfiat.DefaultCoinTypeID (forgotten import ent/runtime?)") 239 } 240 v := coinfiat.DefaultCoinTypeID() 241 cfc.mutation.SetCoinTypeID(v) 242 } 243 if _, ok := cfc.mutation.FiatID(); !ok { 244 if coinfiat.DefaultFiatID == nil { 245 return fmt.Errorf("ent: uninitialized coinfiat.DefaultFiatID (forgotten import ent/runtime?)") 246 } 247 v := coinfiat.DefaultFiatID() 248 cfc.mutation.SetFiatID(v) 249 } 250 if _, ok := cfc.mutation.FeedType(); !ok { 251 v := coinfiat.DefaultFeedType 252 cfc.mutation.SetFeedType(v) 253 } 254 return nil 255 } 256 257 // check runs all checks and user-defined validators on the builder. 258 func (cfc *CoinFiatCreate) check() error { 259 if _, ok := cfc.mutation.CreatedAt(); !ok { 260 return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "CoinFiat.created_at"`)} 261 } 262 if _, ok := cfc.mutation.UpdatedAt(); !ok { 263 return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "CoinFiat.updated_at"`)} 264 } 265 if _, ok := cfc.mutation.DeletedAt(); !ok { 266 return &ValidationError{Name: "deleted_at", err: errors.New(`ent: missing required field "CoinFiat.deleted_at"`)} 267 } 268 if _, ok := cfc.mutation.EntID(); !ok { 269 return &ValidationError{Name: "ent_id", err: errors.New(`ent: missing required field "CoinFiat.ent_id"`)} 270 } 271 return nil 272 } 273 274 func (cfc *CoinFiatCreate) sqlSave(ctx context.Context) (*CoinFiat, error) { 275 _node, _spec := cfc.createSpec() 276 if err := sqlgraph.CreateNode(ctx, cfc.driver, _spec); err != nil { 277 if sqlgraph.IsConstraintError(err) { 278 err = &ConstraintError{msg: err.Error(), wrap: err} 279 } 280 return nil, err 281 } 282 if _spec.ID.Value != _node.ID { 283 id := _spec.ID.Value.(int64) 284 _node.ID = uint32(id) 285 } 286 return _node, nil 287 } 288 289 func (cfc *CoinFiatCreate) createSpec() (*CoinFiat, *sqlgraph.CreateSpec) { 290 var ( 291 _node = &CoinFiat{config: cfc.config} 292 _spec = &sqlgraph.CreateSpec{ 293 Table: coinfiat.Table, 294 ID: &sqlgraph.FieldSpec{ 295 Type: field.TypeUint32, 296 Column: coinfiat.FieldID, 297 }, 298 } 299 ) 300 _spec.OnConflict = cfc.conflict 301 if id, ok := cfc.mutation.ID(); ok { 302 _node.ID = id 303 _spec.ID.Value = id 304 } 305 if value, ok := cfc.mutation.CreatedAt(); ok { 306 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 307 Type: field.TypeUint32, 308 Value: value, 309 Column: coinfiat.FieldCreatedAt, 310 }) 311 _node.CreatedAt = value 312 } 313 if value, ok := cfc.mutation.UpdatedAt(); ok { 314 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 315 Type: field.TypeUint32, 316 Value: value, 317 Column: coinfiat.FieldUpdatedAt, 318 }) 319 _node.UpdatedAt = value 320 } 321 if value, ok := cfc.mutation.DeletedAt(); ok { 322 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 323 Type: field.TypeUint32, 324 Value: value, 325 Column: coinfiat.FieldDeletedAt, 326 }) 327 _node.DeletedAt = value 328 } 329 if value, ok := cfc.mutation.EntID(); ok { 330 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 331 Type: field.TypeUUID, 332 Value: value, 333 Column: coinfiat.FieldEntID, 334 }) 335 _node.EntID = value 336 } 337 if value, ok := cfc.mutation.CoinTypeID(); ok { 338 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 339 Type: field.TypeUUID, 340 Value: value, 341 Column: coinfiat.FieldCoinTypeID, 342 }) 343 _node.CoinTypeID = value 344 } 345 if value, ok := cfc.mutation.FiatID(); ok { 346 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 347 Type: field.TypeUUID, 348 Value: value, 349 Column: coinfiat.FieldFiatID, 350 }) 351 _node.FiatID = value 352 } 353 if value, ok := cfc.mutation.FeedType(); ok { 354 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 355 Type: field.TypeString, 356 Value: value, 357 Column: coinfiat.FieldFeedType, 358 }) 359 _node.FeedType = value 360 } 361 return _node, _spec 362 } 363 364 // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause 365 // of the `INSERT` statement. For example: 366 // 367 // client.CoinFiat.Create(). 368 // SetCreatedAt(v). 369 // OnConflict( 370 // // Update the row with the new values 371 // // the was proposed for insertion. 372 // sql.ResolveWithNewValues(), 373 // ). 374 // // Override some of the fields with custom 375 // // update values. 376 // Update(func(u *ent.CoinFiatUpsert) { 377 // SetCreatedAt(v+v). 378 // }). 379 // Exec(ctx) 380 // 381 func (cfc *CoinFiatCreate) OnConflict(opts ...sql.ConflictOption) *CoinFiatUpsertOne { 382 cfc.conflict = opts 383 return &CoinFiatUpsertOne{ 384 create: cfc, 385 } 386 } 387 388 // OnConflictColumns calls `OnConflict` and configures the columns 389 // as conflict target. Using this option is equivalent to using: 390 // 391 // client.CoinFiat.Create(). 392 // OnConflict(sql.ConflictColumns(columns...)). 393 // Exec(ctx) 394 // 395 func (cfc *CoinFiatCreate) OnConflictColumns(columns ...string) *CoinFiatUpsertOne { 396 cfc.conflict = append(cfc.conflict, sql.ConflictColumns(columns...)) 397 return &CoinFiatUpsertOne{ 398 create: cfc, 399 } 400 } 401 402 type ( 403 // CoinFiatUpsertOne is the builder for "upsert"-ing 404 // one CoinFiat node. 405 CoinFiatUpsertOne struct { 406 create *CoinFiatCreate 407 } 408 409 // CoinFiatUpsert is the "OnConflict" setter. 410 CoinFiatUpsert struct { 411 *sql.UpdateSet 412 } 413 ) 414 415 // SetCreatedAt sets the "created_at" field. 416 func (u *CoinFiatUpsert) SetCreatedAt(v uint32) *CoinFiatUpsert { 417 u.Set(coinfiat.FieldCreatedAt, v) 418 return u 419 } 420 421 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 422 func (u *CoinFiatUpsert) UpdateCreatedAt() *CoinFiatUpsert { 423 u.SetExcluded(coinfiat.FieldCreatedAt) 424 return u 425 } 426 427 // AddCreatedAt adds v to the "created_at" field. 428 func (u *CoinFiatUpsert) AddCreatedAt(v uint32) *CoinFiatUpsert { 429 u.Add(coinfiat.FieldCreatedAt, v) 430 return u 431 } 432 433 // SetUpdatedAt sets the "updated_at" field. 434 func (u *CoinFiatUpsert) SetUpdatedAt(v uint32) *CoinFiatUpsert { 435 u.Set(coinfiat.FieldUpdatedAt, v) 436 return u 437 } 438 439 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 440 func (u *CoinFiatUpsert) UpdateUpdatedAt() *CoinFiatUpsert { 441 u.SetExcluded(coinfiat.FieldUpdatedAt) 442 return u 443 } 444 445 // AddUpdatedAt adds v to the "updated_at" field. 446 func (u *CoinFiatUpsert) AddUpdatedAt(v uint32) *CoinFiatUpsert { 447 u.Add(coinfiat.FieldUpdatedAt, v) 448 return u 449 } 450 451 // SetDeletedAt sets the "deleted_at" field. 452 func (u *CoinFiatUpsert) SetDeletedAt(v uint32) *CoinFiatUpsert { 453 u.Set(coinfiat.FieldDeletedAt, v) 454 return u 455 } 456 457 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 458 func (u *CoinFiatUpsert) UpdateDeletedAt() *CoinFiatUpsert { 459 u.SetExcluded(coinfiat.FieldDeletedAt) 460 return u 461 } 462 463 // AddDeletedAt adds v to the "deleted_at" field. 464 func (u *CoinFiatUpsert) AddDeletedAt(v uint32) *CoinFiatUpsert { 465 u.Add(coinfiat.FieldDeletedAt, v) 466 return u 467 } 468 469 // SetEntID sets the "ent_id" field. 470 func (u *CoinFiatUpsert) SetEntID(v uuid.UUID) *CoinFiatUpsert { 471 u.Set(coinfiat.FieldEntID, v) 472 return u 473 } 474 475 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 476 func (u *CoinFiatUpsert) UpdateEntID() *CoinFiatUpsert { 477 u.SetExcluded(coinfiat.FieldEntID) 478 return u 479 } 480 481 // SetCoinTypeID sets the "coin_type_id" field. 482 func (u *CoinFiatUpsert) SetCoinTypeID(v uuid.UUID) *CoinFiatUpsert { 483 u.Set(coinfiat.FieldCoinTypeID, v) 484 return u 485 } 486 487 // UpdateCoinTypeID sets the "coin_type_id" field to the value that was provided on create. 488 func (u *CoinFiatUpsert) UpdateCoinTypeID() *CoinFiatUpsert { 489 u.SetExcluded(coinfiat.FieldCoinTypeID) 490 return u 491 } 492 493 // ClearCoinTypeID clears the value of the "coin_type_id" field. 494 func (u *CoinFiatUpsert) ClearCoinTypeID() *CoinFiatUpsert { 495 u.SetNull(coinfiat.FieldCoinTypeID) 496 return u 497 } 498 499 // SetFiatID sets the "fiat_id" field. 500 func (u *CoinFiatUpsert) SetFiatID(v uuid.UUID) *CoinFiatUpsert { 501 u.Set(coinfiat.FieldFiatID, v) 502 return u 503 } 504 505 // UpdateFiatID sets the "fiat_id" field to the value that was provided on create. 506 func (u *CoinFiatUpsert) UpdateFiatID() *CoinFiatUpsert { 507 u.SetExcluded(coinfiat.FieldFiatID) 508 return u 509 } 510 511 // ClearFiatID clears the value of the "fiat_id" field. 512 func (u *CoinFiatUpsert) ClearFiatID() *CoinFiatUpsert { 513 u.SetNull(coinfiat.FieldFiatID) 514 return u 515 } 516 517 // SetFeedType sets the "feed_type" field. 518 func (u *CoinFiatUpsert) SetFeedType(v string) *CoinFiatUpsert { 519 u.Set(coinfiat.FieldFeedType, v) 520 return u 521 } 522 523 // UpdateFeedType sets the "feed_type" field to the value that was provided on create. 524 func (u *CoinFiatUpsert) UpdateFeedType() *CoinFiatUpsert { 525 u.SetExcluded(coinfiat.FieldFeedType) 526 return u 527 } 528 529 // ClearFeedType clears the value of the "feed_type" field. 530 func (u *CoinFiatUpsert) ClearFeedType() *CoinFiatUpsert { 531 u.SetNull(coinfiat.FieldFeedType) 532 return u 533 } 534 535 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. 536 // Using this option is equivalent to using: 537 // 538 // client.CoinFiat.Create(). 539 // OnConflict( 540 // sql.ResolveWithNewValues(), 541 // sql.ResolveWith(func(u *sql.UpdateSet) { 542 // u.SetIgnore(coinfiat.FieldID) 543 // }), 544 // ). 545 // Exec(ctx) 546 // 547 func (u *CoinFiatUpsertOne) UpdateNewValues() *CoinFiatUpsertOne { 548 u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) 549 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { 550 if _, exists := u.create.mutation.ID(); exists { 551 s.SetIgnore(coinfiat.FieldID) 552 } 553 })) 554 return u 555 } 556 557 // Ignore sets each column to itself in case of conflict. 558 // Using this option is equivalent to using: 559 // 560 // client.CoinFiat.Create(). 561 // OnConflict(sql.ResolveWithIgnore()). 562 // Exec(ctx) 563 // 564 func (u *CoinFiatUpsertOne) Ignore() *CoinFiatUpsertOne { 565 u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) 566 return u 567 } 568 569 // DoNothing configures the conflict_action to `DO NOTHING`. 570 // Supported only by SQLite and PostgreSQL. 571 func (u *CoinFiatUpsertOne) DoNothing() *CoinFiatUpsertOne { 572 u.create.conflict = append(u.create.conflict, sql.DoNothing()) 573 return u 574 } 575 576 // Update allows overriding fields `UPDATE` values. See the CoinFiatCreate.OnConflict 577 // documentation for more info. 578 func (u *CoinFiatUpsertOne) Update(set func(*CoinFiatUpsert)) *CoinFiatUpsertOne { 579 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { 580 set(&CoinFiatUpsert{UpdateSet: update}) 581 })) 582 return u 583 } 584 585 // SetCreatedAt sets the "created_at" field. 586 func (u *CoinFiatUpsertOne) SetCreatedAt(v uint32) *CoinFiatUpsertOne { 587 return u.Update(func(s *CoinFiatUpsert) { 588 s.SetCreatedAt(v) 589 }) 590 } 591 592 // AddCreatedAt adds v to the "created_at" field. 593 func (u *CoinFiatUpsertOne) AddCreatedAt(v uint32) *CoinFiatUpsertOne { 594 return u.Update(func(s *CoinFiatUpsert) { 595 s.AddCreatedAt(v) 596 }) 597 } 598 599 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 600 func (u *CoinFiatUpsertOne) UpdateCreatedAt() *CoinFiatUpsertOne { 601 return u.Update(func(s *CoinFiatUpsert) { 602 s.UpdateCreatedAt() 603 }) 604 } 605 606 // SetUpdatedAt sets the "updated_at" field. 607 func (u *CoinFiatUpsertOne) SetUpdatedAt(v uint32) *CoinFiatUpsertOne { 608 return u.Update(func(s *CoinFiatUpsert) { 609 s.SetUpdatedAt(v) 610 }) 611 } 612 613 // AddUpdatedAt adds v to the "updated_at" field. 614 func (u *CoinFiatUpsertOne) AddUpdatedAt(v uint32) *CoinFiatUpsertOne { 615 return u.Update(func(s *CoinFiatUpsert) { 616 s.AddUpdatedAt(v) 617 }) 618 } 619 620 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 621 func (u *CoinFiatUpsertOne) UpdateUpdatedAt() *CoinFiatUpsertOne { 622 return u.Update(func(s *CoinFiatUpsert) { 623 s.UpdateUpdatedAt() 624 }) 625 } 626 627 // SetDeletedAt sets the "deleted_at" field. 628 func (u *CoinFiatUpsertOne) SetDeletedAt(v uint32) *CoinFiatUpsertOne { 629 return u.Update(func(s *CoinFiatUpsert) { 630 s.SetDeletedAt(v) 631 }) 632 } 633 634 // AddDeletedAt adds v to the "deleted_at" field. 635 func (u *CoinFiatUpsertOne) AddDeletedAt(v uint32) *CoinFiatUpsertOne { 636 return u.Update(func(s *CoinFiatUpsert) { 637 s.AddDeletedAt(v) 638 }) 639 } 640 641 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 642 func (u *CoinFiatUpsertOne) UpdateDeletedAt() *CoinFiatUpsertOne { 643 return u.Update(func(s *CoinFiatUpsert) { 644 s.UpdateDeletedAt() 645 }) 646 } 647 648 // SetEntID sets the "ent_id" field. 649 func (u *CoinFiatUpsertOne) SetEntID(v uuid.UUID) *CoinFiatUpsertOne { 650 return u.Update(func(s *CoinFiatUpsert) { 651 s.SetEntID(v) 652 }) 653 } 654 655 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 656 func (u *CoinFiatUpsertOne) UpdateEntID() *CoinFiatUpsertOne { 657 return u.Update(func(s *CoinFiatUpsert) { 658 s.UpdateEntID() 659 }) 660 } 661 662 // SetCoinTypeID sets the "coin_type_id" field. 663 func (u *CoinFiatUpsertOne) SetCoinTypeID(v uuid.UUID) *CoinFiatUpsertOne { 664 return u.Update(func(s *CoinFiatUpsert) { 665 s.SetCoinTypeID(v) 666 }) 667 } 668 669 // UpdateCoinTypeID sets the "coin_type_id" field to the value that was provided on create. 670 func (u *CoinFiatUpsertOne) UpdateCoinTypeID() *CoinFiatUpsertOne { 671 return u.Update(func(s *CoinFiatUpsert) { 672 s.UpdateCoinTypeID() 673 }) 674 } 675 676 // ClearCoinTypeID clears the value of the "coin_type_id" field. 677 func (u *CoinFiatUpsertOne) ClearCoinTypeID() *CoinFiatUpsertOne { 678 return u.Update(func(s *CoinFiatUpsert) { 679 s.ClearCoinTypeID() 680 }) 681 } 682 683 // SetFiatID sets the "fiat_id" field. 684 func (u *CoinFiatUpsertOne) SetFiatID(v uuid.UUID) *CoinFiatUpsertOne { 685 return u.Update(func(s *CoinFiatUpsert) { 686 s.SetFiatID(v) 687 }) 688 } 689 690 // UpdateFiatID sets the "fiat_id" field to the value that was provided on create. 691 func (u *CoinFiatUpsertOne) UpdateFiatID() *CoinFiatUpsertOne { 692 return u.Update(func(s *CoinFiatUpsert) { 693 s.UpdateFiatID() 694 }) 695 } 696 697 // ClearFiatID clears the value of the "fiat_id" field. 698 func (u *CoinFiatUpsertOne) ClearFiatID() *CoinFiatUpsertOne { 699 return u.Update(func(s *CoinFiatUpsert) { 700 s.ClearFiatID() 701 }) 702 } 703 704 // SetFeedType sets the "feed_type" field. 705 func (u *CoinFiatUpsertOne) SetFeedType(v string) *CoinFiatUpsertOne { 706 return u.Update(func(s *CoinFiatUpsert) { 707 s.SetFeedType(v) 708 }) 709 } 710 711 // UpdateFeedType sets the "feed_type" field to the value that was provided on create. 712 func (u *CoinFiatUpsertOne) UpdateFeedType() *CoinFiatUpsertOne { 713 return u.Update(func(s *CoinFiatUpsert) { 714 s.UpdateFeedType() 715 }) 716 } 717 718 // ClearFeedType clears the value of the "feed_type" field. 719 func (u *CoinFiatUpsertOne) ClearFeedType() *CoinFiatUpsertOne { 720 return u.Update(func(s *CoinFiatUpsert) { 721 s.ClearFeedType() 722 }) 723 } 724 725 // Exec executes the query. 726 func (u *CoinFiatUpsertOne) Exec(ctx context.Context) error { 727 if len(u.create.conflict) == 0 { 728 return errors.New("ent: missing options for CoinFiatCreate.OnConflict") 729 } 730 return u.create.Exec(ctx) 731 } 732 733 // ExecX is like Exec, but panics if an error occurs. 734 func (u *CoinFiatUpsertOne) ExecX(ctx context.Context) { 735 if err := u.create.Exec(ctx); err != nil { 736 panic(err) 737 } 738 } 739 740 // Exec executes the UPSERT query and returns the inserted/updated ID. 741 func (u *CoinFiatUpsertOne) ID(ctx context.Context) (id uint32, err error) { 742 node, err := u.create.Save(ctx) 743 if err != nil { 744 return id, err 745 } 746 return node.ID, nil 747 } 748 749 // IDX is like ID, but panics if an error occurs. 750 func (u *CoinFiatUpsertOne) IDX(ctx context.Context) uint32 { 751 id, err := u.ID(ctx) 752 if err != nil { 753 panic(err) 754 } 755 return id 756 } 757 758 // CoinFiatCreateBulk is the builder for creating many CoinFiat entities in bulk. 759 type CoinFiatCreateBulk struct { 760 config 761 builders []*CoinFiatCreate 762 conflict []sql.ConflictOption 763 } 764 765 // Save creates the CoinFiat entities in the database. 766 func (cfcb *CoinFiatCreateBulk) Save(ctx context.Context) ([]*CoinFiat, error) { 767 specs := make([]*sqlgraph.CreateSpec, len(cfcb.builders)) 768 nodes := make([]*CoinFiat, len(cfcb.builders)) 769 mutators := make([]Mutator, len(cfcb.builders)) 770 for i := range cfcb.builders { 771 func(i int, root context.Context) { 772 builder := cfcb.builders[i] 773 builder.defaults() 774 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 775 mutation, ok := m.(*CoinFiatMutation) 776 if !ok { 777 return nil, fmt.Errorf("unexpected mutation type %T", m) 778 } 779 if err := builder.check(); err != nil { 780 return nil, err 781 } 782 builder.mutation = mutation 783 nodes[i], specs[i] = builder.createSpec() 784 var err error 785 if i < len(mutators)-1 { 786 _, err = mutators[i+1].Mutate(root, cfcb.builders[i+1].mutation) 787 } else { 788 spec := &sqlgraph.BatchCreateSpec{Nodes: specs} 789 spec.OnConflict = cfcb.conflict 790 // Invoke the actual operation on the latest mutation in the chain. 791 if err = sqlgraph.BatchCreate(ctx, cfcb.driver, spec); err != nil { 792 if sqlgraph.IsConstraintError(err) { 793 err = &ConstraintError{msg: err.Error(), wrap: err} 794 } 795 } 796 } 797 if err != nil { 798 return nil, err 799 } 800 mutation.id = &nodes[i].ID 801 if specs[i].ID.Value != nil && nodes[i].ID == 0 { 802 id := specs[i].ID.Value.(int64) 803 nodes[i].ID = uint32(id) 804 } 805 mutation.done = true 806 return nodes[i], nil 807 }) 808 for i := len(builder.hooks) - 1; i >= 0; i-- { 809 mut = builder.hooks[i](mut) 810 } 811 mutators[i] = mut 812 }(i, ctx) 813 } 814 if len(mutators) > 0 { 815 if _, err := mutators[0].Mutate(ctx, cfcb.builders[0].mutation); err != nil { 816 return nil, err 817 } 818 } 819 return nodes, nil 820 } 821 822 // SaveX is like Save, but panics if an error occurs. 823 func (cfcb *CoinFiatCreateBulk) SaveX(ctx context.Context) []*CoinFiat { 824 v, err := cfcb.Save(ctx) 825 if err != nil { 826 panic(err) 827 } 828 return v 829 } 830 831 // Exec executes the query. 832 func (cfcb *CoinFiatCreateBulk) Exec(ctx context.Context) error { 833 _, err := cfcb.Save(ctx) 834 return err 835 } 836 837 // ExecX is like Exec, but panics if an error occurs. 838 func (cfcb *CoinFiatCreateBulk) ExecX(ctx context.Context) { 839 if err := cfcb.Exec(ctx); err != nil { 840 panic(err) 841 } 842 } 843 844 // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause 845 // of the `INSERT` statement. For example: 846 // 847 // client.CoinFiat.CreateBulk(builders...). 848 // OnConflict( 849 // // Update the row with the new values 850 // // the was proposed for insertion. 851 // sql.ResolveWithNewValues(), 852 // ). 853 // // Override some of the fields with custom 854 // // update values. 855 // Update(func(u *ent.CoinFiatUpsert) { 856 // SetCreatedAt(v+v). 857 // }). 858 // Exec(ctx) 859 // 860 func (cfcb *CoinFiatCreateBulk) OnConflict(opts ...sql.ConflictOption) *CoinFiatUpsertBulk { 861 cfcb.conflict = opts 862 return &CoinFiatUpsertBulk{ 863 create: cfcb, 864 } 865 } 866 867 // OnConflictColumns calls `OnConflict` and configures the columns 868 // as conflict target. Using this option is equivalent to using: 869 // 870 // client.CoinFiat.Create(). 871 // OnConflict(sql.ConflictColumns(columns...)). 872 // Exec(ctx) 873 // 874 func (cfcb *CoinFiatCreateBulk) OnConflictColumns(columns ...string) *CoinFiatUpsertBulk { 875 cfcb.conflict = append(cfcb.conflict, sql.ConflictColumns(columns...)) 876 return &CoinFiatUpsertBulk{ 877 create: cfcb, 878 } 879 } 880 881 // CoinFiatUpsertBulk is the builder for "upsert"-ing 882 // a bulk of CoinFiat nodes. 883 type CoinFiatUpsertBulk struct { 884 create *CoinFiatCreateBulk 885 } 886 887 // UpdateNewValues updates the mutable fields using the new values that 888 // were set on create. Using this option is equivalent to using: 889 // 890 // client.CoinFiat.Create(). 891 // OnConflict( 892 // sql.ResolveWithNewValues(), 893 // sql.ResolveWith(func(u *sql.UpdateSet) { 894 // u.SetIgnore(coinfiat.FieldID) 895 // }), 896 // ). 897 // Exec(ctx) 898 // 899 func (u *CoinFiatUpsertBulk) UpdateNewValues() *CoinFiatUpsertBulk { 900 u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) 901 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { 902 for _, b := range u.create.builders { 903 if _, exists := b.mutation.ID(); exists { 904 s.SetIgnore(coinfiat.FieldID) 905 return 906 } 907 } 908 })) 909 return u 910 } 911 912 // Ignore sets each column to itself in case of conflict. 913 // Using this option is equivalent to using: 914 // 915 // client.CoinFiat.Create(). 916 // OnConflict(sql.ResolveWithIgnore()). 917 // Exec(ctx) 918 // 919 func (u *CoinFiatUpsertBulk) Ignore() *CoinFiatUpsertBulk { 920 u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) 921 return u 922 } 923 924 // DoNothing configures the conflict_action to `DO NOTHING`. 925 // Supported only by SQLite and PostgreSQL. 926 func (u *CoinFiatUpsertBulk) DoNothing() *CoinFiatUpsertBulk { 927 u.create.conflict = append(u.create.conflict, sql.DoNothing()) 928 return u 929 } 930 931 // Update allows overriding fields `UPDATE` values. See the CoinFiatCreateBulk.OnConflict 932 // documentation for more info. 933 func (u *CoinFiatUpsertBulk) Update(set func(*CoinFiatUpsert)) *CoinFiatUpsertBulk { 934 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { 935 set(&CoinFiatUpsert{UpdateSet: update}) 936 })) 937 return u 938 } 939 940 // SetCreatedAt sets the "created_at" field. 941 func (u *CoinFiatUpsertBulk) SetCreatedAt(v uint32) *CoinFiatUpsertBulk { 942 return u.Update(func(s *CoinFiatUpsert) { 943 s.SetCreatedAt(v) 944 }) 945 } 946 947 // AddCreatedAt adds v to the "created_at" field. 948 func (u *CoinFiatUpsertBulk) AddCreatedAt(v uint32) *CoinFiatUpsertBulk { 949 return u.Update(func(s *CoinFiatUpsert) { 950 s.AddCreatedAt(v) 951 }) 952 } 953 954 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 955 func (u *CoinFiatUpsertBulk) UpdateCreatedAt() *CoinFiatUpsertBulk { 956 return u.Update(func(s *CoinFiatUpsert) { 957 s.UpdateCreatedAt() 958 }) 959 } 960 961 // SetUpdatedAt sets the "updated_at" field. 962 func (u *CoinFiatUpsertBulk) SetUpdatedAt(v uint32) *CoinFiatUpsertBulk { 963 return u.Update(func(s *CoinFiatUpsert) { 964 s.SetUpdatedAt(v) 965 }) 966 } 967 968 // AddUpdatedAt adds v to the "updated_at" field. 969 func (u *CoinFiatUpsertBulk) AddUpdatedAt(v uint32) *CoinFiatUpsertBulk { 970 return u.Update(func(s *CoinFiatUpsert) { 971 s.AddUpdatedAt(v) 972 }) 973 } 974 975 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 976 func (u *CoinFiatUpsertBulk) UpdateUpdatedAt() *CoinFiatUpsertBulk { 977 return u.Update(func(s *CoinFiatUpsert) { 978 s.UpdateUpdatedAt() 979 }) 980 } 981 982 // SetDeletedAt sets the "deleted_at" field. 983 func (u *CoinFiatUpsertBulk) SetDeletedAt(v uint32) *CoinFiatUpsertBulk { 984 return u.Update(func(s *CoinFiatUpsert) { 985 s.SetDeletedAt(v) 986 }) 987 } 988 989 // AddDeletedAt adds v to the "deleted_at" field. 990 func (u *CoinFiatUpsertBulk) AddDeletedAt(v uint32) *CoinFiatUpsertBulk { 991 return u.Update(func(s *CoinFiatUpsert) { 992 s.AddDeletedAt(v) 993 }) 994 } 995 996 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 997 func (u *CoinFiatUpsertBulk) UpdateDeletedAt() *CoinFiatUpsertBulk { 998 return u.Update(func(s *CoinFiatUpsert) { 999 s.UpdateDeletedAt() 1000 }) 1001 } 1002 1003 // SetEntID sets the "ent_id" field. 1004 func (u *CoinFiatUpsertBulk) SetEntID(v uuid.UUID) *CoinFiatUpsertBulk { 1005 return u.Update(func(s *CoinFiatUpsert) { 1006 s.SetEntID(v) 1007 }) 1008 } 1009 1010 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 1011 func (u *CoinFiatUpsertBulk) UpdateEntID() *CoinFiatUpsertBulk { 1012 return u.Update(func(s *CoinFiatUpsert) { 1013 s.UpdateEntID() 1014 }) 1015 } 1016 1017 // SetCoinTypeID sets the "coin_type_id" field. 1018 func (u *CoinFiatUpsertBulk) SetCoinTypeID(v uuid.UUID) *CoinFiatUpsertBulk { 1019 return u.Update(func(s *CoinFiatUpsert) { 1020 s.SetCoinTypeID(v) 1021 }) 1022 } 1023 1024 // UpdateCoinTypeID sets the "coin_type_id" field to the value that was provided on create. 1025 func (u *CoinFiatUpsertBulk) UpdateCoinTypeID() *CoinFiatUpsertBulk { 1026 return u.Update(func(s *CoinFiatUpsert) { 1027 s.UpdateCoinTypeID() 1028 }) 1029 } 1030 1031 // ClearCoinTypeID clears the value of the "coin_type_id" field. 1032 func (u *CoinFiatUpsertBulk) ClearCoinTypeID() *CoinFiatUpsertBulk { 1033 return u.Update(func(s *CoinFiatUpsert) { 1034 s.ClearCoinTypeID() 1035 }) 1036 } 1037 1038 // SetFiatID sets the "fiat_id" field. 1039 func (u *CoinFiatUpsertBulk) SetFiatID(v uuid.UUID) *CoinFiatUpsertBulk { 1040 return u.Update(func(s *CoinFiatUpsert) { 1041 s.SetFiatID(v) 1042 }) 1043 } 1044 1045 // UpdateFiatID sets the "fiat_id" field to the value that was provided on create. 1046 func (u *CoinFiatUpsertBulk) UpdateFiatID() *CoinFiatUpsertBulk { 1047 return u.Update(func(s *CoinFiatUpsert) { 1048 s.UpdateFiatID() 1049 }) 1050 } 1051 1052 // ClearFiatID clears the value of the "fiat_id" field. 1053 func (u *CoinFiatUpsertBulk) ClearFiatID() *CoinFiatUpsertBulk { 1054 return u.Update(func(s *CoinFiatUpsert) { 1055 s.ClearFiatID() 1056 }) 1057 } 1058 1059 // SetFeedType sets the "feed_type" field. 1060 func (u *CoinFiatUpsertBulk) SetFeedType(v string) *CoinFiatUpsertBulk { 1061 return u.Update(func(s *CoinFiatUpsert) { 1062 s.SetFeedType(v) 1063 }) 1064 } 1065 1066 // UpdateFeedType sets the "feed_type" field to the value that was provided on create. 1067 func (u *CoinFiatUpsertBulk) UpdateFeedType() *CoinFiatUpsertBulk { 1068 return u.Update(func(s *CoinFiatUpsert) { 1069 s.UpdateFeedType() 1070 }) 1071 } 1072 1073 // ClearFeedType clears the value of the "feed_type" field. 1074 func (u *CoinFiatUpsertBulk) ClearFeedType() *CoinFiatUpsertBulk { 1075 return u.Update(func(s *CoinFiatUpsert) { 1076 s.ClearFeedType() 1077 }) 1078 } 1079 1080 // Exec executes the query. 1081 func (u *CoinFiatUpsertBulk) Exec(ctx context.Context) error { 1082 for i, b := range u.create.builders { 1083 if len(b.conflict) != 0 { 1084 return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the CoinFiatCreateBulk instead", i) 1085 } 1086 } 1087 if len(u.create.conflict) == 0 { 1088 return errors.New("ent: missing options for CoinFiatCreateBulk.OnConflict") 1089 } 1090 return u.create.Exec(ctx) 1091 } 1092 1093 // ExecX is like Exec, but panics if an error occurs. 1094 func (u *CoinFiatUpsertBulk) ExecX(ctx context.Context) { 1095 if err := u.create.Exec(ctx); err != nil { 1096 panic(err) 1097 } 1098 }