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