github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/chainbase_update.go (about) 1 // Code generated by ent, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "errors" 8 "fmt" 9 10 "entgo.io/ent/dialect/sql" 11 "entgo.io/ent/dialect/sql/sqlgraph" 12 "entgo.io/ent/schema/field" 13 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/chainbase" 14 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent/predicate" 15 "github.com/google/uuid" 16 ) 17 18 // ChainBaseUpdate is the builder for updating ChainBase entities. 19 type ChainBaseUpdate struct { 20 config 21 hooks []Hook 22 mutation *ChainBaseMutation 23 modifiers []func(*sql.UpdateBuilder) 24 } 25 26 // Where appends a list predicates to the ChainBaseUpdate builder. 27 func (cbu *ChainBaseUpdate) Where(ps ...predicate.ChainBase) *ChainBaseUpdate { 28 cbu.mutation.Where(ps...) 29 return cbu 30 } 31 32 // SetCreatedAt sets the "created_at" field. 33 func (cbu *ChainBaseUpdate) SetCreatedAt(u uint32) *ChainBaseUpdate { 34 cbu.mutation.ResetCreatedAt() 35 cbu.mutation.SetCreatedAt(u) 36 return cbu 37 } 38 39 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 40 func (cbu *ChainBaseUpdate) SetNillableCreatedAt(u *uint32) *ChainBaseUpdate { 41 if u != nil { 42 cbu.SetCreatedAt(*u) 43 } 44 return cbu 45 } 46 47 // AddCreatedAt adds u to the "created_at" field. 48 func (cbu *ChainBaseUpdate) AddCreatedAt(u int32) *ChainBaseUpdate { 49 cbu.mutation.AddCreatedAt(u) 50 return cbu 51 } 52 53 // SetUpdatedAt sets the "updated_at" field. 54 func (cbu *ChainBaseUpdate) SetUpdatedAt(u uint32) *ChainBaseUpdate { 55 cbu.mutation.ResetUpdatedAt() 56 cbu.mutation.SetUpdatedAt(u) 57 return cbu 58 } 59 60 // AddUpdatedAt adds u to the "updated_at" field. 61 func (cbu *ChainBaseUpdate) AddUpdatedAt(u int32) *ChainBaseUpdate { 62 cbu.mutation.AddUpdatedAt(u) 63 return cbu 64 } 65 66 // SetDeletedAt sets the "deleted_at" field. 67 func (cbu *ChainBaseUpdate) SetDeletedAt(u uint32) *ChainBaseUpdate { 68 cbu.mutation.ResetDeletedAt() 69 cbu.mutation.SetDeletedAt(u) 70 return cbu 71 } 72 73 // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. 74 func (cbu *ChainBaseUpdate) SetNillableDeletedAt(u *uint32) *ChainBaseUpdate { 75 if u != nil { 76 cbu.SetDeletedAt(*u) 77 } 78 return cbu 79 } 80 81 // AddDeletedAt adds u to the "deleted_at" field. 82 func (cbu *ChainBaseUpdate) AddDeletedAt(u int32) *ChainBaseUpdate { 83 cbu.mutation.AddDeletedAt(u) 84 return cbu 85 } 86 87 // SetEntID sets the "ent_id" field. 88 func (cbu *ChainBaseUpdate) SetEntID(u uuid.UUID) *ChainBaseUpdate { 89 cbu.mutation.SetEntID(u) 90 return cbu 91 } 92 93 // SetNillableEntID sets the "ent_id" field if the given value is not nil. 94 func (cbu *ChainBaseUpdate) SetNillableEntID(u *uuid.UUID) *ChainBaseUpdate { 95 if u != nil { 96 cbu.SetEntID(*u) 97 } 98 return cbu 99 } 100 101 // SetName sets the "name" field. 102 func (cbu *ChainBaseUpdate) SetName(s string) *ChainBaseUpdate { 103 cbu.mutation.SetName(s) 104 return cbu 105 } 106 107 // SetNillableName sets the "name" field if the given value is not nil. 108 func (cbu *ChainBaseUpdate) SetNillableName(s *string) *ChainBaseUpdate { 109 if s != nil { 110 cbu.SetName(*s) 111 } 112 return cbu 113 } 114 115 // ClearName clears the value of the "name" field. 116 func (cbu *ChainBaseUpdate) ClearName() *ChainBaseUpdate { 117 cbu.mutation.ClearName() 118 return cbu 119 } 120 121 // SetLogo sets the "logo" field. 122 func (cbu *ChainBaseUpdate) SetLogo(s string) *ChainBaseUpdate { 123 cbu.mutation.SetLogo(s) 124 return cbu 125 } 126 127 // SetNillableLogo sets the "logo" field if the given value is not nil. 128 func (cbu *ChainBaseUpdate) SetNillableLogo(s *string) *ChainBaseUpdate { 129 if s != nil { 130 cbu.SetLogo(*s) 131 } 132 return cbu 133 } 134 135 // ClearLogo clears the value of the "logo" field. 136 func (cbu *ChainBaseUpdate) ClearLogo() *ChainBaseUpdate { 137 cbu.mutation.ClearLogo() 138 return cbu 139 } 140 141 // SetNativeUnit sets the "native_unit" field. 142 func (cbu *ChainBaseUpdate) SetNativeUnit(s string) *ChainBaseUpdate { 143 cbu.mutation.SetNativeUnit(s) 144 return cbu 145 } 146 147 // SetNillableNativeUnit sets the "native_unit" field if the given value is not nil. 148 func (cbu *ChainBaseUpdate) SetNillableNativeUnit(s *string) *ChainBaseUpdate { 149 if s != nil { 150 cbu.SetNativeUnit(*s) 151 } 152 return cbu 153 } 154 155 // ClearNativeUnit clears the value of the "native_unit" field. 156 func (cbu *ChainBaseUpdate) ClearNativeUnit() *ChainBaseUpdate { 157 cbu.mutation.ClearNativeUnit() 158 return cbu 159 } 160 161 // SetAtomicUnit sets the "atomic_unit" field. 162 func (cbu *ChainBaseUpdate) SetAtomicUnit(s string) *ChainBaseUpdate { 163 cbu.mutation.SetAtomicUnit(s) 164 return cbu 165 } 166 167 // SetNillableAtomicUnit sets the "atomic_unit" field if the given value is not nil. 168 func (cbu *ChainBaseUpdate) SetNillableAtomicUnit(s *string) *ChainBaseUpdate { 169 if s != nil { 170 cbu.SetAtomicUnit(*s) 171 } 172 return cbu 173 } 174 175 // ClearAtomicUnit clears the value of the "atomic_unit" field. 176 func (cbu *ChainBaseUpdate) ClearAtomicUnit() *ChainBaseUpdate { 177 cbu.mutation.ClearAtomicUnit() 178 return cbu 179 } 180 181 // SetUnitExp sets the "unit_exp" field. 182 func (cbu *ChainBaseUpdate) SetUnitExp(u uint32) *ChainBaseUpdate { 183 cbu.mutation.ResetUnitExp() 184 cbu.mutation.SetUnitExp(u) 185 return cbu 186 } 187 188 // SetNillableUnitExp sets the "unit_exp" field if the given value is not nil. 189 func (cbu *ChainBaseUpdate) SetNillableUnitExp(u *uint32) *ChainBaseUpdate { 190 if u != nil { 191 cbu.SetUnitExp(*u) 192 } 193 return cbu 194 } 195 196 // AddUnitExp adds u to the "unit_exp" field. 197 func (cbu *ChainBaseUpdate) AddUnitExp(u int32) *ChainBaseUpdate { 198 cbu.mutation.AddUnitExp(u) 199 return cbu 200 } 201 202 // ClearUnitExp clears the value of the "unit_exp" field. 203 func (cbu *ChainBaseUpdate) ClearUnitExp() *ChainBaseUpdate { 204 cbu.mutation.ClearUnitExp() 205 return cbu 206 } 207 208 // SetEnv sets the "env" field. 209 func (cbu *ChainBaseUpdate) SetEnv(s string) *ChainBaseUpdate { 210 cbu.mutation.SetEnv(s) 211 return cbu 212 } 213 214 // SetNillableEnv sets the "env" field if the given value is not nil. 215 func (cbu *ChainBaseUpdate) SetNillableEnv(s *string) *ChainBaseUpdate { 216 if s != nil { 217 cbu.SetEnv(*s) 218 } 219 return cbu 220 } 221 222 // ClearEnv clears the value of the "env" field. 223 func (cbu *ChainBaseUpdate) ClearEnv() *ChainBaseUpdate { 224 cbu.mutation.ClearEnv() 225 return cbu 226 } 227 228 // SetChainID sets the "chain_id" field. 229 func (cbu *ChainBaseUpdate) SetChainID(s string) *ChainBaseUpdate { 230 cbu.mutation.SetChainID(s) 231 return cbu 232 } 233 234 // SetNillableChainID sets the "chain_id" field if the given value is not nil. 235 func (cbu *ChainBaseUpdate) SetNillableChainID(s *string) *ChainBaseUpdate { 236 if s != nil { 237 cbu.SetChainID(*s) 238 } 239 return cbu 240 } 241 242 // ClearChainID clears the value of the "chain_id" field. 243 func (cbu *ChainBaseUpdate) ClearChainID() *ChainBaseUpdate { 244 cbu.mutation.ClearChainID() 245 return cbu 246 } 247 248 // SetNickname sets the "nickname" field. 249 func (cbu *ChainBaseUpdate) SetNickname(s string) *ChainBaseUpdate { 250 cbu.mutation.SetNickname(s) 251 return cbu 252 } 253 254 // SetNillableNickname sets the "nickname" field if the given value is not nil. 255 func (cbu *ChainBaseUpdate) SetNillableNickname(s *string) *ChainBaseUpdate { 256 if s != nil { 257 cbu.SetNickname(*s) 258 } 259 return cbu 260 } 261 262 // ClearNickname clears the value of the "nickname" field. 263 func (cbu *ChainBaseUpdate) ClearNickname() *ChainBaseUpdate { 264 cbu.mutation.ClearNickname() 265 return cbu 266 } 267 268 // SetGasType sets the "gas_type" field. 269 func (cbu *ChainBaseUpdate) SetGasType(s string) *ChainBaseUpdate { 270 cbu.mutation.SetGasType(s) 271 return cbu 272 } 273 274 // SetNillableGasType sets the "gas_type" field if the given value is not nil. 275 func (cbu *ChainBaseUpdate) SetNillableGasType(s *string) *ChainBaseUpdate { 276 if s != nil { 277 cbu.SetGasType(*s) 278 } 279 return cbu 280 } 281 282 // ClearGasType clears the value of the "gas_type" field. 283 func (cbu *ChainBaseUpdate) ClearGasType() *ChainBaseUpdate { 284 cbu.mutation.ClearGasType() 285 return cbu 286 } 287 288 // Mutation returns the ChainBaseMutation object of the builder. 289 func (cbu *ChainBaseUpdate) Mutation() *ChainBaseMutation { 290 return cbu.mutation 291 } 292 293 // Save executes the query and returns the number of nodes affected by the update operation. 294 func (cbu *ChainBaseUpdate) Save(ctx context.Context) (int, error) { 295 var ( 296 err error 297 affected int 298 ) 299 if err := cbu.defaults(); err != nil { 300 return 0, err 301 } 302 if len(cbu.hooks) == 0 { 303 affected, err = cbu.sqlSave(ctx) 304 } else { 305 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 306 mutation, ok := m.(*ChainBaseMutation) 307 if !ok { 308 return nil, fmt.Errorf("unexpected mutation type %T", m) 309 } 310 cbu.mutation = mutation 311 affected, err = cbu.sqlSave(ctx) 312 mutation.done = true 313 return affected, err 314 }) 315 for i := len(cbu.hooks) - 1; i >= 0; i-- { 316 if cbu.hooks[i] == nil { 317 return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 318 } 319 mut = cbu.hooks[i](mut) 320 } 321 if _, err := mut.Mutate(ctx, cbu.mutation); err != nil { 322 return 0, err 323 } 324 } 325 return affected, err 326 } 327 328 // SaveX is like Save, but panics if an error occurs. 329 func (cbu *ChainBaseUpdate) SaveX(ctx context.Context) int { 330 affected, err := cbu.Save(ctx) 331 if err != nil { 332 panic(err) 333 } 334 return affected 335 } 336 337 // Exec executes the query. 338 func (cbu *ChainBaseUpdate) Exec(ctx context.Context) error { 339 _, err := cbu.Save(ctx) 340 return err 341 } 342 343 // ExecX is like Exec, but panics if an error occurs. 344 func (cbu *ChainBaseUpdate) ExecX(ctx context.Context) { 345 if err := cbu.Exec(ctx); err != nil { 346 panic(err) 347 } 348 } 349 350 // defaults sets the default values of the builder before save. 351 func (cbu *ChainBaseUpdate) defaults() error { 352 if _, ok := cbu.mutation.UpdatedAt(); !ok { 353 if chainbase.UpdateDefaultUpdatedAt == nil { 354 return fmt.Errorf("ent: uninitialized chainbase.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") 355 } 356 v := chainbase.UpdateDefaultUpdatedAt() 357 cbu.mutation.SetUpdatedAt(v) 358 } 359 return nil 360 } 361 362 // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. 363 func (cbu *ChainBaseUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ChainBaseUpdate { 364 cbu.modifiers = append(cbu.modifiers, modifiers...) 365 return cbu 366 } 367 368 func (cbu *ChainBaseUpdate) sqlSave(ctx context.Context) (n int, err error) { 369 _spec := &sqlgraph.UpdateSpec{ 370 Node: &sqlgraph.NodeSpec{ 371 Table: chainbase.Table, 372 Columns: chainbase.Columns, 373 ID: &sqlgraph.FieldSpec{ 374 Type: field.TypeUint32, 375 Column: chainbase.FieldID, 376 }, 377 }, 378 } 379 if ps := cbu.mutation.predicates; len(ps) > 0 { 380 _spec.Predicate = func(selector *sql.Selector) { 381 for i := range ps { 382 ps[i](selector) 383 } 384 } 385 } 386 if value, ok := cbu.mutation.CreatedAt(); ok { 387 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 388 Type: field.TypeUint32, 389 Value: value, 390 Column: chainbase.FieldCreatedAt, 391 }) 392 } 393 if value, ok := cbu.mutation.AddedCreatedAt(); ok { 394 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 395 Type: field.TypeUint32, 396 Value: value, 397 Column: chainbase.FieldCreatedAt, 398 }) 399 } 400 if value, ok := cbu.mutation.UpdatedAt(); ok { 401 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 402 Type: field.TypeUint32, 403 Value: value, 404 Column: chainbase.FieldUpdatedAt, 405 }) 406 } 407 if value, ok := cbu.mutation.AddedUpdatedAt(); ok { 408 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 409 Type: field.TypeUint32, 410 Value: value, 411 Column: chainbase.FieldUpdatedAt, 412 }) 413 } 414 if value, ok := cbu.mutation.DeletedAt(); ok { 415 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 416 Type: field.TypeUint32, 417 Value: value, 418 Column: chainbase.FieldDeletedAt, 419 }) 420 } 421 if value, ok := cbu.mutation.AddedDeletedAt(); ok { 422 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 423 Type: field.TypeUint32, 424 Value: value, 425 Column: chainbase.FieldDeletedAt, 426 }) 427 } 428 if value, ok := cbu.mutation.EntID(); ok { 429 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 430 Type: field.TypeUUID, 431 Value: value, 432 Column: chainbase.FieldEntID, 433 }) 434 } 435 if value, ok := cbu.mutation.Name(); ok { 436 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 437 Type: field.TypeString, 438 Value: value, 439 Column: chainbase.FieldName, 440 }) 441 } 442 if cbu.mutation.NameCleared() { 443 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 444 Type: field.TypeString, 445 Column: chainbase.FieldName, 446 }) 447 } 448 if value, ok := cbu.mutation.Logo(); ok { 449 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 450 Type: field.TypeString, 451 Value: value, 452 Column: chainbase.FieldLogo, 453 }) 454 } 455 if cbu.mutation.LogoCleared() { 456 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 457 Type: field.TypeString, 458 Column: chainbase.FieldLogo, 459 }) 460 } 461 if value, ok := cbu.mutation.NativeUnit(); ok { 462 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 463 Type: field.TypeString, 464 Value: value, 465 Column: chainbase.FieldNativeUnit, 466 }) 467 } 468 if cbu.mutation.NativeUnitCleared() { 469 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 470 Type: field.TypeString, 471 Column: chainbase.FieldNativeUnit, 472 }) 473 } 474 if value, ok := cbu.mutation.AtomicUnit(); ok { 475 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 476 Type: field.TypeString, 477 Value: value, 478 Column: chainbase.FieldAtomicUnit, 479 }) 480 } 481 if cbu.mutation.AtomicUnitCleared() { 482 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 483 Type: field.TypeString, 484 Column: chainbase.FieldAtomicUnit, 485 }) 486 } 487 if value, ok := cbu.mutation.UnitExp(); ok { 488 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 489 Type: field.TypeUint32, 490 Value: value, 491 Column: chainbase.FieldUnitExp, 492 }) 493 } 494 if value, ok := cbu.mutation.AddedUnitExp(); ok { 495 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 496 Type: field.TypeUint32, 497 Value: value, 498 Column: chainbase.FieldUnitExp, 499 }) 500 } 501 if cbu.mutation.UnitExpCleared() { 502 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 503 Type: field.TypeUint32, 504 Column: chainbase.FieldUnitExp, 505 }) 506 } 507 if value, ok := cbu.mutation.Env(); ok { 508 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 509 Type: field.TypeString, 510 Value: value, 511 Column: chainbase.FieldEnv, 512 }) 513 } 514 if cbu.mutation.EnvCleared() { 515 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 516 Type: field.TypeString, 517 Column: chainbase.FieldEnv, 518 }) 519 } 520 if value, ok := cbu.mutation.ChainID(); ok { 521 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 522 Type: field.TypeString, 523 Value: value, 524 Column: chainbase.FieldChainID, 525 }) 526 } 527 if cbu.mutation.ChainIDCleared() { 528 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 529 Type: field.TypeString, 530 Column: chainbase.FieldChainID, 531 }) 532 } 533 if value, ok := cbu.mutation.Nickname(); ok { 534 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 535 Type: field.TypeString, 536 Value: value, 537 Column: chainbase.FieldNickname, 538 }) 539 } 540 if cbu.mutation.NicknameCleared() { 541 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 542 Type: field.TypeString, 543 Column: chainbase.FieldNickname, 544 }) 545 } 546 if value, ok := cbu.mutation.GasType(); ok { 547 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 548 Type: field.TypeString, 549 Value: value, 550 Column: chainbase.FieldGasType, 551 }) 552 } 553 if cbu.mutation.GasTypeCleared() { 554 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 555 Type: field.TypeString, 556 Column: chainbase.FieldGasType, 557 }) 558 } 559 _spec.Modifiers = cbu.modifiers 560 if n, err = sqlgraph.UpdateNodes(ctx, cbu.driver, _spec); err != nil { 561 if _, ok := err.(*sqlgraph.NotFoundError); ok { 562 err = &NotFoundError{chainbase.Label} 563 } else if sqlgraph.IsConstraintError(err) { 564 err = &ConstraintError{msg: err.Error(), wrap: err} 565 } 566 return 0, err 567 } 568 return n, nil 569 } 570 571 // ChainBaseUpdateOne is the builder for updating a single ChainBase entity. 572 type ChainBaseUpdateOne struct { 573 config 574 fields []string 575 hooks []Hook 576 mutation *ChainBaseMutation 577 modifiers []func(*sql.UpdateBuilder) 578 } 579 580 // SetCreatedAt sets the "created_at" field. 581 func (cbuo *ChainBaseUpdateOne) SetCreatedAt(u uint32) *ChainBaseUpdateOne { 582 cbuo.mutation.ResetCreatedAt() 583 cbuo.mutation.SetCreatedAt(u) 584 return cbuo 585 } 586 587 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 588 func (cbuo *ChainBaseUpdateOne) SetNillableCreatedAt(u *uint32) *ChainBaseUpdateOne { 589 if u != nil { 590 cbuo.SetCreatedAt(*u) 591 } 592 return cbuo 593 } 594 595 // AddCreatedAt adds u to the "created_at" field. 596 func (cbuo *ChainBaseUpdateOne) AddCreatedAt(u int32) *ChainBaseUpdateOne { 597 cbuo.mutation.AddCreatedAt(u) 598 return cbuo 599 } 600 601 // SetUpdatedAt sets the "updated_at" field. 602 func (cbuo *ChainBaseUpdateOne) SetUpdatedAt(u uint32) *ChainBaseUpdateOne { 603 cbuo.mutation.ResetUpdatedAt() 604 cbuo.mutation.SetUpdatedAt(u) 605 return cbuo 606 } 607 608 // AddUpdatedAt adds u to the "updated_at" field. 609 func (cbuo *ChainBaseUpdateOne) AddUpdatedAt(u int32) *ChainBaseUpdateOne { 610 cbuo.mutation.AddUpdatedAt(u) 611 return cbuo 612 } 613 614 // SetDeletedAt sets the "deleted_at" field. 615 func (cbuo *ChainBaseUpdateOne) SetDeletedAt(u uint32) *ChainBaseUpdateOne { 616 cbuo.mutation.ResetDeletedAt() 617 cbuo.mutation.SetDeletedAt(u) 618 return cbuo 619 } 620 621 // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. 622 func (cbuo *ChainBaseUpdateOne) SetNillableDeletedAt(u *uint32) *ChainBaseUpdateOne { 623 if u != nil { 624 cbuo.SetDeletedAt(*u) 625 } 626 return cbuo 627 } 628 629 // AddDeletedAt adds u to the "deleted_at" field. 630 func (cbuo *ChainBaseUpdateOne) AddDeletedAt(u int32) *ChainBaseUpdateOne { 631 cbuo.mutation.AddDeletedAt(u) 632 return cbuo 633 } 634 635 // SetEntID sets the "ent_id" field. 636 func (cbuo *ChainBaseUpdateOne) SetEntID(u uuid.UUID) *ChainBaseUpdateOne { 637 cbuo.mutation.SetEntID(u) 638 return cbuo 639 } 640 641 // SetNillableEntID sets the "ent_id" field if the given value is not nil. 642 func (cbuo *ChainBaseUpdateOne) SetNillableEntID(u *uuid.UUID) *ChainBaseUpdateOne { 643 if u != nil { 644 cbuo.SetEntID(*u) 645 } 646 return cbuo 647 } 648 649 // SetName sets the "name" field. 650 func (cbuo *ChainBaseUpdateOne) SetName(s string) *ChainBaseUpdateOne { 651 cbuo.mutation.SetName(s) 652 return cbuo 653 } 654 655 // SetNillableName sets the "name" field if the given value is not nil. 656 func (cbuo *ChainBaseUpdateOne) SetNillableName(s *string) *ChainBaseUpdateOne { 657 if s != nil { 658 cbuo.SetName(*s) 659 } 660 return cbuo 661 } 662 663 // ClearName clears the value of the "name" field. 664 func (cbuo *ChainBaseUpdateOne) ClearName() *ChainBaseUpdateOne { 665 cbuo.mutation.ClearName() 666 return cbuo 667 } 668 669 // SetLogo sets the "logo" field. 670 func (cbuo *ChainBaseUpdateOne) SetLogo(s string) *ChainBaseUpdateOne { 671 cbuo.mutation.SetLogo(s) 672 return cbuo 673 } 674 675 // SetNillableLogo sets the "logo" field if the given value is not nil. 676 func (cbuo *ChainBaseUpdateOne) SetNillableLogo(s *string) *ChainBaseUpdateOne { 677 if s != nil { 678 cbuo.SetLogo(*s) 679 } 680 return cbuo 681 } 682 683 // ClearLogo clears the value of the "logo" field. 684 func (cbuo *ChainBaseUpdateOne) ClearLogo() *ChainBaseUpdateOne { 685 cbuo.mutation.ClearLogo() 686 return cbuo 687 } 688 689 // SetNativeUnit sets the "native_unit" field. 690 func (cbuo *ChainBaseUpdateOne) SetNativeUnit(s string) *ChainBaseUpdateOne { 691 cbuo.mutation.SetNativeUnit(s) 692 return cbuo 693 } 694 695 // SetNillableNativeUnit sets the "native_unit" field if the given value is not nil. 696 func (cbuo *ChainBaseUpdateOne) SetNillableNativeUnit(s *string) *ChainBaseUpdateOne { 697 if s != nil { 698 cbuo.SetNativeUnit(*s) 699 } 700 return cbuo 701 } 702 703 // ClearNativeUnit clears the value of the "native_unit" field. 704 func (cbuo *ChainBaseUpdateOne) ClearNativeUnit() *ChainBaseUpdateOne { 705 cbuo.mutation.ClearNativeUnit() 706 return cbuo 707 } 708 709 // SetAtomicUnit sets the "atomic_unit" field. 710 func (cbuo *ChainBaseUpdateOne) SetAtomicUnit(s string) *ChainBaseUpdateOne { 711 cbuo.mutation.SetAtomicUnit(s) 712 return cbuo 713 } 714 715 // SetNillableAtomicUnit sets the "atomic_unit" field if the given value is not nil. 716 func (cbuo *ChainBaseUpdateOne) SetNillableAtomicUnit(s *string) *ChainBaseUpdateOne { 717 if s != nil { 718 cbuo.SetAtomicUnit(*s) 719 } 720 return cbuo 721 } 722 723 // ClearAtomicUnit clears the value of the "atomic_unit" field. 724 func (cbuo *ChainBaseUpdateOne) ClearAtomicUnit() *ChainBaseUpdateOne { 725 cbuo.mutation.ClearAtomicUnit() 726 return cbuo 727 } 728 729 // SetUnitExp sets the "unit_exp" field. 730 func (cbuo *ChainBaseUpdateOne) SetUnitExp(u uint32) *ChainBaseUpdateOne { 731 cbuo.mutation.ResetUnitExp() 732 cbuo.mutation.SetUnitExp(u) 733 return cbuo 734 } 735 736 // SetNillableUnitExp sets the "unit_exp" field if the given value is not nil. 737 func (cbuo *ChainBaseUpdateOne) SetNillableUnitExp(u *uint32) *ChainBaseUpdateOne { 738 if u != nil { 739 cbuo.SetUnitExp(*u) 740 } 741 return cbuo 742 } 743 744 // AddUnitExp adds u to the "unit_exp" field. 745 func (cbuo *ChainBaseUpdateOne) AddUnitExp(u int32) *ChainBaseUpdateOne { 746 cbuo.mutation.AddUnitExp(u) 747 return cbuo 748 } 749 750 // ClearUnitExp clears the value of the "unit_exp" field. 751 func (cbuo *ChainBaseUpdateOne) ClearUnitExp() *ChainBaseUpdateOne { 752 cbuo.mutation.ClearUnitExp() 753 return cbuo 754 } 755 756 // SetEnv sets the "env" field. 757 func (cbuo *ChainBaseUpdateOne) SetEnv(s string) *ChainBaseUpdateOne { 758 cbuo.mutation.SetEnv(s) 759 return cbuo 760 } 761 762 // SetNillableEnv sets the "env" field if the given value is not nil. 763 func (cbuo *ChainBaseUpdateOne) SetNillableEnv(s *string) *ChainBaseUpdateOne { 764 if s != nil { 765 cbuo.SetEnv(*s) 766 } 767 return cbuo 768 } 769 770 // ClearEnv clears the value of the "env" field. 771 func (cbuo *ChainBaseUpdateOne) ClearEnv() *ChainBaseUpdateOne { 772 cbuo.mutation.ClearEnv() 773 return cbuo 774 } 775 776 // SetChainID sets the "chain_id" field. 777 func (cbuo *ChainBaseUpdateOne) SetChainID(s string) *ChainBaseUpdateOne { 778 cbuo.mutation.SetChainID(s) 779 return cbuo 780 } 781 782 // SetNillableChainID sets the "chain_id" field if the given value is not nil. 783 func (cbuo *ChainBaseUpdateOne) SetNillableChainID(s *string) *ChainBaseUpdateOne { 784 if s != nil { 785 cbuo.SetChainID(*s) 786 } 787 return cbuo 788 } 789 790 // ClearChainID clears the value of the "chain_id" field. 791 func (cbuo *ChainBaseUpdateOne) ClearChainID() *ChainBaseUpdateOne { 792 cbuo.mutation.ClearChainID() 793 return cbuo 794 } 795 796 // SetNickname sets the "nickname" field. 797 func (cbuo *ChainBaseUpdateOne) SetNickname(s string) *ChainBaseUpdateOne { 798 cbuo.mutation.SetNickname(s) 799 return cbuo 800 } 801 802 // SetNillableNickname sets the "nickname" field if the given value is not nil. 803 func (cbuo *ChainBaseUpdateOne) SetNillableNickname(s *string) *ChainBaseUpdateOne { 804 if s != nil { 805 cbuo.SetNickname(*s) 806 } 807 return cbuo 808 } 809 810 // ClearNickname clears the value of the "nickname" field. 811 func (cbuo *ChainBaseUpdateOne) ClearNickname() *ChainBaseUpdateOne { 812 cbuo.mutation.ClearNickname() 813 return cbuo 814 } 815 816 // SetGasType sets the "gas_type" field. 817 func (cbuo *ChainBaseUpdateOne) SetGasType(s string) *ChainBaseUpdateOne { 818 cbuo.mutation.SetGasType(s) 819 return cbuo 820 } 821 822 // SetNillableGasType sets the "gas_type" field if the given value is not nil. 823 func (cbuo *ChainBaseUpdateOne) SetNillableGasType(s *string) *ChainBaseUpdateOne { 824 if s != nil { 825 cbuo.SetGasType(*s) 826 } 827 return cbuo 828 } 829 830 // ClearGasType clears the value of the "gas_type" field. 831 func (cbuo *ChainBaseUpdateOne) ClearGasType() *ChainBaseUpdateOne { 832 cbuo.mutation.ClearGasType() 833 return cbuo 834 } 835 836 // Mutation returns the ChainBaseMutation object of the builder. 837 func (cbuo *ChainBaseUpdateOne) Mutation() *ChainBaseMutation { 838 return cbuo.mutation 839 } 840 841 // Select allows selecting one or more fields (columns) of the returned entity. 842 // The default is selecting all fields defined in the entity schema. 843 func (cbuo *ChainBaseUpdateOne) Select(field string, fields ...string) *ChainBaseUpdateOne { 844 cbuo.fields = append([]string{field}, fields...) 845 return cbuo 846 } 847 848 // Save executes the query and returns the updated ChainBase entity. 849 func (cbuo *ChainBaseUpdateOne) Save(ctx context.Context) (*ChainBase, error) { 850 var ( 851 err error 852 node *ChainBase 853 ) 854 if err := cbuo.defaults(); err != nil { 855 return nil, err 856 } 857 if len(cbuo.hooks) == 0 { 858 node, err = cbuo.sqlSave(ctx) 859 } else { 860 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 861 mutation, ok := m.(*ChainBaseMutation) 862 if !ok { 863 return nil, fmt.Errorf("unexpected mutation type %T", m) 864 } 865 cbuo.mutation = mutation 866 node, err = cbuo.sqlSave(ctx) 867 mutation.done = true 868 return node, err 869 }) 870 for i := len(cbuo.hooks) - 1; i >= 0; i-- { 871 if cbuo.hooks[i] == nil { 872 return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 873 } 874 mut = cbuo.hooks[i](mut) 875 } 876 v, err := mut.Mutate(ctx, cbuo.mutation) 877 if err != nil { 878 return nil, err 879 } 880 nv, ok := v.(*ChainBase) 881 if !ok { 882 return nil, fmt.Errorf("unexpected node type %T returned from ChainBaseMutation", v) 883 } 884 node = nv 885 } 886 return node, err 887 } 888 889 // SaveX is like Save, but panics if an error occurs. 890 func (cbuo *ChainBaseUpdateOne) SaveX(ctx context.Context) *ChainBase { 891 node, err := cbuo.Save(ctx) 892 if err != nil { 893 panic(err) 894 } 895 return node 896 } 897 898 // Exec executes the query on the entity. 899 func (cbuo *ChainBaseUpdateOne) Exec(ctx context.Context) error { 900 _, err := cbuo.Save(ctx) 901 return err 902 } 903 904 // ExecX is like Exec, but panics if an error occurs. 905 func (cbuo *ChainBaseUpdateOne) ExecX(ctx context.Context) { 906 if err := cbuo.Exec(ctx); err != nil { 907 panic(err) 908 } 909 } 910 911 // defaults sets the default values of the builder before save. 912 func (cbuo *ChainBaseUpdateOne) defaults() error { 913 if _, ok := cbuo.mutation.UpdatedAt(); !ok { 914 if chainbase.UpdateDefaultUpdatedAt == nil { 915 return fmt.Errorf("ent: uninitialized chainbase.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") 916 } 917 v := chainbase.UpdateDefaultUpdatedAt() 918 cbuo.mutation.SetUpdatedAt(v) 919 } 920 return nil 921 } 922 923 // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. 924 func (cbuo *ChainBaseUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ChainBaseUpdateOne { 925 cbuo.modifiers = append(cbuo.modifiers, modifiers...) 926 return cbuo 927 } 928 929 func (cbuo *ChainBaseUpdateOne) sqlSave(ctx context.Context) (_node *ChainBase, err error) { 930 _spec := &sqlgraph.UpdateSpec{ 931 Node: &sqlgraph.NodeSpec{ 932 Table: chainbase.Table, 933 Columns: chainbase.Columns, 934 ID: &sqlgraph.FieldSpec{ 935 Type: field.TypeUint32, 936 Column: chainbase.FieldID, 937 }, 938 }, 939 } 940 id, ok := cbuo.mutation.ID() 941 if !ok { 942 return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChainBase.id" for update`)} 943 } 944 _spec.Node.ID.Value = id 945 if fields := cbuo.fields; len(fields) > 0 { 946 _spec.Node.Columns = make([]string, 0, len(fields)) 947 _spec.Node.Columns = append(_spec.Node.Columns, chainbase.FieldID) 948 for _, f := range fields { 949 if !chainbase.ValidColumn(f) { 950 return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} 951 } 952 if f != chainbase.FieldID { 953 _spec.Node.Columns = append(_spec.Node.Columns, f) 954 } 955 } 956 } 957 if ps := cbuo.mutation.predicates; len(ps) > 0 { 958 _spec.Predicate = func(selector *sql.Selector) { 959 for i := range ps { 960 ps[i](selector) 961 } 962 } 963 } 964 if value, ok := cbuo.mutation.CreatedAt(); ok { 965 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 966 Type: field.TypeUint32, 967 Value: value, 968 Column: chainbase.FieldCreatedAt, 969 }) 970 } 971 if value, ok := cbuo.mutation.AddedCreatedAt(); ok { 972 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 973 Type: field.TypeUint32, 974 Value: value, 975 Column: chainbase.FieldCreatedAt, 976 }) 977 } 978 if value, ok := cbuo.mutation.UpdatedAt(); ok { 979 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 980 Type: field.TypeUint32, 981 Value: value, 982 Column: chainbase.FieldUpdatedAt, 983 }) 984 } 985 if value, ok := cbuo.mutation.AddedUpdatedAt(); ok { 986 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 987 Type: field.TypeUint32, 988 Value: value, 989 Column: chainbase.FieldUpdatedAt, 990 }) 991 } 992 if value, ok := cbuo.mutation.DeletedAt(); ok { 993 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 994 Type: field.TypeUint32, 995 Value: value, 996 Column: chainbase.FieldDeletedAt, 997 }) 998 } 999 if value, ok := cbuo.mutation.AddedDeletedAt(); ok { 1000 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 1001 Type: field.TypeUint32, 1002 Value: value, 1003 Column: chainbase.FieldDeletedAt, 1004 }) 1005 } 1006 if value, ok := cbuo.mutation.EntID(); ok { 1007 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1008 Type: field.TypeUUID, 1009 Value: value, 1010 Column: chainbase.FieldEntID, 1011 }) 1012 } 1013 if value, ok := cbuo.mutation.Name(); ok { 1014 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1015 Type: field.TypeString, 1016 Value: value, 1017 Column: chainbase.FieldName, 1018 }) 1019 } 1020 if cbuo.mutation.NameCleared() { 1021 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1022 Type: field.TypeString, 1023 Column: chainbase.FieldName, 1024 }) 1025 } 1026 if value, ok := cbuo.mutation.Logo(); ok { 1027 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1028 Type: field.TypeString, 1029 Value: value, 1030 Column: chainbase.FieldLogo, 1031 }) 1032 } 1033 if cbuo.mutation.LogoCleared() { 1034 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1035 Type: field.TypeString, 1036 Column: chainbase.FieldLogo, 1037 }) 1038 } 1039 if value, ok := cbuo.mutation.NativeUnit(); ok { 1040 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1041 Type: field.TypeString, 1042 Value: value, 1043 Column: chainbase.FieldNativeUnit, 1044 }) 1045 } 1046 if cbuo.mutation.NativeUnitCleared() { 1047 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1048 Type: field.TypeString, 1049 Column: chainbase.FieldNativeUnit, 1050 }) 1051 } 1052 if value, ok := cbuo.mutation.AtomicUnit(); ok { 1053 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1054 Type: field.TypeString, 1055 Value: value, 1056 Column: chainbase.FieldAtomicUnit, 1057 }) 1058 } 1059 if cbuo.mutation.AtomicUnitCleared() { 1060 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1061 Type: field.TypeString, 1062 Column: chainbase.FieldAtomicUnit, 1063 }) 1064 } 1065 if value, ok := cbuo.mutation.UnitExp(); ok { 1066 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1067 Type: field.TypeUint32, 1068 Value: value, 1069 Column: chainbase.FieldUnitExp, 1070 }) 1071 } 1072 if value, ok := cbuo.mutation.AddedUnitExp(); ok { 1073 _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ 1074 Type: field.TypeUint32, 1075 Value: value, 1076 Column: chainbase.FieldUnitExp, 1077 }) 1078 } 1079 if cbuo.mutation.UnitExpCleared() { 1080 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1081 Type: field.TypeUint32, 1082 Column: chainbase.FieldUnitExp, 1083 }) 1084 } 1085 if value, ok := cbuo.mutation.Env(); ok { 1086 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1087 Type: field.TypeString, 1088 Value: value, 1089 Column: chainbase.FieldEnv, 1090 }) 1091 } 1092 if cbuo.mutation.EnvCleared() { 1093 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1094 Type: field.TypeString, 1095 Column: chainbase.FieldEnv, 1096 }) 1097 } 1098 if value, ok := cbuo.mutation.ChainID(); ok { 1099 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1100 Type: field.TypeString, 1101 Value: value, 1102 Column: chainbase.FieldChainID, 1103 }) 1104 } 1105 if cbuo.mutation.ChainIDCleared() { 1106 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1107 Type: field.TypeString, 1108 Column: chainbase.FieldChainID, 1109 }) 1110 } 1111 if value, ok := cbuo.mutation.Nickname(); ok { 1112 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1113 Type: field.TypeString, 1114 Value: value, 1115 Column: chainbase.FieldNickname, 1116 }) 1117 } 1118 if cbuo.mutation.NicknameCleared() { 1119 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1120 Type: field.TypeString, 1121 Column: chainbase.FieldNickname, 1122 }) 1123 } 1124 if value, ok := cbuo.mutation.GasType(); ok { 1125 _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ 1126 Type: field.TypeString, 1127 Value: value, 1128 Column: chainbase.FieldGasType, 1129 }) 1130 } 1131 if cbuo.mutation.GasTypeCleared() { 1132 _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ 1133 Type: field.TypeString, 1134 Column: chainbase.FieldGasType, 1135 }) 1136 } 1137 _spec.Modifiers = cbuo.modifiers 1138 _node = &ChainBase{config: cbuo.config} 1139 _spec.Assign = _node.assignValues 1140 _spec.ScanValues = _node.scanValues 1141 if err = sqlgraph.UpdateNode(ctx, cbuo.driver, _spec); err != nil { 1142 if _, ok := err.(*sqlgraph.NotFoundError); ok { 1143 err = &NotFoundError{chainbase.Label} 1144 } else if sqlgraph.IsConstraintError(err) { 1145 err = &ConstraintError{msg: err.Error(), wrap: err} 1146 } 1147 return nil, err 1148 } 1149 return _node, nil 1150 }