123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014 |
- // 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)
- }
- }
|