// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "wechat-api/ent/wpchatroom" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // WpChatroomCreate is the builder for creating a WpChatroom entity. type WpChatroomCreate struct { config mutation *WpChatroomMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (wcc *WpChatroomCreate) SetCreatedAt(t time.Time) *WpChatroomCreate { wcc.mutation.SetCreatedAt(t) return wcc } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (wcc *WpChatroomCreate) SetNillableCreatedAt(t *time.Time) *WpChatroomCreate { if t != nil { wcc.SetCreatedAt(*t) } return wcc } // SetUpdatedAt sets the "updated_at" field. func (wcc *WpChatroomCreate) SetUpdatedAt(t time.Time) *WpChatroomCreate { wcc.mutation.SetUpdatedAt(t) return wcc } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (wcc *WpChatroomCreate) SetNillableUpdatedAt(t *time.Time) *WpChatroomCreate { if t != nil { wcc.SetUpdatedAt(*t) } return wcc } // SetStatus sets the "status" field. func (wcc *WpChatroomCreate) SetStatus(u uint8) *WpChatroomCreate { wcc.mutation.SetStatus(u) return wcc } // SetNillableStatus sets the "status" field if the given value is not nil. func (wcc *WpChatroomCreate) SetNillableStatus(u *uint8) *WpChatroomCreate { if u != nil { wcc.SetStatus(*u) } return wcc } // SetWxWxid sets the "wx_wxid" field. func (wcc *WpChatroomCreate) SetWxWxid(s string) *WpChatroomCreate { wcc.mutation.SetWxWxid(s) return wcc } // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil. func (wcc *WpChatroomCreate) SetNillableWxWxid(s *string) *WpChatroomCreate { if s != nil { wcc.SetWxWxid(*s) } return wcc } // SetChatroomID sets the "chatroom_id" field. func (wcc *WpChatroomCreate) SetChatroomID(s string) *WpChatroomCreate { wcc.mutation.SetChatroomID(s) return wcc } // SetNillableChatroomID sets the "chatroom_id" field if the given value is not nil. func (wcc *WpChatroomCreate) SetNillableChatroomID(s *string) *WpChatroomCreate { if s != nil { wcc.SetChatroomID(*s) } return wcc } // SetNickname sets the "nickname" field. func (wcc *WpChatroomCreate) SetNickname(s string) *WpChatroomCreate { wcc.mutation.SetNickname(s) return wcc } // SetNillableNickname sets the "nickname" field if the given value is not nil. func (wcc *WpChatroomCreate) SetNillableNickname(s *string) *WpChatroomCreate { if s != nil { wcc.SetNickname(*s) } return wcc } // SetOwner sets the "owner" field. func (wcc *WpChatroomCreate) SetOwner(s string) *WpChatroomCreate { wcc.mutation.SetOwner(s) return wcc } // SetNillableOwner sets the "owner" field if the given value is not nil. func (wcc *WpChatroomCreate) SetNillableOwner(s *string) *WpChatroomCreate { if s != nil { wcc.SetOwner(*s) } return wcc } // SetAvatar sets the "avatar" field. func (wcc *WpChatroomCreate) SetAvatar(s string) *WpChatroomCreate { wcc.mutation.SetAvatar(s) return wcc } // SetNillableAvatar sets the "avatar" field if the given value is not nil. func (wcc *WpChatroomCreate) SetNillableAvatar(s *string) *WpChatroomCreate { if s != nil { wcc.SetAvatar(*s) } return wcc } // SetMemberList sets the "member_list" field. func (wcc *WpChatroomCreate) SetMemberList(s []string) *WpChatroomCreate { wcc.mutation.SetMemberList(s) return wcc } // SetID sets the "id" field. func (wcc *WpChatroomCreate) SetID(u uint64) *WpChatroomCreate { wcc.mutation.SetID(u) return wcc } // Mutation returns the WpChatroomMutation object of the builder. func (wcc *WpChatroomCreate) Mutation() *WpChatroomMutation { return wcc.mutation } // Save creates the WpChatroom in the database. func (wcc *WpChatroomCreate) Save(ctx context.Context) (*WpChatroom, error) { wcc.defaults() return withHooks(ctx, wcc.sqlSave, wcc.mutation, wcc.hooks) } // SaveX calls Save and panics if Save returns an error. func (wcc *WpChatroomCreate) SaveX(ctx context.Context) *WpChatroom { v, err := wcc.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (wcc *WpChatroomCreate) Exec(ctx context.Context) error { _, err := wcc.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (wcc *WpChatroomCreate) ExecX(ctx context.Context) { if err := wcc.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (wcc *WpChatroomCreate) defaults() { if _, ok := wcc.mutation.CreatedAt(); !ok { v := wpchatroom.DefaultCreatedAt() wcc.mutation.SetCreatedAt(v) } if _, ok := wcc.mutation.UpdatedAt(); !ok { v := wpchatroom.DefaultUpdatedAt() wcc.mutation.SetUpdatedAt(v) } if _, ok := wcc.mutation.Status(); !ok { v := wpchatroom.DefaultStatus wcc.mutation.SetStatus(v) } if _, ok := wcc.mutation.WxWxid(); !ok { v := wpchatroom.DefaultWxWxid wcc.mutation.SetWxWxid(v) } if _, ok := wcc.mutation.ChatroomID(); !ok { v := wpchatroom.DefaultChatroomID wcc.mutation.SetChatroomID(v) } if _, ok := wcc.mutation.Nickname(); !ok { v := wpchatroom.DefaultNickname wcc.mutation.SetNickname(v) } if _, ok := wcc.mutation.Owner(); !ok { v := wpchatroom.DefaultOwner wcc.mutation.SetOwner(v) } if _, ok := wcc.mutation.Avatar(); !ok { v := wpchatroom.DefaultAvatar wcc.mutation.SetAvatar(v) } } // check runs all checks and user-defined validators on the builder. func (wcc *WpChatroomCreate) check() error { if _, ok := wcc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WpChatroom.created_at"`)} } if _, ok := wcc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "WpChatroom.updated_at"`)} } if _, ok := wcc.mutation.WxWxid(); !ok { return &ValidationError{Name: "wx_wxid", err: errors.New(`ent: missing required field "WpChatroom.wx_wxid"`)} } if _, ok := wcc.mutation.ChatroomID(); !ok { return &ValidationError{Name: "chatroom_id", err: errors.New(`ent: missing required field "WpChatroom.chatroom_id"`)} } if _, ok := wcc.mutation.Nickname(); !ok { return &ValidationError{Name: "nickname", err: errors.New(`ent: missing required field "WpChatroom.nickname"`)} } if _, ok := wcc.mutation.Owner(); !ok { return &ValidationError{Name: "owner", err: errors.New(`ent: missing required field "WpChatroom.owner"`)} } if _, ok := wcc.mutation.Avatar(); !ok { return &ValidationError{Name: "avatar", err: errors.New(`ent: missing required field "WpChatroom.avatar"`)} } if _, ok := wcc.mutation.MemberList(); !ok { return &ValidationError{Name: "member_list", err: errors.New(`ent: missing required field "WpChatroom.member_list"`)} } return nil } func (wcc *WpChatroomCreate) sqlSave(ctx context.Context) (*WpChatroom, error) { if err := wcc.check(); err != nil { return nil, err } _node, _spec := wcc.createSpec() if err := sqlgraph.CreateNode(ctx, wcc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } if _spec.ID.Value != _node.ID { id := _spec.ID.Value.(int64) _node.ID = uint64(id) } wcc.mutation.id = &_node.ID wcc.mutation.done = true return _node, nil } func (wcc *WpChatroomCreate) createSpec() (*WpChatroom, *sqlgraph.CreateSpec) { var ( _node = &WpChatroom{config: wcc.config} _spec = sqlgraph.NewCreateSpec(wpchatroom.Table, sqlgraph.NewFieldSpec(wpchatroom.FieldID, field.TypeUint64)) ) _spec.OnConflict = wcc.conflict if id, ok := wcc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := wcc.mutation.CreatedAt(); ok { _spec.SetField(wpchatroom.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := wcc.mutation.UpdatedAt(); ok { _spec.SetField(wpchatroom.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := wcc.mutation.Status(); ok { _spec.SetField(wpchatroom.FieldStatus, field.TypeUint8, value) _node.Status = value } if value, ok := wcc.mutation.WxWxid(); ok { _spec.SetField(wpchatroom.FieldWxWxid, field.TypeString, value) _node.WxWxid = value } if value, ok := wcc.mutation.ChatroomID(); ok { _spec.SetField(wpchatroom.FieldChatroomID, field.TypeString, value) _node.ChatroomID = value } if value, ok := wcc.mutation.Nickname(); ok { _spec.SetField(wpchatroom.FieldNickname, field.TypeString, value) _node.Nickname = value } if value, ok := wcc.mutation.Owner(); ok { _spec.SetField(wpchatroom.FieldOwner, field.TypeString, value) _node.Owner = value } if value, ok := wcc.mutation.Avatar(); ok { _spec.SetField(wpchatroom.FieldAvatar, field.TypeString, value) _node.Avatar = value } if value, ok := wcc.mutation.MemberList(); ok { _spec.SetField(wpchatroom.FieldMemberList, field.TypeJSON, value) _node.MemberList = value } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.WpChatroom.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.WpChatroomUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (wcc *WpChatroomCreate) OnConflict(opts ...sql.ConflictOption) *WpChatroomUpsertOne { wcc.conflict = opts return &WpChatroomUpsertOne{ create: wcc, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.WpChatroom.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (wcc *WpChatroomCreate) OnConflictColumns(columns ...string) *WpChatroomUpsertOne { wcc.conflict = append(wcc.conflict, sql.ConflictColumns(columns...)) return &WpChatroomUpsertOne{ create: wcc, } } type ( // WpChatroomUpsertOne is the builder for "upsert"-ing // one WpChatroom node. WpChatroomUpsertOne struct { create *WpChatroomCreate } // WpChatroomUpsert is the "OnConflict" setter. WpChatroomUpsert struct { *sql.UpdateSet } ) // SetUpdatedAt sets the "updated_at" field. func (u *WpChatroomUpsert) SetUpdatedAt(v time.Time) *WpChatroomUpsert { u.Set(wpchatroom.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *WpChatroomUpsert) UpdateUpdatedAt() *WpChatroomUpsert { u.SetExcluded(wpchatroom.FieldUpdatedAt) return u } // SetStatus sets the "status" field. func (u *WpChatroomUpsert) SetStatus(v uint8) *WpChatroomUpsert { u.Set(wpchatroom.FieldStatus, v) return u } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *WpChatroomUpsert) UpdateStatus() *WpChatroomUpsert { u.SetExcluded(wpchatroom.FieldStatus) return u } // AddStatus adds v to the "status" field. func (u *WpChatroomUpsert) AddStatus(v uint8) *WpChatroomUpsert { u.Add(wpchatroom.FieldStatus, v) return u } // ClearStatus clears the value of the "status" field. func (u *WpChatroomUpsert) ClearStatus() *WpChatroomUpsert { u.SetNull(wpchatroom.FieldStatus) return u } // SetWxWxid sets the "wx_wxid" field. func (u *WpChatroomUpsert) SetWxWxid(v string) *WpChatroomUpsert { u.Set(wpchatroom.FieldWxWxid, v) return u } // UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create. func (u *WpChatroomUpsert) UpdateWxWxid() *WpChatroomUpsert { u.SetExcluded(wpchatroom.FieldWxWxid) return u } // SetChatroomID sets the "chatroom_id" field. func (u *WpChatroomUpsert) SetChatroomID(v string) *WpChatroomUpsert { u.Set(wpchatroom.FieldChatroomID, v) return u } // UpdateChatroomID sets the "chatroom_id" field to the value that was provided on create. func (u *WpChatroomUpsert) UpdateChatroomID() *WpChatroomUpsert { u.SetExcluded(wpchatroom.FieldChatroomID) return u } // SetNickname sets the "nickname" field. func (u *WpChatroomUpsert) SetNickname(v string) *WpChatroomUpsert { u.Set(wpchatroom.FieldNickname, v) return u } // UpdateNickname sets the "nickname" field to the value that was provided on create. func (u *WpChatroomUpsert) UpdateNickname() *WpChatroomUpsert { u.SetExcluded(wpchatroom.FieldNickname) return u } // SetOwner sets the "owner" field. func (u *WpChatroomUpsert) SetOwner(v string) *WpChatroomUpsert { u.Set(wpchatroom.FieldOwner, v) return u } // UpdateOwner sets the "owner" field to the value that was provided on create. func (u *WpChatroomUpsert) UpdateOwner() *WpChatroomUpsert { u.SetExcluded(wpchatroom.FieldOwner) return u } // SetAvatar sets the "avatar" field. func (u *WpChatroomUpsert) SetAvatar(v string) *WpChatroomUpsert { u.Set(wpchatroom.FieldAvatar, v) return u } // UpdateAvatar sets the "avatar" field to the value that was provided on create. func (u *WpChatroomUpsert) UpdateAvatar() *WpChatroomUpsert { u.SetExcluded(wpchatroom.FieldAvatar) return u } // SetMemberList sets the "member_list" field. func (u *WpChatroomUpsert) SetMemberList(v []string) *WpChatroomUpsert { u.Set(wpchatroom.FieldMemberList, v) return u } // UpdateMemberList sets the "member_list" field to the value that was provided on create. func (u *WpChatroomUpsert) UpdateMemberList() *WpChatroomUpsert { u.SetExcluded(wpchatroom.FieldMemberList) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. // Using this option is equivalent to using: // // client.WpChatroom.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(wpchatroom.FieldID) // }), // ). // Exec(ctx) func (u *WpChatroomUpsertOne) UpdateNewValues() *WpChatroomUpsertOne { 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.ID(); exists { s.SetIgnore(wpchatroom.FieldID) } if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(wpchatroom.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.WpChatroom.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *WpChatroomUpsertOne) Ignore() *WpChatroomUpsertOne { 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 *WpChatroomUpsertOne) DoNothing() *WpChatroomUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the WpChatroomCreate.OnConflict // documentation for more info. func (u *WpChatroomUpsertOne) Update(set func(*WpChatroomUpsert)) *WpChatroomUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&WpChatroomUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *WpChatroomUpsertOne) SetUpdatedAt(v time.Time) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *WpChatroomUpsertOne) UpdateUpdatedAt() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.UpdateUpdatedAt() }) } // SetStatus sets the "status" field. func (u *WpChatroomUpsertOne) SetStatus(v uint8) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.SetStatus(v) }) } // AddStatus adds v to the "status" field. func (u *WpChatroomUpsertOne) AddStatus(v uint8) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.AddStatus(v) }) } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *WpChatroomUpsertOne) UpdateStatus() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.UpdateStatus() }) } // ClearStatus clears the value of the "status" field. func (u *WpChatroomUpsertOne) ClearStatus() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.ClearStatus() }) } // SetWxWxid sets the "wx_wxid" field. func (u *WpChatroomUpsertOne) SetWxWxid(v string) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.SetWxWxid(v) }) } // UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create. func (u *WpChatroomUpsertOne) UpdateWxWxid() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.UpdateWxWxid() }) } // SetChatroomID sets the "chatroom_id" field. func (u *WpChatroomUpsertOne) SetChatroomID(v string) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.SetChatroomID(v) }) } // UpdateChatroomID sets the "chatroom_id" field to the value that was provided on create. func (u *WpChatroomUpsertOne) UpdateChatroomID() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.UpdateChatroomID() }) } // SetNickname sets the "nickname" field. func (u *WpChatroomUpsertOne) SetNickname(v string) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.SetNickname(v) }) } // UpdateNickname sets the "nickname" field to the value that was provided on create. func (u *WpChatroomUpsertOne) UpdateNickname() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.UpdateNickname() }) } // SetOwner sets the "owner" field. func (u *WpChatroomUpsertOne) SetOwner(v string) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.SetOwner(v) }) } // UpdateOwner sets the "owner" field to the value that was provided on create. func (u *WpChatroomUpsertOne) UpdateOwner() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.UpdateOwner() }) } // SetAvatar sets the "avatar" field. func (u *WpChatroomUpsertOne) SetAvatar(v string) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.SetAvatar(v) }) } // UpdateAvatar sets the "avatar" field to the value that was provided on create. func (u *WpChatroomUpsertOne) UpdateAvatar() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.UpdateAvatar() }) } // SetMemberList sets the "member_list" field. func (u *WpChatroomUpsertOne) SetMemberList(v []string) *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.SetMemberList(v) }) } // UpdateMemberList sets the "member_list" field to the value that was provided on create. func (u *WpChatroomUpsertOne) UpdateMemberList() *WpChatroomUpsertOne { return u.Update(func(s *WpChatroomUpsert) { s.UpdateMemberList() }) } // Exec executes the query. func (u *WpChatroomUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for WpChatroomCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *WpChatroomUpsertOne) 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 *WpChatroomUpsertOne) ID(ctx context.Context) (id uint64, 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 *WpChatroomUpsertOne) IDX(ctx context.Context) uint64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // WpChatroomCreateBulk is the builder for creating many WpChatroom entities in bulk. type WpChatroomCreateBulk struct { config err error builders []*WpChatroomCreate conflict []sql.ConflictOption } // Save creates the WpChatroom entities in the database. func (wccb *WpChatroomCreateBulk) Save(ctx context.Context) ([]*WpChatroom, error) { if wccb.err != nil { return nil, wccb.err } specs := make([]*sqlgraph.CreateSpec, len(wccb.builders)) nodes := make([]*WpChatroom, len(wccb.builders)) mutators := make([]Mutator, len(wccb.builders)) for i := range wccb.builders { func(i int, root context.Context) { builder := wccb.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*WpChatroomMutation) 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, wccb.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = wccb.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, wccb.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 && nodes[i].ID == 0 { id := specs[i].ID.Value.(int64) nodes[i].ID = uint64(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, wccb.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (wccb *WpChatroomCreateBulk) SaveX(ctx context.Context) []*WpChatroom { v, err := wccb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (wccb *WpChatroomCreateBulk) Exec(ctx context.Context) error { _, err := wccb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (wccb *WpChatroomCreateBulk) ExecX(ctx context.Context) { if err := wccb.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.WpChatroom.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.WpChatroomUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (wccb *WpChatroomCreateBulk) OnConflict(opts ...sql.ConflictOption) *WpChatroomUpsertBulk { wccb.conflict = opts return &WpChatroomUpsertBulk{ create: wccb, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.WpChatroom.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (wccb *WpChatroomCreateBulk) OnConflictColumns(columns ...string) *WpChatroomUpsertBulk { wccb.conflict = append(wccb.conflict, sql.ConflictColumns(columns...)) return &WpChatroomUpsertBulk{ create: wccb, } } // WpChatroomUpsertBulk is the builder for "upsert"-ing // a bulk of WpChatroom nodes. type WpChatroomUpsertBulk struct { create *WpChatroomCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.WpChatroom.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(wpchatroom.FieldID) // }), // ). // Exec(ctx) func (u *WpChatroomUpsertBulk) UpdateNewValues() *WpChatroomUpsertBulk { 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.ID(); exists { s.SetIgnore(wpchatroom.FieldID) } if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(wpchatroom.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.WpChatroom.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *WpChatroomUpsertBulk) Ignore() *WpChatroomUpsertBulk { 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 *WpChatroomUpsertBulk) DoNothing() *WpChatroomUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the WpChatroomCreateBulk.OnConflict // documentation for more info. func (u *WpChatroomUpsertBulk) Update(set func(*WpChatroomUpsert)) *WpChatroomUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&WpChatroomUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *WpChatroomUpsertBulk) SetUpdatedAt(v time.Time) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *WpChatroomUpsertBulk) UpdateUpdatedAt() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.UpdateUpdatedAt() }) } // SetStatus sets the "status" field. func (u *WpChatroomUpsertBulk) SetStatus(v uint8) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.SetStatus(v) }) } // AddStatus adds v to the "status" field. func (u *WpChatroomUpsertBulk) AddStatus(v uint8) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.AddStatus(v) }) } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *WpChatroomUpsertBulk) UpdateStatus() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.UpdateStatus() }) } // ClearStatus clears the value of the "status" field. func (u *WpChatroomUpsertBulk) ClearStatus() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.ClearStatus() }) } // SetWxWxid sets the "wx_wxid" field. func (u *WpChatroomUpsertBulk) SetWxWxid(v string) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.SetWxWxid(v) }) } // UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create. func (u *WpChatroomUpsertBulk) UpdateWxWxid() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.UpdateWxWxid() }) } // SetChatroomID sets the "chatroom_id" field. func (u *WpChatroomUpsertBulk) SetChatroomID(v string) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.SetChatroomID(v) }) } // UpdateChatroomID sets the "chatroom_id" field to the value that was provided on create. func (u *WpChatroomUpsertBulk) UpdateChatroomID() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.UpdateChatroomID() }) } // SetNickname sets the "nickname" field. func (u *WpChatroomUpsertBulk) SetNickname(v string) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.SetNickname(v) }) } // UpdateNickname sets the "nickname" field to the value that was provided on create. func (u *WpChatroomUpsertBulk) UpdateNickname() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.UpdateNickname() }) } // SetOwner sets the "owner" field. func (u *WpChatroomUpsertBulk) SetOwner(v string) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.SetOwner(v) }) } // UpdateOwner sets the "owner" field to the value that was provided on create. func (u *WpChatroomUpsertBulk) UpdateOwner() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.UpdateOwner() }) } // SetAvatar sets the "avatar" field. func (u *WpChatroomUpsertBulk) SetAvatar(v string) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.SetAvatar(v) }) } // UpdateAvatar sets the "avatar" field to the value that was provided on create. func (u *WpChatroomUpsertBulk) UpdateAvatar() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.UpdateAvatar() }) } // SetMemberList sets the "member_list" field. func (u *WpChatroomUpsertBulk) SetMemberList(v []string) *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.SetMemberList(v) }) } // UpdateMemberList sets the "member_list" field to the value that was provided on create. func (u *WpChatroomUpsertBulk) UpdateMemberList() *WpChatroomUpsertBulk { return u.Update(func(s *WpChatroomUpsert) { s.UpdateMemberList() }) } // Exec executes the query. func (u *WpChatroomUpsertBulk) 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 WpChatroomCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for WpChatroomCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *WpChatroomUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }