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