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