// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/Wei-Shaw/sub2api/ent/authidentity" "github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision" "github.com/Wei-Shaw/sub2api/ent/pendingauthsession" ) // IdentityAdoptionDecisionCreate is the builder for creating a IdentityAdoptionDecision entity. type IdentityAdoptionDecisionCreate struct { config mutation *IdentityAdoptionDecisionMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (_c *IdentityAdoptionDecisionCreate) SetCreatedAt(v time.Time) *IdentityAdoptionDecisionCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *IdentityAdoptionDecisionCreate) SetNillableCreatedAt(v *time.Time) *IdentityAdoptionDecisionCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *IdentityAdoptionDecisionCreate) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *IdentityAdoptionDecisionCreate) SetNillableUpdatedAt(v *time.Time) *IdentityAdoptionDecisionCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetPendingAuthSessionID sets the "pending_auth_session_id" field. func (_c *IdentityAdoptionDecisionCreate) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionCreate { _c.mutation.SetPendingAuthSessionID(v) return _c } // SetIdentityID sets the "identity_id" field. func (_c *IdentityAdoptionDecisionCreate) SetIdentityID(v int64) *IdentityAdoptionDecisionCreate { _c.mutation.SetIdentityID(v) return _c } // SetNillableIdentityID sets the "identity_id" field if the given value is not nil. func (_c *IdentityAdoptionDecisionCreate) SetNillableIdentityID(v *int64) *IdentityAdoptionDecisionCreate { if v != nil { _c.SetIdentityID(*v) } return _c } // SetAdoptDisplayName sets the "adopt_display_name" field. func (_c *IdentityAdoptionDecisionCreate) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionCreate { _c.mutation.SetAdoptDisplayName(v) return _c } // SetNillableAdoptDisplayName sets the "adopt_display_name" field if the given value is not nil. func (_c *IdentityAdoptionDecisionCreate) SetNillableAdoptDisplayName(v *bool) *IdentityAdoptionDecisionCreate { if v != nil { _c.SetAdoptDisplayName(*v) } return _c } // SetAdoptAvatar sets the "adopt_avatar" field. func (_c *IdentityAdoptionDecisionCreate) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionCreate { _c.mutation.SetAdoptAvatar(v) return _c } // SetNillableAdoptAvatar sets the "adopt_avatar" field if the given value is not nil. func (_c *IdentityAdoptionDecisionCreate) SetNillableAdoptAvatar(v *bool) *IdentityAdoptionDecisionCreate { if v != nil { _c.SetAdoptAvatar(*v) } return _c } // SetDecidedAt sets the "decided_at" field. func (_c *IdentityAdoptionDecisionCreate) SetDecidedAt(v time.Time) *IdentityAdoptionDecisionCreate { _c.mutation.SetDecidedAt(v) return _c } // SetNillableDecidedAt sets the "decided_at" field if the given value is not nil. func (_c *IdentityAdoptionDecisionCreate) SetNillableDecidedAt(v *time.Time) *IdentityAdoptionDecisionCreate { if v != nil { _c.SetDecidedAt(*v) } return _c } // SetPendingAuthSession sets the "pending_auth_session" edge to the PendingAuthSession entity. func (_c *IdentityAdoptionDecisionCreate) SetPendingAuthSession(v *PendingAuthSession) *IdentityAdoptionDecisionCreate { return _c.SetPendingAuthSessionID(v.ID) } // SetIdentity sets the "identity" edge to the AuthIdentity entity. func (_c *IdentityAdoptionDecisionCreate) SetIdentity(v *AuthIdentity) *IdentityAdoptionDecisionCreate { return _c.SetIdentityID(v.ID) } // Mutation returns the IdentityAdoptionDecisionMutation object of the builder. func (_c *IdentityAdoptionDecisionCreate) Mutation() *IdentityAdoptionDecisionMutation { return _c.mutation } // Save creates the IdentityAdoptionDecision in the database. func (_c *IdentityAdoptionDecisionCreate) Save(ctx context.Context) (*IdentityAdoptionDecision, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *IdentityAdoptionDecisionCreate) SaveX(ctx context.Context) *IdentityAdoptionDecision { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *IdentityAdoptionDecisionCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *IdentityAdoptionDecisionCreate) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_c *IdentityAdoptionDecisionCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := identityadoptiondecision.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { v := identityadoptiondecision.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } if _, ok := _c.mutation.AdoptDisplayName(); !ok { v := identityadoptiondecision.DefaultAdoptDisplayName _c.mutation.SetAdoptDisplayName(v) } if _, ok := _c.mutation.AdoptAvatar(); !ok { v := identityadoptiondecision.DefaultAdoptAvatar _c.mutation.SetAdoptAvatar(v) } if _, ok := _c.mutation.DecidedAt(); !ok { v := identityadoptiondecision.DefaultDecidedAt() _c.mutation.SetDecidedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_c *IdentityAdoptionDecisionCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.updated_at"`)} } if _, ok := _c.mutation.PendingAuthSessionID(); !ok { return &ValidationError{Name: "pending_auth_session_id", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.pending_auth_session_id"`)} } if _, ok := _c.mutation.AdoptDisplayName(); !ok { return &ValidationError{Name: "adopt_display_name", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.adopt_display_name"`)} } if _, ok := _c.mutation.AdoptAvatar(); !ok { return &ValidationError{Name: "adopt_avatar", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.adopt_avatar"`)} } if _, ok := _c.mutation.DecidedAt(); !ok { return &ValidationError{Name: "decided_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.decided_at"`)} } if len(_c.mutation.PendingAuthSessionIDs()) == 0 { return &ValidationError{Name: "pending_auth_session", err: errors.New(`ent: missing required edge "IdentityAdoptionDecision.pending_auth_session"`)} } return nil } func (_c *IdentityAdoptionDecisionCreate) sqlSave(ctx context.Context) (*IdentityAdoptionDecision, error) { if err := _c.check(); err != nil { return nil, err } _node, _spec := _c.createSpec() if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } id := _spec.ID.Value.(int64) _node.ID = int64(id) _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *IdentityAdoptionDecisionCreate) createSpec() (*IdentityAdoptionDecision, *sqlgraph.CreateSpec) { var ( _node = &IdentityAdoptionDecision{config: _c.config} _spec = sqlgraph.NewCreateSpec(identityadoptiondecision.Table, sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64)) ) _spec.OnConflict = _c.conflict if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(identityadoptiondecision.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(identityadoptiondecision.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := _c.mutation.AdoptDisplayName(); ok { _spec.SetField(identityadoptiondecision.FieldAdoptDisplayName, field.TypeBool, value) _node.AdoptDisplayName = value } if value, ok := _c.mutation.AdoptAvatar(); ok { _spec.SetField(identityadoptiondecision.FieldAdoptAvatar, field.TypeBool, value) _node.AdoptAvatar = value } if value, ok := _c.mutation.DecidedAt(); ok { _spec.SetField(identityadoptiondecision.FieldDecidedAt, field.TypeTime, value) _node.DecidedAt = value } if nodes := _c.mutation.PendingAuthSessionIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, Inverse: true, Table: identityadoptiondecision.PendingAuthSessionTable, Columns: []string{identityadoptiondecision.PendingAuthSessionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.PendingAuthSessionID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.IdentityIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: identityadoptiondecision.IdentityTable, Columns: []string{identityadoptiondecision.IdentityColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.IdentityID = &nodes[0] _spec.Edges = append(_spec.Edges, edge) } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.IdentityAdoptionDecision.Create(). // SetCreatedAt(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.IdentityAdoptionDecisionUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *IdentityAdoptionDecisionCreate) OnConflict(opts ...sql.ConflictOption) *IdentityAdoptionDecisionUpsertOne { _c.conflict = opts return &IdentityAdoptionDecisionUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.IdentityAdoptionDecision.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *IdentityAdoptionDecisionCreate) OnConflictColumns(columns ...string) *IdentityAdoptionDecisionUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &IdentityAdoptionDecisionUpsertOne{ create: _c, } } type ( // IdentityAdoptionDecisionUpsertOne is the builder for "upsert"-ing // one IdentityAdoptionDecision node. IdentityAdoptionDecisionUpsertOne struct { create *IdentityAdoptionDecisionCreate } // IdentityAdoptionDecisionUpsert is the "OnConflict" setter. IdentityAdoptionDecisionUpsert struct { *sql.UpdateSet } ) // SetUpdatedAt sets the "updated_at" field. func (u *IdentityAdoptionDecisionUpsert) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsert { u.Set(identityadoptiondecision.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsert) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsert { u.SetExcluded(identityadoptiondecision.FieldUpdatedAt) return u } // SetPendingAuthSessionID sets the "pending_auth_session_id" field. func (u *IdentityAdoptionDecisionUpsert) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsert { u.Set(identityadoptiondecision.FieldPendingAuthSessionID, v) return u } // UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsert) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsert { u.SetExcluded(identityadoptiondecision.FieldPendingAuthSessionID) return u } // SetIdentityID sets the "identity_id" field. func (u *IdentityAdoptionDecisionUpsert) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsert { u.Set(identityadoptiondecision.FieldIdentityID, v) return u } // UpdateIdentityID sets the "identity_id" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsert) UpdateIdentityID() *IdentityAdoptionDecisionUpsert { u.SetExcluded(identityadoptiondecision.FieldIdentityID) return u } // ClearIdentityID clears the value of the "identity_id" field. func (u *IdentityAdoptionDecisionUpsert) ClearIdentityID() *IdentityAdoptionDecisionUpsert { u.SetNull(identityadoptiondecision.FieldIdentityID) return u } // SetAdoptDisplayName sets the "adopt_display_name" field. func (u *IdentityAdoptionDecisionUpsert) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsert { u.Set(identityadoptiondecision.FieldAdoptDisplayName, v) return u } // UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsert) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsert { u.SetExcluded(identityadoptiondecision.FieldAdoptDisplayName) return u } // SetAdoptAvatar sets the "adopt_avatar" field. func (u *IdentityAdoptionDecisionUpsert) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsert { u.Set(identityadoptiondecision.FieldAdoptAvatar, v) return u } // UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsert) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsert { u.SetExcluded(identityadoptiondecision.FieldAdoptAvatar) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // // client.IdentityAdoptionDecision.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *IdentityAdoptionDecisionUpsertOne) UpdateNewValues() *IdentityAdoptionDecisionUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(identityadoptiondecision.FieldCreatedAt) } if _, exists := u.create.mutation.DecidedAt(); exists { s.SetIgnore(identityadoptiondecision.FieldDecidedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.IdentityAdoptionDecision.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *IdentityAdoptionDecisionUpsertOne) Ignore() *IdentityAdoptionDecisionUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *IdentityAdoptionDecisionUpsertOne) DoNothing() *IdentityAdoptionDecisionUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the IdentityAdoptionDecisionCreate.OnConflict // documentation for more info. func (u *IdentityAdoptionDecisionUpsertOne) Update(set func(*IdentityAdoptionDecisionUpsert)) *IdentityAdoptionDecisionUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&IdentityAdoptionDecisionUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *IdentityAdoptionDecisionUpsertOne) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertOne) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdateUpdatedAt() }) } // SetPendingAuthSessionID sets the "pending_auth_session_id" field. func (u *IdentityAdoptionDecisionUpsertOne) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetPendingAuthSessionID(v) }) } // UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertOne) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdatePendingAuthSessionID() }) } // SetIdentityID sets the "identity_id" field. func (u *IdentityAdoptionDecisionUpsertOne) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetIdentityID(v) }) } // UpdateIdentityID sets the "identity_id" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertOne) UpdateIdentityID() *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdateIdentityID() }) } // ClearIdentityID clears the value of the "identity_id" field. func (u *IdentityAdoptionDecisionUpsertOne) ClearIdentityID() *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.ClearIdentityID() }) } // SetAdoptDisplayName sets the "adopt_display_name" field. func (u *IdentityAdoptionDecisionUpsertOne) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetAdoptDisplayName(v) }) } // UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertOne) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdateAdoptDisplayName() }) } // SetAdoptAvatar sets the "adopt_avatar" field. func (u *IdentityAdoptionDecisionUpsertOne) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetAdoptAvatar(v) }) } // UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertOne) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsertOne { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdateAdoptAvatar() }) } // Exec executes the query. func (u *IdentityAdoptionDecisionUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for IdentityAdoptionDecisionCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *IdentityAdoptionDecisionUpsertOne) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } } // Exec executes the UPSERT query and returns the inserted/updated ID. func (u *IdentityAdoptionDecisionUpsertOne) ID(ctx context.Context) (id int64, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err } return node.ID, nil } // IDX is like ID, but panics if an error occurs. func (u *IdentityAdoptionDecisionUpsertOne) IDX(ctx context.Context) int64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // IdentityAdoptionDecisionCreateBulk is the builder for creating many IdentityAdoptionDecision entities in bulk. type IdentityAdoptionDecisionCreateBulk struct { config err error builders []*IdentityAdoptionDecisionCreate conflict []sql.ConflictOption } // Save creates the IdentityAdoptionDecision entities in the database. func (_c *IdentityAdoptionDecisionCreateBulk) Save(ctx context.Context) ([]*IdentityAdoptionDecision, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*IdentityAdoptionDecision, len(_c.builders)) mutators := make([]Mutator, len(_c.builders)) for i := range _c.builders { func(i int, root context.Context) { builder := _c.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*IdentityAdoptionDecisionMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } if err := builder.check(); err != nil { return nil, err } builder.mutation = mutation var err error nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = _c.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } } } if err != nil { return nil, err } mutation.id = &nodes[i].ID if specs[i].ID.Value != nil { id := specs[i].ID.Value.(int64) nodes[i].ID = int64(id) } mutation.done = true return nodes[i], nil }) for i := len(builder.hooks) - 1; i >= 0; i-- { mut = builder.hooks[i](mut) } mutators[i] = mut }(i, ctx) } if len(mutators) > 0 { if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (_c *IdentityAdoptionDecisionCreateBulk) SaveX(ctx context.Context) []*IdentityAdoptionDecision { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *IdentityAdoptionDecisionCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *IdentityAdoptionDecisionCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.IdentityAdoptionDecision.CreateBulk(builders...). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.IdentityAdoptionDecisionUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *IdentityAdoptionDecisionCreateBulk) OnConflict(opts ...sql.ConflictOption) *IdentityAdoptionDecisionUpsertBulk { _c.conflict = opts return &IdentityAdoptionDecisionUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.IdentityAdoptionDecision.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *IdentityAdoptionDecisionCreateBulk) OnConflictColumns(columns ...string) *IdentityAdoptionDecisionUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &IdentityAdoptionDecisionUpsertBulk{ create: _c, } } // IdentityAdoptionDecisionUpsertBulk is the builder for "upsert"-ing // a bulk of IdentityAdoptionDecision nodes. type IdentityAdoptionDecisionUpsertBulk struct { create *IdentityAdoptionDecisionCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.IdentityAdoptionDecision.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *IdentityAdoptionDecisionUpsertBulk) UpdateNewValues() *IdentityAdoptionDecisionUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { for _, b := range u.create.builders { if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(identityadoptiondecision.FieldCreatedAt) } if _, exists := b.mutation.DecidedAt(); exists { s.SetIgnore(identityadoptiondecision.FieldDecidedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.IdentityAdoptionDecision.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *IdentityAdoptionDecisionUpsertBulk) Ignore() *IdentityAdoptionDecisionUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *IdentityAdoptionDecisionUpsertBulk) DoNothing() *IdentityAdoptionDecisionUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the IdentityAdoptionDecisionCreateBulk.OnConflict // documentation for more info. func (u *IdentityAdoptionDecisionUpsertBulk) Update(set func(*IdentityAdoptionDecisionUpsert)) *IdentityAdoptionDecisionUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&IdentityAdoptionDecisionUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *IdentityAdoptionDecisionUpsertBulk) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdateUpdatedAt() }) } // SetPendingAuthSessionID sets the "pending_auth_session_id" field. func (u *IdentityAdoptionDecisionUpsertBulk) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetPendingAuthSessionID(v) }) } // UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertBulk) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdatePendingAuthSessionID() }) } // SetIdentityID sets the "identity_id" field. func (u *IdentityAdoptionDecisionUpsertBulk) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetIdentityID(v) }) } // UpdateIdentityID sets the "identity_id" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateIdentityID() *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdateIdentityID() }) } // ClearIdentityID clears the value of the "identity_id" field. func (u *IdentityAdoptionDecisionUpsertBulk) ClearIdentityID() *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.ClearIdentityID() }) } // SetAdoptDisplayName sets the "adopt_display_name" field. func (u *IdentityAdoptionDecisionUpsertBulk) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetAdoptDisplayName(v) }) } // UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdateAdoptDisplayName() }) } // SetAdoptAvatar sets the "adopt_avatar" field. func (u *IdentityAdoptionDecisionUpsertBulk) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.SetAdoptAvatar(v) }) } // UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsertBulk { return u.Update(func(s *IdentityAdoptionDecisionUpsert) { s.UpdateAdoptAvatar() }) } // Exec executes the query. func (u *IdentityAdoptionDecisionUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { return u.create.err } for i, b := range u.create.builders { if len(b.conflict) != 0 { return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the IdentityAdoptionDecisionCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for IdentityAdoptionDecisionCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *IdentityAdoptionDecisionUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }