github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/setting_create.go (about) 1 // Code generated by entc, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "errors" 8 "fmt" 9 "time" 10 11 "entgo.io/ent/dialect/sql" 12 "entgo.io/ent/dialect/sql/sqlgraph" 13 "entgo.io/ent/schema/field" 14 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/setting" 15 ) 16 17 // SettingCreate is the builder for creating a Setting entity. 18 type SettingCreate struct { 19 config 20 mutation *SettingMutation 21 hooks []Hook 22 conflict []sql.ConflictOption 23 } 24 25 // SetCreatedAt sets the "created_at" field. 26 func (sc *SettingCreate) SetCreatedAt(t time.Time) *SettingCreate { 27 sc.mutation.SetCreatedAt(t) 28 return sc 29 } 30 31 // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. 32 func (sc *SettingCreate) SetNillableCreatedAt(t *time.Time) *SettingCreate { 33 if t != nil { 34 sc.SetCreatedAt(*t) 35 } 36 return sc 37 } 38 39 // SetUpdatedAt sets the "updated_at" field. 40 func (sc *SettingCreate) SetUpdatedAt(t time.Time) *SettingCreate { 41 sc.mutation.SetUpdatedAt(t) 42 return sc 43 } 44 45 // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. 46 func (sc *SettingCreate) SetNillableUpdatedAt(t *time.Time) *SettingCreate { 47 if t != nil { 48 sc.SetUpdatedAt(*t) 49 } 50 return sc 51 } 52 53 // SetDeletedAt sets the "deleted_at" field. 54 func (sc *SettingCreate) SetDeletedAt(t time.Time) *SettingCreate { 55 sc.mutation.SetDeletedAt(t) 56 return sc 57 } 58 59 // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. 60 func (sc *SettingCreate) SetNillableDeletedAt(t *time.Time) *SettingCreate { 61 if t != nil { 62 sc.SetDeletedAt(*t) 63 } 64 return sc 65 } 66 67 // SetName sets the "name" field. 68 func (sc *SettingCreate) SetName(s string) *SettingCreate { 69 sc.mutation.SetName(s) 70 return sc 71 } 72 73 // SetValue sets the "value" field. 74 func (sc *SettingCreate) SetValue(s string) *SettingCreate { 75 sc.mutation.SetValue(s) 76 return sc 77 } 78 79 // SetNillableValue sets the "value" field if the given value is not nil. 80 func (sc *SettingCreate) SetNillableValue(s *string) *SettingCreate { 81 if s != nil { 82 sc.SetValue(*s) 83 } 84 return sc 85 } 86 87 // SetType sets the "type" field. 88 func (sc *SettingCreate) SetType(s string) *SettingCreate { 89 sc.mutation.SetType(s) 90 return sc 91 } 92 93 // SetNillableType sets the "type" field if the given value is not nil. 94 func (sc *SettingCreate) SetNillableType(s *string) *SettingCreate { 95 if s != nil { 96 sc.SetType(*s) 97 } 98 return sc 99 } 100 101 // Mutation returns the SettingMutation object of the builder. 102 func (sc *SettingCreate) Mutation() *SettingMutation { 103 return sc.mutation 104 } 105 106 // Save creates the Setting in the database. 107 func (sc *SettingCreate) Save(ctx context.Context) (*Setting, error) { 108 var ( 109 err error 110 node *Setting 111 ) 112 sc.defaults() 113 if len(sc.hooks) == 0 { 114 if err = sc.check(); err != nil { 115 return nil, err 116 } 117 node, err = sc.sqlSave(ctx) 118 } else { 119 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 120 mutation, ok := m.(*SettingMutation) 121 if !ok { 122 return nil, fmt.Errorf("unexpected mutation type %T", m) 123 } 124 if err = sc.check(); err != nil { 125 return nil, err 126 } 127 sc.mutation = mutation 128 if node, err = sc.sqlSave(ctx); err != nil { 129 return nil, err 130 } 131 mutation.id = &node.ID 132 mutation.done = true 133 return node, err 134 }) 135 for i := len(sc.hooks) - 1; i >= 0; i-- { 136 if sc.hooks[i] == nil { 137 return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") 138 } 139 mut = sc.hooks[i](mut) 140 } 141 if _, err := mut.Mutate(ctx, sc.mutation); err != nil { 142 return nil, err 143 } 144 } 145 return node, err 146 } 147 148 // SaveX calls Save and panics if Save returns an error. 149 func (sc *SettingCreate) SaveX(ctx context.Context) *Setting { 150 v, err := sc.Save(ctx) 151 if err != nil { 152 panic(err) 153 } 154 return v 155 } 156 157 // Exec executes the query. 158 func (sc *SettingCreate) Exec(ctx context.Context) error { 159 _, err := sc.Save(ctx) 160 return err 161 } 162 163 // ExecX is like Exec, but panics if an error occurs. 164 func (sc *SettingCreate) ExecX(ctx context.Context) { 165 if err := sc.Exec(ctx); err != nil { 166 panic(err) 167 } 168 } 169 170 // defaults sets the default values of the builder before save. 171 func (sc *SettingCreate) defaults() { 172 if _, ok := sc.mutation.CreatedAt(); !ok { 173 v := setting.DefaultCreatedAt() 174 sc.mutation.SetCreatedAt(v) 175 } 176 if _, ok := sc.mutation.UpdatedAt(); !ok { 177 v := setting.DefaultUpdatedAt() 178 sc.mutation.SetUpdatedAt(v) 179 } 180 if _, ok := sc.mutation.GetType(); !ok { 181 v := setting.DefaultType 182 sc.mutation.SetType(v) 183 } 184 } 185 186 // check runs all checks and user-defined validators on the builder. 187 func (sc *SettingCreate) check() error { 188 if _, ok := sc.mutation.CreatedAt(); !ok { 189 return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Setting.created_at"`)} 190 } 191 if _, ok := sc.mutation.UpdatedAt(); !ok { 192 return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Setting.updated_at"`)} 193 } 194 if _, ok := sc.mutation.Name(); !ok { 195 return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Setting.name"`)} 196 } 197 return nil 198 } 199 200 func (sc *SettingCreate) sqlSave(ctx context.Context) (*Setting, error) { 201 _node, _spec := sc.createSpec() 202 if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil { 203 if sqlgraph.IsConstraintError(err) { 204 err = &ConstraintError{err.Error(), err} 205 } 206 return nil, err 207 } 208 id := _spec.ID.Value.(int64) 209 _node.ID = int(id) 210 return _node, nil 211 } 212 213 func (sc *SettingCreate) createSpec() (*Setting, *sqlgraph.CreateSpec) { 214 var ( 215 _node = &Setting{config: sc.config} 216 _spec = &sqlgraph.CreateSpec{ 217 Table: setting.Table, 218 ID: &sqlgraph.FieldSpec{ 219 Type: field.TypeInt, 220 Column: setting.FieldID, 221 }, 222 } 223 ) 224 _spec.OnConflict = sc.conflict 225 if value, ok := sc.mutation.CreatedAt(); ok { 226 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 227 Type: field.TypeTime, 228 Value: value, 229 Column: setting.FieldCreatedAt, 230 }) 231 _node.CreatedAt = value 232 } 233 if value, ok := sc.mutation.UpdatedAt(); ok { 234 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 235 Type: field.TypeTime, 236 Value: value, 237 Column: setting.FieldUpdatedAt, 238 }) 239 _node.UpdatedAt = value 240 } 241 if value, ok := sc.mutation.DeletedAt(); ok { 242 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 243 Type: field.TypeTime, 244 Value: value, 245 Column: setting.FieldDeletedAt, 246 }) 247 _node.DeletedAt = value 248 } 249 if value, ok := sc.mutation.Name(); ok { 250 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 251 Type: field.TypeString, 252 Value: value, 253 Column: setting.FieldName, 254 }) 255 _node.Name = value 256 } 257 if value, ok := sc.mutation.Value(); ok { 258 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 259 Type: field.TypeString, 260 Value: value, 261 Column: setting.FieldValue, 262 }) 263 _node.Value = value 264 } 265 if value, ok := sc.mutation.GetType(); ok { 266 _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ 267 Type: field.TypeString, 268 Value: value, 269 Column: setting.FieldType, 270 }) 271 _node.Type = value 272 } 273 return _node, _spec 274 } 275 276 // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause 277 // of the `INSERT` statement. For example: 278 // 279 // client.Setting.Create(). 280 // SetCreatedAt(v). 281 // OnConflict( 282 // // Update the row with the new values 283 // // the was proposed for insertion. 284 // sql.ResolveWithNewValues(), 285 // ). 286 // // Override some of the fields with custom 287 // // update values. 288 // Update(func(u *ent.SettingUpsert) { 289 // SetCreatedAt(v+v). 290 // }). 291 // Exec(ctx) 292 // 293 func (sc *SettingCreate) OnConflict(opts ...sql.ConflictOption) *SettingUpsertOne { 294 sc.conflict = opts 295 return &SettingUpsertOne{ 296 create: sc, 297 } 298 } 299 300 // OnConflictColumns calls `OnConflict` and configures the columns 301 // as conflict target. Using this option is equivalent to using: 302 // 303 // client.Setting.Create(). 304 // OnConflict(sql.ConflictColumns(columns...)). 305 // Exec(ctx) 306 // 307 func (sc *SettingCreate) OnConflictColumns(columns ...string) *SettingUpsertOne { 308 sc.conflict = append(sc.conflict, sql.ConflictColumns(columns...)) 309 return &SettingUpsertOne{ 310 create: sc, 311 } 312 } 313 314 type ( 315 // SettingUpsertOne is the builder for "upsert"-ing 316 // one Setting node. 317 SettingUpsertOne struct { 318 create *SettingCreate 319 } 320 321 // SettingUpsert is the "OnConflict" setter. 322 SettingUpsert struct { 323 *sql.UpdateSet 324 } 325 ) 326 327 // SetCreatedAt sets the "created_at" field. 328 func (u *SettingUpsert) SetCreatedAt(v time.Time) *SettingUpsert { 329 u.Set(setting.FieldCreatedAt, v) 330 return u 331 } 332 333 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 334 func (u *SettingUpsert) UpdateCreatedAt() *SettingUpsert { 335 u.SetExcluded(setting.FieldCreatedAt) 336 return u 337 } 338 339 // SetUpdatedAt sets the "updated_at" field. 340 func (u *SettingUpsert) SetUpdatedAt(v time.Time) *SettingUpsert { 341 u.Set(setting.FieldUpdatedAt, v) 342 return u 343 } 344 345 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 346 func (u *SettingUpsert) UpdateUpdatedAt() *SettingUpsert { 347 u.SetExcluded(setting.FieldUpdatedAt) 348 return u 349 } 350 351 // SetDeletedAt sets the "deleted_at" field. 352 func (u *SettingUpsert) SetDeletedAt(v time.Time) *SettingUpsert { 353 u.Set(setting.FieldDeletedAt, v) 354 return u 355 } 356 357 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 358 func (u *SettingUpsert) UpdateDeletedAt() *SettingUpsert { 359 u.SetExcluded(setting.FieldDeletedAt) 360 return u 361 } 362 363 // ClearDeletedAt clears the value of the "deleted_at" field. 364 func (u *SettingUpsert) ClearDeletedAt() *SettingUpsert { 365 u.SetNull(setting.FieldDeletedAt) 366 return u 367 } 368 369 // SetName sets the "name" field. 370 func (u *SettingUpsert) SetName(v string) *SettingUpsert { 371 u.Set(setting.FieldName, v) 372 return u 373 } 374 375 // UpdateName sets the "name" field to the value that was provided on create. 376 func (u *SettingUpsert) UpdateName() *SettingUpsert { 377 u.SetExcluded(setting.FieldName) 378 return u 379 } 380 381 // SetValue sets the "value" field. 382 func (u *SettingUpsert) SetValue(v string) *SettingUpsert { 383 u.Set(setting.FieldValue, v) 384 return u 385 } 386 387 // UpdateValue sets the "value" field to the value that was provided on create. 388 func (u *SettingUpsert) UpdateValue() *SettingUpsert { 389 u.SetExcluded(setting.FieldValue) 390 return u 391 } 392 393 // ClearValue clears the value of the "value" field. 394 func (u *SettingUpsert) ClearValue() *SettingUpsert { 395 u.SetNull(setting.FieldValue) 396 return u 397 } 398 399 // SetType sets the "type" field. 400 func (u *SettingUpsert) SetType(v string) *SettingUpsert { 401 u.Set(setting.FieldType, v) 402 return u 403 } 404 405 // UpdateType sets the "type" field to the value that was provided on create. 406 func (u *SettingUpsert) UpdateType() *SettingUpsert { 407 u.SetExcluded(setting.FieldType) 408 return u 409 } 410 411 // ClearType clears the value of the "type" field. 412 func (u *SettingUpsert) ClearType() *SettingUpsert { 413 u.SetNull(setting.FieldType) 414 return u 415 } 416 417 // UpdateNewValues updates the mutable fields using the new values that were set on create. 418 // Using this option is equivalent to using: 419 // 420 // client.Setting.Create(). 421 // OnConflict( 422 // sql.ResolveWithNewValues(), 423 // ). 424 // Exec(ctx) 425 // 426 func (u *SettingUpsertOne) UpdateNewValues() *SettingUpsertOne { 427 u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) 428 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { 429 if _, exists := u.create.mutation.CreatedAt(); exists { 430 s.SetIgnore(setting.FieldCreatedAt) 431 } 432 })) 433 return u 434 } 435 436 // Ignore sets each column to itself in case of conflict. 437 // Using this option is equivalent to using: 438 // 439 // client.Setting.Create(). 440 // OnConflict(sql.ResolveWithIgnore()). 441 // Exec(ctx) 442 // 443 func (u *SettingUpsertOne) Ignore() *SettingUpsertOne { 444 u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) 445 return u 446 } 447 448 // DoNothing configures the conflict_action to `DO NOTHING`. 449 // Supported only by SQLite and PostgreSQL. 450 func (u *SettingUpsertOne) DoNothing() *SettingUpsertOne { 451 u.create.conflict = append(u.create.conflict, sql.DoNothing()) 452 return u 453 } 454 455 // Update allows overriding fields `UPDATE` values. See the SettingCreate.OnConflict 456 // documentation for more info. 457 func (u *SettingUpsertOne) Update(set func(*SettingUpsert)) *SettingUpsertOne { 458 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { 459 set(&SettingUpsert{UpdateSet: update}) 460 })) 461 return u 462 } 463 464 // SetCreatedAt sets the "created_at" field. 465 func (u *SettingUpsertOne) SetCreatedAt(v time.Time) *SettingUpsertOne { 466 return u.Update(func(s *SettingUpsert) { 467 s.SetCreatedAt(v) 468 }) 469 } 470 471 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 472 func (u *SettingUpsertOne) UpdateCreatedAt() *SettingUpsertOne { 473 return u.Update(func(s *SettingUpsert) { 474 s.UpdateCreatedAt() 475 }) 476 } 477 478 // SetUpdatedAt sets the "updated_at" field. 479 func (u *SettingUpsertOne) SetUpdatedAt(v time.Time) *SettingUpsertOne { 480 return u.Update(func(s *SettingUpsert) { 481 s.SetUpdatedAt(v) 482 }) 483 } 484 485 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 486 func (u *SettingUpsertOne) UpdateUpdatedAt() *SettingUpsertOne { 487 return u.Update(func(s *SettingUpsert) { 488 s.UpdateUpdatedAt() 489 }) 490 } 491 492 // SetDeletedAt sets the "deleted_at" field. 493 func (u *SettingUpsertOne) SetDeletedAt(v time.Time) *SettingUpsertOne { 494 return u.Update(func(s *SettingUpsert) { 495 s.SetDeletedAt(v) 496 }) 497 } 498 499 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 500 func (u *SettingUpsertOne) UpdateDeletedAt() *SettingUpsertOne { 501 return u.Update(func(s *SettingUpsert) { 502 s.UpdateDeletedAt() 503 }) 504 } 505 506 // ClearDeletedAt clears the value of the "deleted_at" field. 507 func (u *SettingUpsertOne) ClearDeletedAt() *SettingUpsertOne { 508 return u.Update(func(s *SettingUpsert) { 509 s.ClearDeletedAt() 510 }) 511 } 512 513 // SetName sets the "name" field. 514 func (u *SettingUpsertOne) SetName(v string) *SettingUpsertOne { 515 return u.Update(func(s *SettingUpsert) { 516 s.SetName(v) 517 }) 518 } 519 520 // UpdateName sets the "name" field to the value that was provided on create. 521 func (u *SettingUpsertOne) UpdateName() *SettingUpsertOne { 522 return u.Update(func(s *SettingUpsert) { 523 s.UpdateName() 524 }) 525 } 526 527 // SetValue sets the "value" field. 528 func (u *SettingUpsertOne) SetValue(v string) *SettingUpsertOne { 529 return u.Update(func(s *SettingUpsert) { 530 s.SetValue(v) 531 }) 532 } 533 534 // UpdateValue sets the "value" field to the value that was provided on create. 535 func (u *SettingUpsertOne) UpdateValue() *SettingUpsertOne { 536 return u.Update(func(s *SettingUpsert) { 537 s.UpdateValue() 538 }) 539 } 540 541 // ClearValue clears the value of the "value" field. 542 func (u *SettingUpsertOne) ClearValue() *SettingUpsertOne { 543 return u.Update(func(s *SettingUpsert) { 544 s.ClearValue() 545 }) 546 } 547 548 // SetType sets the "type" field. 549 func (u *SettingUpsertOne) SetType(v string) *SettingUpsertOne { 550 return u.Update(func(s *SettingUpsert) { 551 s.SetType(v) 552 }) 553 } 554 555 // UpdateType sets the "type" field to the value that was provided on create. 556 func (u *SettingUpsertOne) UpdateType() *SettingUpsertOne { 557 return u.Update(func(s *SettingUpsert) { 558 s.UpdateType() 559 }) 560 } 561 562 // ClearType clears the value of the "type" field. 563 func (u *SettingUpsertOne) ClearType() *SettingUpsertOne { 564 return u.Update(func(s *SettingUpsert) { 565 s.ClearType() 566 }) 567 } 568 569 // Exec executes the query. 570 func (u *SettingUpsertOne) Exec(ctx context.Context) error { 571 if len(u.create.conflict) == 0 { 572 return errors.New("ent: missing options for SettingCreate.OnConflict") 573 } 574 return u.create.Exec(ctx) 575 } 576 577 // ExecX is like Exec, but panics if an error occurs. 578 func (u *SettingUpsertOne) ExecX(ctx context.Context) { 579 if err := u.create.Exec(ctx); err != nil { 580 panic(err) 581 } 582 } 583 584 // Exec executes the UPSERT query and returns the inserted/updated ID. 585 func (u *SettingUpsertOne) ID(ctx context.Context) (id int, err error) { 586 node, err := u.create.Save(ctx) 587 if err != nil { 588 return id, err 589 } 590 return node.ID, nil 591 } 592 593 // IDX is like ID, but panics if an error occurs. 594 func (u *SettingUpsertOne) IDX(ctx context.Context) int { 595 id, err := u.ID(ctx) 596 if err != nil { 597 panic(err) 598 } 599 return id 600 } 601 602 // SettingCreateBulk is the builder for creating many Setting entities in bulk. 603 type SettingCreateBulk struct { 604 config 605 builders []*SettingCreate 606 conflict []sql.ConflictOption 607 } 608 609 // Save creates the Setting entities in the database. 610 func (scb *SettingCreateBulk) Save(ctx context.Context) ([]*Setting, error) { 611 specs := make([]*sqlgraph.CreateSpec, len(scb.builders)) 612 nodes := make([]*Setting, len(scb.builders)) 613 mutators := make([]Mutator, len(scb.builders)) 614 for i := range scb.builders { 615 func(i int, root context.Context) { 616 builder := scb.builders[i] 617 builder.defaults() 618 var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { 619 mutation, ok := m.(*SettingMutation) 620 if !ok { 621 return nil, fmt.Errorf("unexpected mutation type %T", m) 622 } 623 if err := builder.check(); err != nil { 624 return nil, err 625 } 626 builder.mutation = mutation 627 nodes[i], specs[i] = builder.createSpec() 628 var err error 629 if i < len(mutators)-1 { 630 _, err = mutators[i+1].Mutate(root, scb.builders[i+1].mutation) 631 } else { 632 spec := &sqlgraph.BatchCreateSpec{Nodes: specs} 633 spec.OnConflict = scb.conflict 634 // Invoke the actual operation on the latest mutation in the chain. 635 if err = sqlgraph.BatchCreate(ctx, scb.driver, spec); err != nil { 636 if sqlgraph.IsConstraintError(err) { 637 err = &ConstraintError{err.Error(), err} 638 } 639 } 640 } 641 if err != nil { 642 return nil, err 643 } 644 mutation.id = &nodes[i].ID 645 mutation.done = true 646 if specs[i].ID.Value != nil { 647 id := specs[i].ID.Value.(int64) 648 nodes[i].ID = int(id) 649 } 650 return nodes[i], nil 651 }) 652 for i := len(builder.hooks) - 1; i >= 0; i-- { 653 mut = builder.hooks[i](mut) 654 } 655 mutators[i] = mut 656 }(i, ctx) 657 } 658 if len(mutators) > 0 { 659 if _, err := mutators[0].Mutate(ctx, scb.builders[0].mutation); err != nil { 660 return nil, err 661 } 662 } 663 return nodes, nil 664 } 665 666 // SaveX is like Save, but panics if an error occurs. 667 func (scb *SettingCreateBulk) SaveX(ctx context.Context) []*Setting { 668 v, err := scb.Save(ctx) 669 if err != nil { 670 panic(err) 671 } 672 return v 673 } 674 675 // Exec executes the query. 676 func (scb *SettingCreateBulk) Exec(ctx context.Context) error { 677 _, err := scb.Save(ctx) 678 return err 679 } 680 681 // ExecX is like Exec, but panics if an error occurs. 682 func (scb *SettingCreateBulk) ExecX(ctx context.Context) { 683 if err := scb.Exec(ctx); err != nil { 684 panic(err) 685 } 686 } 687 688 // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause 689 // of the `INSERT` statement. For example: 690 // 691 // client.Setting.CreateBulk(builders...). 692 // OnConflict( 693 // // Update the row with the new values 694 // // the was proposed for insertion. 695 // sql.ResolveWithNewValues(), 696 // ). 697 // // Override some of the fields with custom 698 // // update values. 699 // Update(func(u *ent.SettingUpsert) { 700 // SetCreatedAt(v+v). 701 // }). 702 // Exec(ctx) 703 // 704 func (scb *SettingCreateBulk) OnConflict(opts ...sql.ConflictOption) *SettingUpsertBulk { 705 scb.conflict = opts 706 return &SettingUpsertBulk{ 707 create: scb, 708 } 709 } 710 711 // OnConflictColumns calls `OnConflict` and configures the columns 712 // as conflict target. Using this option is equivalent to using: 713 // 714 // client.Setting.Create(). 715 // OnConflict(sql.ConflictColumns(columns...)). 716 // Exec(ctx) 717 // 718 func (scb *SettingCreateBulk) OnConflictColumns(columns ...string) *SettingUpsertBulk { 719 scb.conflict = append(scb.conflict, sql.ConflictColumns(columns...)) 720 return &SettingUpsertBulk{ 721 create: scb, 722 } 723 } 724 725 // SettingUpsertBulk is the builder for "upsert"-ing 726 // a bulk of Setting nodes. 727 type SettingUpsertBulk struct { 728 create *SettingCreateBulk 729 } 730 731 // UpdateNewValues updates the mutable fields using the new values that 732 // were set on create. Using this option is equivalent to using: 733 // 734 // client.Setting.Create(). 735 // OnConflict( 736 // sql.ResolveWithNewValues(), 737 // ). 738 // Exec(ctx) 739 // 740 func (u *SettingUpsertBulk) UpdateNewValues() *SettingUpsertBulk { 741 u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) 742 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { 743 for _, b := range u.create.builders { 744 if _, exists := b.mutation.CreatedAt(); exists { 745 s.SetIgnore(setting.FieldCreatedAt) 746 } 747 } 748 })) 749 return u 750 } 751 752 // Ignore sets each column to itself in case of conflict. 753 // Using this option is equivalent to using: 754 // 755 // client.Setting.Create(). 756 // OnConflict(sql.ResolveWithIgnore()). 757 // Exec(ctx) 758 // 759 func (u *SettingUpsertBulk) Ignore() *SettingUpsertBulk { 760 u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) 761 return u 762 } 763 764 // DoNothing configures the conflict_action to `DO NOTHING`. 765 // Supported only by SQLite and PostgreSQL. 766 func (u *SettingUpsertBulk) DoNothing() *SettingUpsertBulk { 767 u.create.conflict = append(u.create.conflict, sql.DoNothing()) 768 return u 769 } 770 771 // Update allows overriding fields `UPDATE` values. See the SettingCreateBulk.OnConflict 772 // documentation for more info. 773 func (u *SettingUpsertBulk) Update(set func(*SettingUpsert)) *SettingUpsertBulk { 774 u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { 775 set(&SettingUpsert{UpdateSet: update}) 776 })) 777 return u 778 } 779 780 // SetCreatedAt sets the "created_at" field. 781 func (u *SettingUpsertBulk) SetCreatedAt(v time.Time) *SettingUpsertBulk { 782 return u.Update(func(s *SettingUpsert) { 783 s.SetCreatedAt(v) 784 }) 785 } 786 787 // UpdateCreatedAt sets the "created_at" field to the value that was provided on create. 788 func (u *SettingUpsertBulk) UpdateCreatedAt() *SettingUpsertBulk { 789 return u.Update(func(s *SettingUpsert) { 790 s.UpdateCreatedAt() 791 }) 792 } 793 794 // SetUpdatedAt sets the "updated_at" field. 795 func (u *SettingUpsertBulk) SetUpdatedAt(v time.Time) *SettingUpsertBulk { 796 return u.Update(func(s *SettingUpsert) { 797 s.SetUpdatedAt(v) 798 }) 799 } 800 801 // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. 802 func (u *SettingUpsertBulk) UpdateUpdatedAt() *SettingUpsertBulk { 803 return u.Update(func(s *SettingUpsert) { 804 s.UpdateUpdatedAt() 805 }) 806 } 807 808 // SetDeletedAt sets the "deleted_at" field. 809 func (u *SettingUpsertBulk) SetDeletedAt(v time.Time) *SettingUpsertBulk { 810 return u.Update(func(s *SettingUpsert) { 811 s.SetDeletedAt(v) 812 }) 813 } 814 815 // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. 816 func (u *SettingUpsertBulk) UpdateDeletedAt() *SettingUpsertBulk { 817 return u.Update(func(s *SettingUpsert) { 818 s.UpdateDeletedAt() 819 }) 820 } 821 822 // ClearDeletedAt clears the value of the "deleted_at" field. 823 func (u *SettingUpsertBulk) ClearDeletedAt() *SettingUpsertBulk { 824 return u.Update(func(s *SettingUpsert) { 825 s.ClearDeletedAt() 826 }) 827 } 828 829 // SetName sets the "name" field. 830 func (u *SettingUpsertBulk) SetName(v string) *SettingUpsertBulk { 831 return u.Update(func(s *SettingUpsert) { 832 s.SetName(v) 833 }) 834 } 835 836 // UpdateName sets the "name" field to the value that was provided on create. 837 func (u *SettingUpsertBulk) UpdateName() *SettingUpsertBulk { 838 return u.Update(func(s *SettingUpsert) { 839 s.UpdateName() 840 }) 841 } 842 843 // SetValue sets the "value" field. 844 func (u *SettingUpsertBulk) SetValue(v string) *SettingUpsertBulk { 845 return u.Update(func(s *SettingUpsert) { 846 s.SetValue(v) 847 }) 848 } 849 850 // UpdateValue sets the "value" field to the value that was provided on create. 851 func (u *SettingUpsertBulk) UpdateValue() *SettingUpsertBulk { 852 return u.Update(func(s *SettingUpsert) { 853 s.UpdateValue() 854 }) 855 } 856 857 // ClearValue clears the value of the "value" field. 858 func (u *SettingUpsertBulk) ClearValue() *SettingUpsertBulk { 859 return u.Update(func(s *SettingUpsert) { 860 s.ClearValue() 861 }) 862 } 863 864 // SetType sets the "type" field. 865 func (u *SettingUpsertBulk) SetType(v string) *SettingUpsertBulk { 866 return u.Update(func(s *SettingUpsert) { 867 s.SetType(v) 868 }) 869 } 870 871 // UpdateType sets the "type" field to the value that was provided on create. 872 func (u *SettingUpsertBulk) UpdateType() *SettingUpsertBulk { 873 return u.Update(func(s *SettingUpsert) { 874 s.UpdateType() 875 }) 876 } 877 878 // ClearType clears the value of the "type" field. 879 func (u *SettingUpsertBulk) ClearType() *SettingUpsertBulk { 880 return u.Update(func(s *SettingUpsert) { 881 s.ClearType() 882 }) 883 } 884 885 // Exec executes the query. 886 func (u *SettingUpsertBulk) Exec(ctx context.Context) error { 887 for i, b := range u.create.builders { 888 if len(b.conflict) != 0 { 889 return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SettingCreateBulk instead", i) 890 } 891 } 892 if len(u.create.conflict) == 0 { 893 return errors.New("ent: missing options for SettingCreateBulk.OnConflict") 894 } 895 return u.create.Exec(ctx) 896 } 897 898 // ExecX is like Exec, but panics if an error occurs. 899 func (u *SettingUpsertBulk) ExecX(ctx context.Context) { 900 if err := u.create.Exec(ctx); err != nil { 901 panic(err) 902 } 903 }