github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/chainbase_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/chainbase" 14 "github.com/google/uuid" 15 ) 16 17 // ChainBaseCreate is the builder for creating a ChainBase entity. 18 type ChainBaseCreate struct { 19 config 20 mutation *ChainBaseMutation 21 hooks []Hook 22 conflict []sql.ConflictOption 23 } 24 25 // SetCreatedAt sets the "created_at" field. 26 func (cbc *ChainBaseCreate) SetCreatedAt(u uint32) *ChainBaseCreate { 27 cbc.mutation.SetCreatedAt(u) 28 return cbc 29 } 30 31 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 32 func (cbc *ChainBaseCreate) SetNillableCreatedAt(u *uint32) *ChainBaseCreate { 33 if u != nil { 34 cbc.SetCreatedAt(*u) 35 } 36 return cbc 37 } 38 39 // SetUpdatedAt sets the "updated_at" field. 40 func (cbc *ChainBaseCreate) SetUpdatedAt(u uint32) *ChainBaseCreate { 41 cbc.mutation.SetUpdatedAt(u) 42 return cbc 43 } 44 45 // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. 46 func (cbc *ChainBaseCreate) SetNillableUpdatedAt(u *uint32) *ChainBaseCreate { 47 if u != nil { 48 cbc.SetUpdatedAt(*u) 49 } 50 return cbc 51 } 52 53 // SetDeletedAt sets the "deleted_at" field. 54 func (cbc *ChainBaseCreate) SetDeletedAt(u uint32) *ChainBaseCreate { 55 cbc.mutation.SetDeletedAt(u) 56 return cbc 57 } 58 59 // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. 60 func (cbc *ChainBaseCreate) SetNillableDeletedAt(u *uint32) *ChainBaseCreate { 61 if u != nil { 62 cbc.SetDeletedAt(*u) 63 } 64 return cbc 65 } 66 67 // SetEntID sets the "ent_id" field. 68 func (cbc *ChainBaseCreate) SetEntID(u uuid.UUID) *ChainBaseCreate { 69 cbc.mutation.SetEntID(u) 70 return cbc 71 } 72 73 // SetNillableEntID sets the "ent_id" field if the given value is not nil. 74 func (cbc *ChainBaseCreate) SetNillableEntID(u *uuid.UUID) *ChainBaseCreate { 75 if u != nil { 76 cbc.SetEntID(*u) 77 } 78 return cbc 79 } 80 81 // SetName sets the "name" field. 82 func (cbc *ChainBaseCreate) SetName(s string) *ChainBaseCreate { 83 cbc.mutation.SetName(s) 84 return cbc 85 } 86 87 // SetNillableName sets the "name" field if the given value is not nil. 88 func (cbc *ChainBaseCreate) SetNillableName(s *string) *ChainBaseCreate { 89 if s != nil { 90 cbc.SetName(*s) 91 } 92 return cbc 93 } 94 95 // SetLogo sets the "logo" field. 96 func (cbc *ChainBaseCreate) SetLogo(s string) *ChainBaseCreate { 97 cbc.mutation.SetLogo(s) 98 return cbc 99 } 100 101 // SetNillableLogo sets the "logo" field if the given value is not nil. 102 func (cbc *ChainBaseCreate) SetNillableLogo(s *string) *ChainBaseCreate { 103 if s != nil { 104 cbc.SetLogo(*s) 105 } 106 return cbc 107 } 108 109 // SetNativeUnit sets the "native_unit" field. 110 func (cbc *ChainBaseCreate) SetNativeUnit(s string) *ChainBaseCreate { 111 cbc.mutation.SetNativeUnit(s) 112 return cbc 113 } 114 115 // SetNillableNativeUnit sets the "native_unit" field if the given value is not nil. 116 func (cbc *ChainBaseCreate) SetNillableNativeUnit(s *string) *ChainBaseCreate { 117 if s != nil { 118 cbc.SetNativeUnit(*s) 119 } 120 return cbc 121 } 122 123 // SetAtomicUnit sets the "atomic_unit" field. 124 func (cbc *ChainBaseCreate) SetAtomicUnit(s string) *ChainBaseCreate { 125 cbc.mutation.SetAtomicUnit(s) 126 return cbc 127 } 128 129 // SetNillableAtomicUnit sets the "atomic_unit" field if the given value is not nil. 130 func (cbc *ChainBaseCreate) SetNillableAtomicUnit(s *string) *ChainBaseCreate { 131 if s != nil { 132 cbc.SetAtomicUnit(*s) 133 } 134 return cbc 135 } 136 137 // SetUnitExp sets the "unit_exp" field. 138 func (cbc *ChainBaseCreate) SetUnitExp(u uint32) *ChainBaseCreate { 139 cbc.mutation.SetUnitExp(u) 140 return cbc 141 } 142 143 // SetNillableUnitExp sets the "unit_exp" field if the given value is not nil. 144 func (cbc *ChainBaseCreate) SetNillableUnitExp(u *uint32) *ChainBaseCreate { 145 if u != nil { 146 cbc.SetUnitExp(*u) 147 } 148 return cbc 149 } 150 151 // SetEnv sets the "env" field. 152 func (cbc *ChainBaseCreate) SetEnv(s string) *ChainBaseCreate { 153 cbc.mutation.SetEnv(s) 154 return cbc 155 } 156 157 // SetNillableEnv sets the "env" field if the given value is not nil. 158 func (cbc *ChainBaseCreate) SetNillableEnv(s *string) *ChainBaseCreate { 159 if s != nil { 160 cbc.SetEnv(*s) 161 } 162 return cbc 163 } 164 165 // SetChainID sets the "chain_id" field. 166 func (cbc *ChainBaseCreate) SetChainID(s string) *ChainBaseCreate { 167 cbc.mutation.SetChainID(s) 168 return cbc 169 } 170 171 // SetNillableChainID sets the "chain_id" field if the given value is not nil. 172 func (cbc *ChainBaseCreate) SetNillableChainID(s *string) *ChainBaseCreate { 173 if s != nil { 174 cbc.SetChainID(*s) 175 } 176 return cbc 177 } 178 179 // SetNickname sets the "nickname" field. 180 func (cbc *ChainBaseCreate) SetNickname(s string) *ChainBaseCreate { 181 cbc.mutation.SetNickname(s) 182 return cbc 183 } 184 185 // SetNillableNickname sets the "nickname" field if the given value is not nil. 186 func (cbc *ChainBaseCreate) SetNillableNickname(s *string) *ChainBaseCreate { 187 if s != nil { 188 cbc.SetNickname(*s) 189 } 190 return cbc 191 } 192 193 // SetGasType sets the "gas_type" field. 194 func (cbc *ChainBaseCreate) SetGasType(s string) *ChainBaseCreate { 195 cbc.mutation.SetGasType(s) 196 return cbc 197 } 198 199 // SetNillableGasType sets the "gas_type" field if the given value is not nil. 200 func (cbc *ChainBaseCreate) SetNillableGasType(s *string) *ChainBaseCreate { 201 if s != nil { 202 cbc.SetGasType(*s) 203 } 204 return cbc 205 } 206 207 // SetID sets the "id" field. 208 func (cbc *ChainBaseCreate) SetID(u uint32) *ChainBaseCreate { 209 cbc.mutation.SetID(u) 210 return cbc 211 } 212 213 // Mutation returns the ChainBaseMutation object of the builder. 214 func (cbc *ChainBaseCreate) Mutation() *ChainBaseMutation { 215 return cbc.mutation 216 } 217 218 // Save creates the ChainBase in the database. 219 func (cbc *ChainBaseCreate) Save(ctx context.Context) (*ChainBase, error) { 220 var ( 221 err error 222 node *ChainBase 223 ) 224 if err := cbc.defaults(); err != nil { 225 return nil, err 226 } 227 if len(cbc.hooks) == 0 { 228 if err = cbc.check(); err != nil { 229 return nil, err 230 } 231 node, err = cbc.sqlSave(ctx) 232 } else { 233 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 234 mutation, ok := m.(*ChainBaseMutation) 235 if !ok { 236 return nil, fmt.Errorf("unexpected mutation type %T", m) 237 } 238 if err = cbc.check(); err != nil { 239 return nil, err 240 } 241 cbc.mutation = mutation 242 if node, err = cbc.sqlSave(ctx); err != nil { 243 return nil, err 244 } 245 mutation.id = &node.ID 246 mutation.done = true 247 return node, err 248 }) 249 for i := len(cbc.hooks) - 1; i >= 0; i-- { 250 if cbc.hooks[i] == nil { 251 return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 252 } 253 mut = cbc.hooks[i](mut) 254 } 255 v, err := mut.Mutate(ctx, cbc.mutation) 256 if err != nil { 257 return nil, err 258 } 259 nv, ok := v.(*ChainBase) 260 if !ok { 261 return nil, fmt.Errorf("unexpected node type %T returned from ChainBaseMutation", v) 262 } 263 node = nv 264 } 265 return node, err 266 } 267 268 // SaveX calls Save and panics if Save returns an error. 269 func (cbc *ChainBaseCreate) SaveX(ctx context.Context) *ChainBase { 270 v, err := cbc.Save(ctx) 271 if err != nil { 272 panic(err) 273 } 274 return v 275 } 276 277 // Exec executes the query. 278 func (cbc *ChainBaseCreate) Exec(ctx context.Context) error { 279 _, err := cbc.Save(ctx) 280 return err 281 } 282 283 // ExecX is like Exec, but panics if an error occurs. 284 func (cbc *ChainBaseCreate) ExecX(ctx context.Context) { 285 if err := cbc.Exec(ctx); err != nil { 286 panic(err) 287 } 288 } 289 290 // defaults sets the default values of the builder before save. 291 func (cbc *ChainBaseCreate) defaults() error { 292 if _, ok := cbc.mutation.CreatedAt(); !ok { 293 if chainbase.DefaultCreatedAt == nil { 294 return fmt.Errorf("ent: uninitialized chainbase.DefaultCreatedAt (forgotten import ent/runtime?)") 295 } 296 v := chainbase.DefaultCreatedAt() 297 cbc.mutation.SetCreatedAt(v) 298 } 299 if _, ok := cbc.mutation.UpdatedAt(); !ok { 300 if chainbase.DefaultUpdatedAt == nil { 301 return fmt.Errorf("ent: uninitialized chainbase.DefaultUpdatedAt (forgotten import ent/runtime?)") 302 } 303 v := chainbase.DefaultUpdatedAt() 304 cbc.mutation.SetUpdatedAt(v) 305 } 306 if _, ok := cbc.mutation.DeletedAt(); !ok { 307 if chainbase.DefaultDeletedAt == nil { 308 return fmt.Errorf("ent: uninitialized chainbase.DefaultDeletedAt (forgotten import ent/runtime?)") 309 } 310 v := chainbase.DefaultDeletedAt() 311 cbc.mutation.SetDeletedAt(v) 312 } 313 if _, ok := cbc.mutation.EntID(); !ok { 314 if chainbase.DefaultEntID == nil { 315 return fmt.Errorf("ent: uninitialized chainbase.DefaultEntID (forgotten import ent/runtime?)") 316 } 317 v := chainbase.DefaultEntID() 318 cbc.mutation.SetEntID(v) 319 } 320 if _, ok := cbc.mutation.Name(); !ok { 321 v := chainbase.DefaultName 322 cbc.mutation.SetName(v) 323 } 324 if _, ok := cbc.mutation.Logo(); !ok { 325 v := chainbase.DefaultLogo 326 cbc.mutation.SetLogo(v) 327 } 328 if _, ok := cbc.mutation.NativeUnit(); !ok { 329 v := chainbase.DefaultNativeUnit 330 cbc.mutation.SetNativeUnit(v) 331 } 332 if _, ok := cbc.mutation.AtomicUnit(); !ok { 333 v := chainbase.DefaultAtomicUnit 334 cbc.mutation.SetAtomicUnit(v) 335 } 336 if _, ok := cbc.mutation.UnitExp(); !ok { 337 v := chainbase.DefaultUnitExp 338 cbc.mutation.SetUnitExp(v) 339 } 340 if _, ok := cbc.mutation.Env(); !ok { 341 v := chainbase.DefaultEnv 342 cbc.mutation.SetEnv(v) 343 } 344 if _, ok := cbc.mutation.ChainID(); !ok { 345 v := chainbase.DefaultChainID 346 cbc.mutation.SetChainID(v) 347 } 348 if _, ok := cbc.mutation.Nickname(); !ok { 349 v := chainbase.DefaultNickname 350 cbc.mutation.SetNickname(v) 351 } 352 if _, ok := cbc.mutation.GasType(); !ok { 353 v := chainbase.DefaultGasType 354 cbc.mutation.SetGasType(v) 355 } 356 return nil 357 } 358 359 // check runs all checks and user-defined validators on the builder. 360 func (cbc *ChainBaseCreate) check() error { 361 if _, ok := cbc.mutation.CreatedAt(); !ok { 362 return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ChainBase.created_at"`)} 363 } 364 if _, ok := cbc.mutation.UpdatedAt(); !ok { 365 return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "ChainBase.updated_at"`)} 366 } 367 if _, ok := cbc.mutation.DeletedAt(); !ok { 368 return &ValidationError{Name: "deleted_at", err: errors.New(`ent: missing required field "ChainBase.deleted_at"`)} 369 } 370 if _, ok := cbc.mutation.EntID(); !ok { 371 return &ValidationError{Name: "ent_id", err: errors.New(`ent: missing required field "ChainBase.ent_id"`)} 372 } 373 return nil 374 } 375 376 func (cbc *ChainBaseCreate) sqlSave(ctx context.Context) (*ChainBase, error) { 377 _node, _spec := cbc.createSpec() 378 if err := sqlgraph.CreateNode(ctx, cbc.driver, _spec); err != nil { 379 if sqlgraph.IsConstraintError(err) { 380 err = &ConstraintError{msg: err.Error(), wrap: err} 381 } 382 return nil, err 383 } 384 if _spec.ID.Value != _node.ID { 385 id := _spec.ID.Value.(int64) 386 _node.ID = uint32(id) 387 } 388 return _node, nil 389 } 390 391 func (cbc *ChainBaseCreate) createSpec() (*ChainBase, *sqlgraph.CreateSpec) { 392 var ( 393 _node = &ChainBase{config: cbc.config} 394 _spec = &sqlgraph.CreateSpec{ 395 Table: chainbase.Table, 396 ID: &sqlgraph.FieldSpec{ 397 Type: field.TypeUint32, 398 Column: chainbase.FieldID, 399 }, 400 } 401 ) 402 _spec.OnConflict = cbc.conflict 403 if id, ok := cbc.mutation.ID(); ok { 404 _node.ID = id 405 _spec.ID.Value = id 406 } 407 if value, ok := cbc.mutation.CreatedAt(); ok { 408 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 409 Type: field.TypeUint32, 410 Value: value, 411 Column: chainbase.FieldCreatedAt, 412 }) 413 _node.CreatedAt = value 414 } 415 if value, ok := cbc.mutation.UpdatedAt(); ok { 416 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 417 Type: field.TypeUint32, 418 Value: value, 419 Column: chainbase.FieldUpdatedAt, 420 }) 421 _node.UpdatedAt = value 422 } 423 if value, ok := cbc.mutation.DeletedAt(); ok { 424 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 425 Type: field.TypeUint32, 426 Value: value, 427 Column: chainbase.FieldDeletedAt, 428 }) 429 _node.DeletedAt = value 430 } 431 if value, ok := cbc.mutation.EntID(); ok { 432 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 433 Type: field.TypeUUID, 434 Value: value, 435 Column: chainbase.FieldEntID, 436 }) 437 _node.EntID = value 438 } 439 if value, ok := cbc.mutation.Name(); ok { 440 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 441 Type: field.TypeString, 442 Value: value, 443 Column: chainbase.FieldName, 444 }) 445 _node.Name = value 446 } 447 if value, ok := cbc.mutation.Logo(); ok { 448 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 449 Type: field.TypeString, 450 Value: value, 451 Column: chainbase.FieldLogo, 452 }) 453 _node.Logo = value 454 } 455 if value, ok := cbc.mutation.NativeUnit(); ok { 456 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 457 Type: field.TypeString, 458 Value: value, 459 Column: chainbase.FieldNativeUnit, 460 }) 461 _node.NativeUnit = value 462 } 463 if value, ok := cbc.mutation.AtomicUnit(); ok { 464 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 465 Type: field.TypeString, 466 Value: value, 467 Column: chainbase.FieldAtomicUnit, 468 }) 469 _node.AtomicUnit = value 470 } 471 if value, ok := cbc.mutation.UnitExp(); ok { 472 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 473 Type: field.TypeUint32, 474 Value: value, 475 Column: chainbase.FieldUnitExp, 476 }) 477 _node.UnitExp = value 478 } 479 if value, ok := cbc.mutation.Env(); ok { 480 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 481 Type: field.TypeString, 482 Value: value, 483 Column: chainbase.FieldEnv, 484 }) 485 _node.Env = value 486 } 487 if value, ok := cbc.mutation.ChainID(); ok { 488 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 489 Type: field.TypeString, 490 Value: value, 491 Column: chainbase.FieldChainID, 492 }) 493 _node.ChainID = value 494 } 495 if value, ok := cbc.mutation.Nickname(); ok { 496 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 497 Type: field.TypeString, 498 Value: value, 499 Column: chainbase.FieldNickname, 500 }) 501 _node.Nickname = value 502 } 503 if value, ok := cbc.mutation.GasType(); ok { 504 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 505 Type: field.TypeString, 506 Value: value, 507 Column: chainbase.FieldGasType, 508 }) 509 _node.GasType = value 510 } 511 return _node, _spec 512 } 513 514 // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause 515 // of the `INSERT` statement. For example: 516 // 517 // client.ChainBase.Create(). 518 // SetCreatedAt(v). 519 // OnConflict( 520 // // Update the row with the new values 521 // // the was proposed for insertion. 522 // sql.ResolveWithNewValues(), 523 // ). 524 // // Override some of the fields with custom 525 // // update values. 526 // Update(func(u *ent.ChainBaseUpsert) { 527 // SetCreatedAt(v+v). 528 // }). 529 // Exec(ctx) 530 // 531 func (cbc *ChainBaseCreate) OnConflict(opts ...sql.ConflictOption) *ChainBaseUpsertOne { 532 cbc.conflict = opts 533 return &ChainBaseUpsertOne{ 534 create: cbc, 535 } 536 } 537 538 // OnConflictColumns calls `OnConflict` and configures the columns 539 // as conflict target. Using this option is equivalent to using: 540 // 541 // client.ChainBase.Create(). 542 // OnConflict(sql.ConflictColumns(columns...)). 543 // Exec(ctx) 544 // 545 func (cbc *ChainBaseCreate) OnConflictColumns(columns ...string) *ChainBaseUpsertOne { 546 cbc.conflict = append(cbc.conflict, sql.ConflictColumns(columns...)) 547 return &ChainBaseUpsertOne{ 548 create: cbc, 549 } 550 } 551 552 type ( 553 // ChainBaseUpsertOne is the builder for "upsert"-ing 554 // one ChainBase node. 555 ChainBaseUpsertOne struct { 556 create *ChainBaseCreate 557 } 558 559 // ChainBaseUpsert is the "OnConflict" setter. 560 ChainBaseUpsert struct { 561 *sql.UpdateSet 562 } 563 ) 564 565 // SetCreatedAt sets the "created_at" field. 566 func (u *ChainBaseUpsert) SetCreatedAt(v uint32) *ChainBaseUpsert { 567 u.Set(chainbase.FieldCreatedAt, v) 568 return u 569 } 570 571 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 572 func (u *ChainBaseUpsert) UpdateCreatedAt() *ChainBaseUpsert { 573 u.SetExcluded(chainbase.FieldCreatedAt) 574 return u 575 } 576 577 // AddCreatedAt adds v to the "created_at" field. 578 func (u *ChainBaseUpsert) AddCreatedAt(v uint32) *ChainBaseUpsert { 579 u.Add(chainbase.FieldCreatedAt, v) 580 return u 581 } 582 583 // SetUpdatedAt sets the "updated_at" field. 584 func (u *ChainBaseUpsert) SetUpdatedAt(v uint32) *ChainBaseUpsert { 585 u.Set(chainbase.FieldUpdatedAt, v) 586 return u 587 } 588 589 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 590 func (u *ChainBaseUpsert) UpdateUpdatedAt() *ChainBaseUpsert { 591 u.SetExcluded(chainbase.FieldUpdatedAt) 592 return u 593 } 594 595 // AddUpdatedAt adds v to the "updated_at" field. 596 func (u *ChainBaseUpsert) AddUpdatedAt(v uint32) *ChainBaseUpsert { 597 u.Add(chainbase.FieldUpdatedAt, v) 598 return u 599 } 600 601 // SetDeletedAt sets the "deleted_at" field. 602 func (u *ChainBaseUpsert) SetDeletedAt(v uint32) *ChainBaseUpsert { 603 u.Set(chainbase.FieldDeletedAt, v) 604 return u 605 } 606 607 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 608 func (u *ChainBaseUpsert) UpdateDeletedAt() *ChainBaseUpsert { 609 u.SetExcluded(chainbase.FieldDeletedAt) 610 return u 611 } 612 613 // AddDeletedAt adds v to the "deleted_at" field. 614 func (u *ChainBaseUpsert) AddDeletedAt(v uint32) *ChainBaseUpsert { 615 u.Add(chainbase.FieldDeletedAt, v) 616 return u 617 } 618 619 // SetEntID sets the "ent_id" field. 620 func (u *ChainBaseUpsert) SetEntID(v uuid.UUID) *ChainBaseUpsert { 621 u.Set(chainbase.FieldEntID, v) 622 return u 623 } 624 625 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 626 func (u *ChainBaseUpsert) UpdateEntID() *ChainBaseUpsert { 627 u.SetExcluded(chainbase.FieldEntID) 628 return u 629 } 630 631 // SetName sets the "name" field. 632 func (u *ChainBaseUpsert) SetName(v string) *ChainBaseUpsert { 633 u.Set(chainbase.FieldName, v) 634 return u 635 } 636 637 // UpdateName sets the "name" field to the value that was provided on create. 638 func (u *ChainBaseUpsert) UpdateName() *ChainBaseUpsert { 639 u.SetExcluded(chainbase.FieldName) 640 return u 641 } 642 643 // ClearName clears the value of the "name" field. 644 func (u *ChainBaseUpsert) ClearName() *ChainBaseUpsert { 645 u.SetNull(chainbase.FieldName) 646 return u 647 } 648 649 // SetLogo sets the "logo" field. 650 func (u *ChainBaseUpsert) SetLogo(v string) *ChainBaseUpsert { 651 u.Set(chainbase.FieldLogo, v) 652 return u 653 } 654 655 // UpdateLogo sets the "logo" field to the value that was provided on create. 656 func (u *ChainBaseUpsert) UpdateLogo() *ChainBaseUpsert { 657 u.SetExcluded(chainbase.FieldLogo) 658 return u 659 } 660 661 // ClearLogo clears the value of the "logo" field. 662 func (u *ChainBaseUpsert) ClearLogo() *ChainBaseUpsert { 663 u.SetNull(chainbase.FieldLogo) 664 return u 665 } 666 667 // SetNativeUnit sets the "native_unit" field. 668 func (u *ChainBaseUpsert) SetNativeUnit(v string) *ChainBaseUpsert { 669 u.Set(chainbase.FieldNativeUnit, v) 670 return u 671 } 672 673 // UpdateNativeUnit sets the "native_unit" field to the value that was provided on create. 674 func (u *ChainBaseUpsert) UpdateNativeUnit() *ChainBaseUpsert { 675 u.SetExcluded(chainbase.FieldNativeUnit) 676 return u 677 } 678 679 // ClearNativeUnit clears the value of the "native_unit" field. 680 func (u *ChainBaseUpsert) ClearNativeUnit() *ChainBaseUpsert { 681 u.SetNull(chainbase.FieldNativeUnit) 682 return u 683 } 684 685 // SetAtomicUnit sets the "atomic_unit" field. 686 func (u *ChainBaseUpsert) SetAtomicUnit(v string) *ChainBaseUpsert { 687 u.Set(chainbase.FieldAtomicUnit, v) 688 return u 689 } 690 691 // UpdateAtomicUnit sets the "atomic_unit" field to the value that was provided on create. 692 func (u *ChainBaseUpsert) UpdateAtomicUnit() *ChainBaseUpsert { 693 u.SetExcluded(chainbase.FieldAtomicUnit) 694 return u 695 } 696 697 // ClearAtomicUnit clears the value of the "atomic_unit" field. 698 func (u *ChainBaseUpsert) ClearAtomicUnit() *ChainBaseUpsert { 699 u.SetNull(chainbase.FieldAtomicUnit) 700 return u 701 } 702 703 // SetUnitExp sets the "unit_exp" field. 704 func (u *ChainBaseUpsert) SetUnitExp(v uint32) *ChainBaseUpsert { 705 u.Set(chainbase.FieldUnitExp, v) 706 return u 707 } 708 709 // UpdateUnitExp sets the "unit_exp" field to the value that was provided on create. 710 func (u *ChainBaseUpsert) UpdateUnitExp() *ChainBaseUpsert { 711 u.SetExcluded(chainbase.FieldUnitExp) 712 return u 713 } 714 715 // AddUnitExp adds v to the "unit_exp" field. 716 func (u *ChainBaseUpsert) AddUnitExp(v uint32) *ChainBaseUpsert { 717 u.Add(chainbase.FieldUnitExp, v) 718 return u 719 } 720 721 // ClearUnitExp clears the value of the "unit_exp" field. 722 func (u *ChainBaseUpsert) ClearUnitExp() *ChainBaseUpsert { 723 u.SetNull(chainbase.FieldUnitExp) 724 return u 725 } 726 727 // SetEnv sets the "env" field. 728 func (u *ChainBaseUpsert) SetEnv(v string) *ChainBaseUpsert { 729 u.Set(chainbase.FieldEnv, v) 730 return u 731 } 732 733 // UpdateEnv sets the "env" field to the value that was provided on create. 734 func (u *ChainBaseUpsert) UpdateEnv() *ChainBaseUpsert { 735 u.SetExcluded(chainbase.FieldEnv) 736 return u 737 } 738 739 // ClearEnv clears the value of the "env" field. 740 func (u *ChainBaseUpsert) ClearEnv() *ChainBaseUpsert { 741 u.SetNull(chainbase.FieldEnv) 742 return u 743 } 744 745 // SetChainID sets the "chain_id" field. 746 func (u *ChainBaseUpsert) SetChainID(v string) *ChainBaseUpsert { 747 u.Set(chainbase.FieldChainID, v) 748 return u 749 } 750 751 // UpdateChainID sets the "chain_id" field to the value that was provided on create. 752 func (u *ChainBaseUpsert) UpdateChainID() *ChainBaseUpsert { 753 u.SetExcluded(chainbase.FieldChainID) 754 return u 755 } 756 757 // ClearChainID clears the value of the "chain_id" field. 758 func (u *ChainBaseUpsert) ClearChainID() *ChainBaseUpsert { 759 u.SetNull(chainbase.FieldChainID) 760 return u 761 } 762 763 // SetNickname sets the "nickname" field. 764 func (u *ChainBaseUpsert) SetNickname(v string) *ChainBaseUpsert { 765 u.Set(chainbase.FieldNickname, v) 766 return u 767 } 768 769 // UpdateNickname sets the "nickname" field to the value that was provided on create. 770 func (u *ChainBaseUpsert) UpdateNickname() *ChainBaseUpsert { 771 u.SetExcluded(chainbase.FieldNickname) 772 return u 773 } 774 775 // ClearNickname clears the value of the "nickname" field. 776 func (u *ChainBaseUpsert) ClearNickname() *ChainBaseUpsert { 777 u.SetNull(chainbase.FieldNickname) 778 return u 779 } 780 781 // SetGasType sets the "gas_type" field. 782 func (u *ChainBaseUpsert) SetGasType(v string) *ChainBaseUpsert { 783 u.Set(chainbase.FieldGasType, v) 784 return u 785 } 786 787 // UpdateGasType sets the "gas_type" field to the value that was provided on create. 788 func (u *ChainBaseUpsert) UpdateGasType() *ChainBaseUpsert { 789 u.SetExcluded(chainbase.FieldGasType) 790 return u 791 } 792 793 // ClearGasType clears the value of the "gas_type" field. 794 func (u *ChainBaseUpsert) ClearGasType() *ChainBaseUpsert { 795 u.SetNull(chainbase.FieldGasType) 796 return u 797 } 798 799 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. 800 // Using this option is equivalent to using: 801 // 802 // client.ChainBase.Create(). 803 // OnConflict( 804 // sql.ResolveWithNewValues(), 805 // sql.ResolveWith(func(u *sql.UpdateSet) { 806 // u.SetIgnore(chainbase.FieldID) 807 // }), 808 // ). 809 // Exec(ctx) 810 // 811 func (u *ChainBaseUpsertOne) UpdateNewValues() *ChainBaseUpsertOne { 812 u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) 813 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { 814 if _, exists := u.create.mutation.ID(); exists { 815 s.SetIgnore(chainbase.FieldID) 816 } 817 })) 818 return u 819 } 820 821 // Ignore sets each column to itself in case of conflict. 822 // Using this option is equivalent to using: 823 // 824 // client.ChainBase.Create(). 825 // OnConflict(sql.ResolveWithIgnore()). 826 // Exec(ctx) 827 // 828 func (u *ChainBaseUpsertOne) Ignore() *ChainBaseUpsertOne { 829 u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) 830 return u 831 } 832 833 // DoNothing configures the conflict_action to `DO NOTHING`. 834 // Supported only by SQLite and PostgreSQL. 835 func (u *ChainBaseUpsertOne) DoNothing() *ChainBaseUpsertOne { 836 u.create.conflict = append(u.create.conflict, sql.DoNothing()) 837 return u 838 } 839 840 // Update allows overriding fields `UPDATE` values. See the ChainBaseCreate.OnConflict 841 // documentation for more info. 842 func (u *ChainBaseUpsertOne) Update(set func(*ChainBaseUpsert)) *ChainBaseUpsertOne { 843 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { 844 set(&ChainBaseUpsert{UpdateSet: update}) 845 })) 846 return u 847 } 848 849 // SetCreatedAt sets the "created_at" field. 850 func (u *ChainBaseUpsertOne) SetCreatedAt(v uint32) *ChainBaseUpsertOne { 851 return u.Update(func(s *ChainBaseUpsert) { 852 s.SetCreatedAt(v) 853 }) 854 } 855 856 // AddCreatedAt adds v to the "created_at" field. 857 func (u *ChainBaseUpsertOne) AddCreatedAt(v uint32) *ChainBaseUpsertOne { 858 return u.Update(func(s *ChainBaseUpsert) { 859 s.AddCreatedAt(v) 860 }) 861 } 862 863 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 864 func (u *ChainBaseUpsertOne) UpdateCreatedAt() *ChainBaseUpsertOne { 865 return u.Update(func(s *ChainBaseUpsert) { 866 s.UpdateCreatedAt() 867 }) 868 } 869 870 // SetUpdatedAt sets the "updated_at" field. 871 func (u *ChainBaseUpsertOne) SetUpdatedAt(v uint32) *ChainBaseUpsertOne { 872 return u.Update(func(s *ChainBaseUpsert) { 873 s.SetUpdatedAt(v) 874 }) 875 } 876 877 // AddUpdatedAt adds v to the "updated_at" field. 878 func (u *ChainBaseUpsertOne) AddUpdatedAt(v uint32) *ChainBaseUpsertOne { 879 return u.Update(func(s *ChainBaseUpsert) { 880 s.AddUpdatedAt(v) 881 }) 882 } 883 884 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 885 func (u *ChainBaseUpsertOne) UpdateUpdatedAt() *ChainBaseUpsertOne { 886 return u.Update(func(s *ChainBaseUpsert) { 887 s.UpdateUpdatedAt() 888 }) 889 } 890 891 // SetDeletedAt sets the "deleted_at" field. 892 func (u *ChainBaseUpsertOne) SetDeletedAt(v uint32) *ChainBaseUpsertOne { 893 return u.Update(func(s *ChainBaseUpsert) { 894 s.SetDeletedAt(v) 895 }) 896 } 897 898 // AddDeletedAt adds v to the "deleted_at" field. 899 func (u *ChainBaseUpsertOne) AddDeletedAt(v uint32) *ChainBaseUpsertOne { 900 return u.Update(func(s *ChainBaseUpsert) { 901 s.AddDeletedAt(v) 902 }) 903 } 904 905 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 906 func (u *ChainBaseUpsertOne) UpdateDeletedAt() *ChainBaseUpsertOne { 907 return u.Update(func(s *ChainBaseUpsert) { 908 s.UpdateDeletedAt() 909 }) 910 } 911 912 // SetEntID sets the "ent_id" field. 913 func (u *ChainBaseUpsertOne) SetEntID(v uuid.UUID) *ChainBaseUpsertOne { 914 return u.Update(func(s *ChainBaseUpsert) { 915 s.SetEntID(v) 916 }) 917 } 918 919 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 920 func (u *ChainBaseUpsertOne) UpdateEntID() *ChainBaseUpsertOne { 921 return u.Update(func(s *ChainBaseUpsert) { 922 s.UpdateEntID() 923 }) 924 } 925 926 // SetName sets the "name" field. 927 func (u *ChainBaseUpsertOne) SetName(v string) *ChainBaseUpsertOne { 928 return u.Update(func(s *ChainBaseUpsert) { 929 s.SetName(v) 930 }) 931 } 932 933 // UpdateName sets the "name" field to the value that was provided on create. 934 func (u *ChainBaseUpsertOne) UpdateName() *ChainBaseUpsertOne { 935 return u.Update(func(s *ChainBaseUpsert) { 936 s.UpdateName() 937 }) 938 } 939 940 // ClearName clears the value of the "name" field. 941 func (u *ChainBaseUpsertOne) ClearName() *ChainBaseUpsertOne { 942 return u.Update(func(s *ChainBaseUpsert) { 943 s.ClearName() 944 }) 945 } 946 947 // SetLogo sets the "logo" field. 948 func (u *ChainBaseUpsertOne) SetLogo(v string) *ChainBaseUpsertOne { 949 return u.Update(func(s *ChainBaseUpsert) { 950 s.SetLogo(v) 951 }) 952 } 953 954 // UpdateLogo sets the "logo" field to the value that was provided on create. 955 func (u *ChainBaseUpsertOne) UpdateLogo() *ChainBaseUpsertOne { 956 return u.Update(func(s *ChainBaseUpsert) { 957 s.UpdateLogo() 958 }) 959 } 960 961 // ClearLogo clears the value of the "logo" field. 962 func (u *ChainBaseUpsertOne) ClearLogo() *ChainBaseUpsertOne { 963 return u.Update(func(s *ChainBaseUpsert) { 964 s.ClearLogo() 965 }) 966 } 967 968 // SetNativeUnit sets the "native_unit" field. 969 func (u *ChainBaseUpsertOne) SetNativeUnit(v string) *ChainBaseUpsertOne { 970 return u.Update(func(s *ChainBaseUpsert) { 971 s.SetNativeUnit(v) 972 }) 973 } 974 975 // UpdateNativeUnit sets the "native_unit" field to the value that was provided on create. 976 func (u *ChainBaseUpsertOne) UpdateNativeUnit() *ChainBaseUpsertOne { 977 return u.Update(func(s *ChainBaseUpsert) { 978 s.UpdateNativeUnit() 979 }) 980 } 981 982 // ClearNativeUnit clears the value of the "native_unit" field. 983 func (u *ChainBaseUpsertOne) ClearNativeUnit() *ChainBaseUpsertOne { 984 return u.Update(func(s *ChainBaseUpsert) { 985 s.ClearNativeUnit() 986 }) 987 } 988 989 // SetAtomicUnit sets the "atomic_unit" field. 990 func (u *ChainBaseUpsertOne) SetAtomicUnit(v string) *ChainBaseUpsertOne { 991 return u.Update(func(s *ChainBaseUpsert) { 992 s.SetAtomicUnit(v) 993 }) 994 } 995 996 // UpdateAtomicUnit sets the "atomic_unit" field to the value that was provided on create. 997 func (u *ChainBaseUpsertOne) UpdateAtomicUnit() *ChainBaseUpsertOne { 998 return u.Update(func(s *ChainBaseUpsert) { 999 s.UpdateAtomicUnit() 1000 }) 1001 } 1002 1003 // ClearAtomicUnit clears the value of the "atomic_unit" field. 1004 func (u *ChainBaseUpsertOne) ClearAtomicUnit() *ChainBaseUpsertOne { 1005 return u.Update(func(s *ChainBaseUpsert) { 1006 s.ClearAtomicUnit() 1007 }) 1008 } 1009 1010 // SetUnitExp sets the "unit_exp" field. 1011 func (u *ChainBaseUpsertOne) SetUnitExp(v uint32) *ChainBaseUpsertOne { 1012 return u.Update(func(s *ChainBaseUpsert) { 1013 s.SetUnitExp(v) 1014 }) 1015 } 1016 1017 // AddUnitExp adds v to the "unit_exp" field. 1018 func (u *ChainBaseUpsertOne) AddUnitExp(v uint32) *ChainBaseUpsertOne { 1019 return u.Update(func(s *ChainBaseUpsert) { 1020 s.AddUnitExp(v) 1021 }) 1022 } 1023 1024 // UpdateUnitExp sets the "unit_exp" field to the value that was provided on create. 1025 func (u *ChainBaseUpsertOne) UpdateUnitExp() *ChainBaseUpsertOne { 1026 return u.Update(func(s *ChainBaseUpsert) { 1027 s.UpdateUnitExp() 1028 }) 1029 } 1030 1031 // ClearUnitExp clears the value of the "unit_exp" field. 1032 func (u *ChainBaseUpsertOne) ClearUnitExp() *ChainBaseUpsertOne { 1033 return u.Update(func(s *ChainBaseUpsert) { 1034 s.ClearUnitExp() 1035 }) 1036 } 1037 1038 // SetEnv sets the "env" field. 1039 func (u *ChainBaseUpsertOne) SetEnv(v string) *ChainBaseUpsertOne { 1040 return u.Update(func(s *ChainBaseUpsert) { 1041 s.SetEnv(v) 1042 }) 1043 } 1044 1045 // UpdateEnv sets the "env" field to the value that was provided on create. 1046 func (u *ChainBaseUpsertOne) UpdateEnv() *ChainBaseUpsertOne { 1047 return u.Update(func(s *ChainBaseUpsert) { 1048 s.UpdateEnv() 1049 }) 1050 } 1051 1052 // ClearEnv clears the value of the "env" field. 1053 func (u *ChainBaseUpsertOne) ClearEnv() *ChainBaseUpsertOne { 1054 return u.Update(func(s *ChainBaseUpsert) { 1055 s.ClearEnv() 1056 }) 1057 } 1058 1059 // SetChainID sets the "chain_id" field. 1060 func (u *ChainBaseUpsertOne) SetChainID(v string) *ChainBaseUpsertOne { 1061 return u.Update(func(s *ChainBaseUpsert) { 1062 s.SetChainID(v) 1063 }) 1064 } 1065 1066 // UpdateChainID sets the "chain_id" field to the value that was provided on create. 1067 func (u *ChainBaseUpsertOne) UpdateChainID() *ChainBaseUpsertOne { 1068 return u.Update(func(s *ChainBaseUpsert) { 1069 s.UpdateChainID() 1070 }) 1071 } 1072 1073 // ClearChainID clears the value of the "chain_id" field. 1074 func (u *ChainBaseUpsertOne) ClearChainID() *ChainBaseUpsertOne { 1075 return u.Update(func(s *ChainBaseUpsert) { 1076 s.ClearChainID() 1077 }) 1078 } 1079 1080 // SetNickname sets the "nickname" field. 1081 func (u *ChainBaseUpsertOne) SetNickname(v string) *ChainBaseUpsertOne { 1082 return u.Update(func(s *ChainBaseUpsert) { 1083 s.SetNickname(v) 1084 }) 1085 } 1086 1087 // UpdateNickname sets the "nickname" field to the value that was provided on create. 1088 func (u *ChainBaseUpsertOne) UpdateNickname() *ChainBaseUpsertOne { 1089 return u.Update(func(s *ChainBaseUpsert) { 1090 s.UpdateNickname() 1091 }) 1092 } 1093 1094 // ClearNickname clears the value of the "nickname" field. 1095 func (u *ChainBaseUpsertOne) ClearNickname() *ChainBaseUpsertOne { 1096 return u.Update(func(s *ChainBaseUpsert) { 1097 s.ClearNickname() 1098 }) 1099 } 1100 1101 // SetGasType sets the "gas_type" field. 1102 func (u *ChainBaseUpsertOne) SetGasType(v string) *ChainBaseUpsertOne { 1103 return u.Update(func(s *ChainBaseUpsert) { 1104 s.SetGasType(v) 1105 }) 1106 } 1107 1108 // UpdateGasType sets the "gas_type" field to the value that was provided on create. 1109 func (u *ChainBaseUpsertOne) UpdateGasType() *ChainBaseUpsertOne { 1110 return u.Update(func(s *ChainBaseUpsert) { 1111 s.UpdateGasType() 1112 }) 1113 } 1114 1115 // ClearGasType clears the value of the "gas_type" field. 1116 func (u *ChainBaseUpsertOne) ClearGasType() *ChainBaseUpsertOne { 1117 return u.Update(func(s *ChainBaseUpsert) { 1118 s.ClearGasType() 1119 }) 1120 } 1121 1122 // Exec executes the query. 1123 func (u *ChainBaseUpsertOne) Exec(ctx context.Context) error { 1124 if len(u.create.conflict) == 0 { 1125 return errors.New("ent: missing options for ChainBaseCreate.OnConflict") 1126 } 1127 return u.create.Exec(ctx) 1128 } 1129 1130 // ExecX is like Exec, but panics if an error occurs. 1131 func (u *ChainBaseUpsertOne) ExecX(ctx context.Context) { 1132 if err := u.create.Exec(ctx); err != nil { 1133 panic(err) 1134 } 1135 } 1136 1137 // Exec executes the UPSERT query and returns the inserted/updated ID. 1138 func (u *ChainBaseUpsertOne) ID(ctx context.Context) (id uint32, err error) { 1139 node, err := u.create.Save(ctx) 1140 if err != nil { 1141 return id, err 1142 } 1143 return node.ID, nil 1144 } 1145 1146 // IDX is like ID, but panics if an error occurs. 1147 func (u *ChainBaseUpsertOne) IDX(ctx context.Context) uint32 { 1148 id, err := u.ID(ctx) 1149 if err != nil { 1150 panic(err) 1151 } 1152 return id 1153 } 1154 1155 // ChainBaseCreateBulk is the builder for creating many ChainBase entities in bulk. 1156 type ChainBaseCreateBulk struct { 1157 config 1158 builders []*ChainBaseCreate 1159 conflict []sql.ConflictOption 1160 } 1161 1162 // Save creates the ChainBase entities in the database. 1163 func (cbcb *ChainBaseCreateBulk) Save(ctx context.Context) ([]*ChainBase, error) { 1164 specs := make([]*sqlgraph.CreateSpec, len(cbcb.builders)) 1165 nodes := make([]*ChainBase, len(cbcb.builders)) 1166 mutators := make([]Mutator, len(cbcb.builders)) 1167 for i := range cbcb.builders { 1168 func(i int, root context.Context) { 1169 builder := cbcb.builders[i] 1170 builder.defaults() 1171 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 1172 mutation, ok := m.(*ChainBaseMutation) 1173 if !ok { 1174 return nil, fmt.Errorf("unexpected mutation type %T", m) 1175 } 1176 if err := builder.check(); err != nil { 1177 return nil, err 1178 } 1179 builder.mutation = mutation 1180 nodes[i], specs[i] = builder.createSpec() 1181 var err error 1182 if i < len(mutators)-1 { 1183 _, err = mutators[i+1].Mutate(root, cbcb.builders[i+1].mutation) 1184 } else { 1185 spec := &sqlgraph.BatchCreateSpec{Nodes: specs} 1186 spec.OnConflict = cbcb.conflict 1187 // Invoke the actual operation on the latest mutation in the chain. 1188 if err = sqlgraph.BatchCreate(ctx, cbcb.driver, spec); err != nil { 1189 if sqlgraph.IsConstraintError(err) { 1190 err = &ConstraintError{msg: err.Error(), wrap: err} 1191 } 1192 } 1193 } 1194 if err != nil { 1195 return nil, err 1196 } 1197 mutation.id = &nodes[i].ID 1198 if specs[i].ID.Value != nil && nodes[i].ID == 0 { 1199 id := specs[i].ID.Value.(int64) 1200 nodes[i].ID = uint32(id) 1201 } 1202 mutation.done = true 1203 return nodes[i], nil 1204 }) 1205 for i := len(builder.hooks) - 1; i >= 0; i-- { 1206 mut = builder.hooks[i](mut) 1207 } 1208 mutators[i] = mut 1209 }(i, ctx) 1210 } 1211 if len(mutators) > 0 { 1212 if _, err := mutators[0].Mutate(ctx, cbcb.builders[0].mutation); err != nil { 1213 return nil, err 1214 } 1215 } 1216 return nodes, nil 1217 } 1218 1219 // SaveX is like Save, but panics if an error occurs. 1220 func (cbcb *ChainBaseCreateBulk) SaveX(ctx context.Context) []*ChainBase { 1221 v, err := cbcb.Save(ctx) 1222 if err != nil { 1223 panic(err) 1224 } 1225 return v 1226 } 1227 1228 // Exec executes the query. 1229 func (cbcb *ChainBaseCreateBulk) Exec(ctx context.Context) error { 1230 _, err := cbcb.Save(ctx) 1231 return err 1232 } 1233 1234 // ExecX is like Exec, but panics if an error occurs. 1235 func (cbcb *ChainBaseCreateBulk) ExecX(ctx context.Context) { 1236 if err := cbcb.Exec(ctx); err != nil { 1237 panic(err) 1238 } 1239 } 1240 1241 // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause 1242 // of the `INSERT` statement. For example: 1243 // 1244 // client.ChainBase.CreateBulk(builders...). 1245 // OnConflict( 1246 // // Update the row with the new values 1247 // // the was proposed for insertion. 1248 // sql.ResolveWithNewValues(), 1249 // ). 1250 // // Override some of the fields with custom 1251 // // update values. 1252 // Update(func(u *ent.ChainBaseUpsert) { 1253 // SetCreatedAt(v+v). 1254 // }). 1255 // Exec(ctx) 1256 // 1257 func (cbcb *ChainBaseCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChainBaseUpsertBulk { 1258 cbcb.conflict = opts 1259 return &ChainBaseUpsertBulk{ 1260 create: cbcb, 1261 } 1262 } 1263 1264 // OnConflictColumns calls `OnConflict` and configures the columns 1265 // as conflict target. Using this option is equivalent to using: 1266 // 1267 // client.ChainBase.Create(). 1268 // OnConflict(sql.ConflictColumns(columns...)). 1269 // Exec(ctx) 1270 // 1271 func (cbcb *ChainBaseCreateBulk) OnConflictColumns(columns ...string) *ChainBaseUpsertBulk { 1272 cbcb.conflict = append(cbcb.conflict, sql.ConflictColumns(columns...)) 1273 return &ChainBaseUpsertBulk{ 1274 create: cbcb, 1275 } 1276 } 1277 1278 // ChainBaseUpsertBulk is the builder for "upsert"-ing 1279 // a bulk of ChainBase nodes. 1280 type ChainBaseUpsertBulk struct { 1281 create *ChainBaseCreateBulk 1282 } 1283 1284 // UpdateNewValues updates the mutable fields using the new values that 1285 // were set on create. Using this option is equivalent to using: 1286 // 1287 // client.ChainBase.Create(). 1288 // OnConflict( 1289 // sql.ResolveWithNewValues(), 1290 // sql.ResolveWith(func(u *sql.UpdateSet) { 1291 // u.SetIgnore(chainbase.FieldID) 1292 // }), 1293 // ). 1294 // Exec(ctx) 1295 // 1296 func (u *ChainBaseUpsertBulk) UpdateNewValues() *ChainBaseUpsertBulk { 1297 u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) 1298 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { 1299 for _, b := range u.create.builders { 1300 if _, exists := b.mutation.ID(); exists { 1301 s.SetIgnore(chainbase.FieldID) 1302 return 1303 } 1304 } 1305 })) 1306 return u 1307 } 1308 1309 // Ignore sets each column to itself in case of conflict. 1310 // Using this option is equivalent to using: 1311 // 1312 // client.ChainBase.Create(). 1313 // OnConflict(sql.ResolveWithIgnore()). 1314 // Exec(ctx) 1315 // 1316 func (u *ChainBaseUpsertBulk) Ignore() *ChainBaseUpsertBulk { 1317 u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) 1318 return u 1319 } 1320 1321 // DoNothing configures the conflict_action to `DO NOTHING`. 1322 // Supported only by SQLite and PostgreSQL. 1323 func (u *ChainBaseUpsertBulk) DoNothing() *ChainBaseUpsertBulk { 1324 u.create.conflict = append(u.create.conflict, sql.DoNothing()) 1325 return u 1326 } 1327 1328 // Update allows overriding fields `UPDATE` values. See the ChainBaseCreateBulk.OnConflict 1329 // documentation for more info. 1330 func (u *ChainBaseUpsertBulk) Update(set func(*ChainBaseUpsert)) *ChainBaseUpsertBulk { 1331 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { 1332 set(&ChainBaseUpsert{UpdateSet: update}) 1333 })) 1334 return u 1335 } 1336 1337 // SetCreatedAt sets the "created_at" field. 1338 func (u *ChainBaseUpsertBulk) SetCreatedAt(v uint32) *ChainBaseUpsertBulk { 1339 return u.Update(func(s *ChainBaseUpsert) { 1340 s.SetCreatedAt(v) 1341 }) 1342 } 1343 1344 // AddCreatedAt adds v to the "created_at" field. 1345 func (u *ChainBaseUpsertBulk) AddCreatedAt(v uint32) *ChainBaseUpsertBulk { 1346 return u.Update(func(s *ChainBaseUpsert) { 1347 s.AddCreatedAt(v) 1348 }) 1349 } 1350 1351 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 1352 func (u *ChainBaseUpsertBulk) UpdateCreatedAt() *ChainBaseUpsertBulk { 1353 return u.Update(func(s *ChainBaseUpsert) { 1354 s.UpdateCreatedAt() 1355 }) 1356 } 1357 1358 // SetUpdatedAt sets the "updated_at" field. 1359 func (u *ChainBaseUpsertBulk) SetUpdatedAt(v uint32) *ChainBaseUpsertBulk { 1360 return u.Update(func(s *ChainBaseUpsert) { 1361 s.SetUpdatedAt(v) 1362 }) 1363 } 1364 1365 // AddUpdatedAt adds v to the "updated_at" field. 1366 func (u *ChainBaseUpsertBulk) AddUpdatedAt(v uint32) *ChainBaseUpsertBulk { 1367 return u.Update(func(s *ChainBaseUpsert) { 1368 s.AddUpdatedAt(v) 1369 }) 1370 } 1371 1372 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 1373 func (u *ChainBaseUpsertBulk) UpdateUpdatedAt() *ChainBaseUpsertBulk { 1374 return u.Update(func(s *ChainBaseUpsert) { 1375 s.UpdateUpdatedAt() 1376 }) 1377 } 1378 1379 // SetDeletedAt sets the "deleted_at" field. 1380 func (u *ChainBaseUpsertBulk) SetDeletedAt(v uint32) *ChainBaseUpsertBulk { 1381 return u.Update(func(s *ChainBaseUpsert) { 1382 s.SetDeletedAt(v) 1383 }) 1384 } 1385 1386 // AddDeletedAt adds v to the "deleted_at" field. 1387 func (u *ChainBaseUpsertBulk) AddDeletedAt(v uint32) *ChainBaseUpsertBulk { 1388 return u.Update(func(s *ChainBaseUpsert) { 1389 s.AddDeletedAt(v) 1390 }) 1391 } 1392 1393 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 1394 func (u *ChainBaseUpsertBulk) UpdateDeletedAt() *ChainBaseUpsertBulk { 1395 return u.Update(func(s *ChainBaseUpsert) { 1396 s.UpdateDeletedAt() 1397 }) 1398 } 1399 1400 // SetEntID sets the "ent_id" field. 1401 func (u *ChainBaseUpsertBulk) SetEntID(v uuid.UUID) *ChainBaseUpsertBulk { 1402 return u.Update(func(s *ChainBaseUpsert) { 1403 s.SetEntID(v) 1404 }) 1405 } 1406 1407 // UpdateEntID sets the "ent_id" field to the value that was provided on create. 1408 func (u *ChainBaseUpsertBulk) UpdateEntID() *ChainBaseUpsertBulk { 1409 return u.Update(func(s *ChainBaseUpsert) { 1410 s.UpdateEntID() 1411 }) 1412 } 1413 1414 // SetName sets the "name" field. 1415 func (u *ChainBaseUpsertBulk) SetName(v string) *ChainBaseUpsertBulk { 1416 return u.Update(func(s *ChainBaseUpsert) { 1417 s.SetName(v) 1418 }) 1419 } 1420 1421 // UpdateName sets the "name" field to the value that was provided on create. 1422 func (u *ChainBaseUpsertBulk) UpdateName() *ChainBaseUpsertBulk { 1423 return u.Update(func(s *ChainBaseUpsert) { 1424 s.UpdateName() 1425 }) 1426 } 1427 1428 // ClearName clears the value of the "name" field. 1429 func (u *ChainBaseUpsertBulk) ClearName() *ChainBaseUpsertBulk { 1430 return u.Update(func(s *ChainBaseUpsert) { 1431 s.ClearName() 1432 }) 1433 } 1434 1435 // SetLogo sets the "logo" field. 1436 func (u *ChainBaseUpsertBulk) SetLogo(v string) *ChainBaseUpsertBulk { 1437 return u.Update(func(s *ChainBaseUpsert) { 1438 s.SetLogo(v) 1439 }) 1440 } 1441 1442 // UpdateLogo sets the "logo" field to the value that was provided on create. 1443 func (u *ChainBaseUpsertBulk) UpdateLogo() *ChainBaseUpsertBulk { 1444 return u.Update(func(s *ChainBaseUpsert) { 1445 s.UpdateLogo() 1446 }) 1447 } 1448 1449 // ClearLogo clears the value of the "logo" field. 1450 func (u *ChainBaseUpsertBulk) ClearLogo() *ChainBaseUpsertBulk { 1451 return u.Update(func(s *ChainBaseUpsert) { 1452 s.ClearLogo() 1453 }) 1454 } 1455 1456 // SetNativeUnit sets the "native_unit" field. 1457 func (u *ChainBaseUpsertBulk) SetNativeUnit(v string) *ChainBaseUpsertBulk { 1458 return u.Update(func(s *ChainBaseUpsert) { 1459 s.SetNativeUnit(v) 1460 }) 1461 } 1462 1463 // UpdateNativeUnit sets the "native_unit" field to the value that was provided on create. 1464 func (u *ChainBaseUpsertBulk) UpdateNativeUnit() *ChainBaseUpsertBulk { 1465 return u.Update(func(s *ChainBaseUpsert) { 1466 s.UpdateNativeUnit() 1467 }) 1468 } 1469 1470 // ClearNativeUnit clears the value of the "native_unit" field. 1471 func (u *ChainBaseUpsertBulk) ClearNativeUnit() *ChainBaseUpsertBulk { 1472 return u.Update(func(s *ChainBaseUpsert) { 1473 s.ClearNativeUnit() 1474 }) 1475 } 1476 1477 // SetAtomicUnit sets the "atomic_unit" field. 1478 func (u *ChainBaseUpsertBulk) SetAtomicUnit(v string) *ChainBaseUpsertBulk { 1479 return u.Update(func(s *ChainBaseUpsert) { 1480 s.SetAtomicUnit(v) 1481 }) 1482 } 1483 1484 // UpdateAtomicUnit sets the "atomic_unit" field to the value that was provided on create. 1485 func (u *ChainBaseUpsertBulk) UpdateAtomicUnit() *ChainBaseUpsertBulk { 1486 return u.Update(func(s *ChainBaseUpsert) { 1487 s.UpdateAtomicUnit() 1488 }) 1489 } 1490 1491 // ClearAtomicUnit clears the value of the "atomic_unit" field. 1492 func (u *ChainBaseUpsertBulk) ClearAtomicUnit() *ChainBaseUpsertBulk { 1493 return u.Update(func(s *ChainBaseUpsert) { 1494 s.ClearAtomicUnit() 1495 }) 1496 } 1497 1498 // SetUnitExp sets the "unit_exp" field. 1499 func (u *ChainBaseUpsertBulk) SetUnitExp(v uint32) *ChainBaseUpsertBulk { 1500 return u.Update(func(s *ChainBaseUpsert) { 1501 s.SetUnitExp(v) 1502 }) 1503 } 1504 1505 // AddUnitExp adds v to the "unit_exp" field. 1506 func (u *ChainBaseUpsertBulk) AddUnitExp(v uint32) *ChainBaseUpsertBulk { 1507 return u.Update(func(s *ChainBaseUpsert) { 1508 s.AddUnitExp(v) 1509 }) 1510 } 1511 1512 // UpdateUnitExp sets the "unit_exp" field to the value that was provided on create. 1513 func (u *ChainBaseUpsertBulk) UpdateUnitExp() *ChainBaseUpsertBulk { 1514 return u.Update(func(s *ChainBaseUpsert) { 1515 s.UpdateUnitExp() 1516 }) 1517 } 1518 1519 // ClearUnitExp clears the value of the "unit_exp" field. 1520 func (u *ChainBaseUpsertBulk) ClearUnitExp() *ChainBaseUpsertBulk { 1521 return u.Update(func(s *ChainBaseUpsert) { 1522 s.ClearUnitExp() 1523 }) 1524 } 1525 1526 // SetEnv sets the "env" field. 1527 func (u *ChainBaseUpsertBulk) SetEnv(v string) *ChainBaseUpsertBulk { 1528 return u.Update(func(s *ChainBaseUpsert) { 1529 s.SetEnv(v) 1530 }) 1531 } 1532 1533 // UpdateEnv sets the "env" field to the value that was provided on create. 1534 func (u *ChainBaseUpsertBulk) UpdateEnv() *ChainBaseUpsertBulk { 1535 return u.Update(func(s *ChainBaseUpsert) { 1536 s.UpdateEnv() 1537 }) 1538 } 1539 1540 // ClearEnv clears the value of the "env" field. 1541 func (u *ChainBaseUpsertBulk) ClearEnv() *ChainBaseUpsertBulk { 1542 return u.Update(func(s *ChainBaseUpsert) { 1543 s.ClearEnv() 1544 }) 1545 } 1546 1547 // SetChainID sets the "chain_id" field. 1548 func (u *ChainBaseUpsertBulk) SetChainID(v string) *ChainBaseUpsertBulk { 1549 return u.Update(func(s *ChainBaseUpsert) { 1550 s.SetChainID(v) 1551 }) 1552 } 1553 1554 // UpdateChainID sets the "chain_id" field to the value that was provided on create. 1555 func (u *ChainBaseUpsertBulk) UpdateChainID() *ChainBaseUpsertBulk { 1556 return u.Update(func(s *ChainBaseUpsert) { 1557 s.UpdateChainID() 1558 }) 1559 } 1560 1561 // ClearChainID clears the value of the "chain_id" field. 1562 func (u *ChainBaseUpsertBulk) ClearChainID() *ChainBaseUpsertBulk { 1563 return u.Update(func(s *ChainBaseUpsert) { 1564 s.ClearChainID() 1565 }) 1566 } 1567 1568 // SetNickname sets the "nickname" field. 1569 func (u *ChainBaseUpsertBulk) SetNickname(v string) *ChainBaseUpsertBulk { 1570 return u.Update(func(s *ChainBaseUpsert) { 1571 s.SetNickname(v) 1572 }) 1573 } 1574 1575 // UpdateNickname sets the "nickname" field to the value that was provided on create. 1576 func (u *ChainBaseUpsertBulk) UpdateNickname() *ChainBaseUpsertBulk { 1577 return u.Update(func(s *ChainBaseUpsert) { 1578 s.UpdateNickname() 1579 }) 1580 } 1581 1582 // ClearNickname clears the value of the "nickname" field. 1583 func (u *ChainBaseUpsertBulk) ClearNickname() *ChainBaseUpsertBulk { 1584 return u.Update(func(s *ChainBaseUpsert) { 1585 s.ClearNickname() 1586 }) 1587 } 1588 1589 // SetGasType sets the "gas_type" field. 1590 func (u *ChainBaseUpsertBulk) SetGasType(v string) *ChainBaseUpsertBulk { 1591 return u.Update(func(s *ChainBaseUpsert) { 1592 s.SetGasType(v) 1593 }) 1594 } 1595 1596 // UpdateGasType sets the "gas_type" field to the value that was provided on create. 1597 func (u *ChainBaseUpsertBulk) UpdateGasType() *ChainBaseUpsertBulk { 1598 return u.Update(func(s *ChainBaseUpsert) { 1599 s.UpdateGasType() 1600 }) 1601 } 1602 1603 // ClearGasType clears the value of the "gas_type" field. 1604 func (u *ChainBaseUpsertBulk) ClearGasType() *ChainBaseUpsertBulk { 1605 return u.Update(func(s *ChainBaseUpsert) { 1606 s.ClearGasType() 1607 }) 1608 } 1609 1610 // Exec executes the query. 1611 func (u *ChainBaseUpsertBulk) Exec(ctx context.Context) error { 1612 for i, b := range u.create.builders { 1613 if len(b.conflict) != 0 { 1614 return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ChainBaseCreateBulk instead", i) 1615 } 1616 } 1617 if len(u.create.conflict) == 0 { 1618 return errors.New("ent: missing options for ChainBaseCreateBulk.OnConflict") 1619 } 1620 return u.create.Exec(ctx) 1621 } 1622 1623 // ExecX is like Exec, but panics if an error occurs. 1624 func (u *ChainBaseUpsertBulk) ExecX(ctx context.Context) { 1625 if err := u.create.Exec(ctx); err != nil { 1626 panic(err) 1627 } 1628 }