123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/contact"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // ContactCreate is the builder for creating a Contact entity.
- type ContactCreate struct {
- config
- mutation *ContactMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (cc *ContactCreate) SetCreatedAt(t time.Time) *ContactCreate {
- cc.mutation.SetCreatedAt(t)
- return cc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableCreatedAt(t *time.Time) *ContactCreate {
- if t != nil {
- cc.SetCreatedAt(*t)
- }
- return cc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cc *ContactCreate) SetUpdatedAt(t time.Time) *ContactCreate {
- cc.mutation.SetUpdatedAt(t)
- return cc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableUpdatedAt(t *time.Time) *ContactCreate {
- if t != nil {
- cc.SetUpdatedAt(*t)
- }
- return cc
- }
- // SetStatus sets the "status" field.
- func (cc *ContactCreate) SetStatus(u uint8) *ContactCreate {
- cc.mutation.SetStatus(u)
- return cc
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableStatus(u *uint8) *ContactCreate {
- if u != nil {
- cc.SetStatus(*u)
- }
- return cc
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (cc *ContactCreate) SetDeletedAt(t time.Time) *ContactCreate {
- cc.mutation.SetDeletedAt(t)
- return cc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableDeletedAt(t *time.Time) *ContactCreate {
- if t != nil {
- cc.SetDeletedAt(*t)
- }
- return cc
- }
- // SetWxWxid sets the "wx_wxid" field.
- func (cc *ContactCreate) SetWxWxid(s string) *ContactCreate {
- cc.mutation.SetWxWxid(s)
- return cc
- }
- // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableWxWxid(s *string) *ContactCreate {
- if s != nil {
- cc.SetWxWxid(*s)
- }
- return cc
- }
- // SetType sets the "type" field.
- func (cc *ContactCreate) SetType(i int) *ContactCreate {
- cc.mutation.SetType(i)
- return cc
- }
- // SetNillableType sets the "type" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableType(i *int) *ContactCreate {
- if i != nil {
- cc.SetType(*i)
- }
- return cc
- }
- // SetWxid sets the "wxid" field.
- func (cc *ContactCreate) SetWxid(s string) *ContactCreate {
- cc.mutation.SetWxid(s)
- return cc
- }
- // SetNillableWxid sets the "wxid" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableWxid(s *string) *ContactCreate {
- if s != nil {
- cc.SetWxid(*s)
- }
- return cc
- }
- // SetAccount sets the "account" field.
- func (cc *ContactCreate) SetAccount(s string) *ContactCreate {
- cc.mutation.SetAccount(s)
- return cc
- }
- // SetNillableAccount sets the "account" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableAccount(s *string) *ContactCreate {
- if s != nil {
- cc.SetAccount(*s)
- }
- return cc
- }
- // SetNickname sets the "nickname" field.
- func (cc *ContactCreate) SetNickname(s string) *ContactCreate {
- cc.mutation.SetNickname(s)
- return cc
- }
- // SetNillableNickname sets the "nickname" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableNickname(s *string) *ContactCreate {
- if s != nil {
- cc.SetNickname(*s)
- }
- return cc
- }
- // SetMarkname sets the "markname" field.
- func (cc *ContactCreate) SetMarkname(s string) *ContactCreate {
- cc.mutation.SetMarkname(s)
- return cc
- }
- // SetNillableMarkname sets the "markname" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableMarkname(s *string) *ContactCreate {
- if s != nil {
- cc.SetMarkname(*s)
- }
- return cc
- }
- // SetHeadimg sets the "headimg" field.
- func (cc *ContactCreate) SetHeadimg(s string) *ContactCreate {
- cc.mutation.SetHeadimg(s)
- return cc
- }
- // SetNillableHeadimg sets the "headimg" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableHeadimg(s *string) *ContactCreate {
- if s != nil {
- cc.SetHeadimg(*s)
- }
- return cc
- }
- // SetSex sets the "sex" field.
- func (cc *ContactCreate) SetSex(i int) *ContactCreate {
- cc.mutation.SetSex(i)
- return cc
- }
- // SetNillableSex sets the "sex" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableSex(i *int) *ContactCreate {
- if i != nil {
- cc.SetSex(*i)
- }
- return cc
- }
- // SetStarrole sets the "starrole" field.
- func (cc *ContactCreate) SetStarrole(s string) *ContactCreate {
- cc.mutation.SetStarrole(s)
- return cc
- }
- // SetNillableStarrole sets the "starrole" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableStarrole(s *string) *ContactCreate {
- if s != nil {
- cc.SetStarrole(*s)
- }
- return cc
- }
- // SetDontseeit sets the "dontseeit" field.
- func (cc *ContactCreate) SetDontseeit(i int) *ContactCreate {
- cc.mutation.SetDontseeit(i)
- return cc
- }
- // SetNillableDontseeit sets the "dontseeit" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableDontseeit(i *int) *ContactCreate {
- if i != nil {
- cc.SetDontseeit(*i)
- }
- return cc
- }
- // SetDontseeme sets the "dontseeme" field.
- func (cc *ContactCreate) SetDontseeme(i int) *ContactCreate {
- cc.mutation.SetDontseeme(i)
- return cc
- }
- // SetNillableDontseeme sets the "dontseeme" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableDontseeme(i *int) *ContactCreate {
- if i != nil {
- cc.SetDontseeme(*i)
- }
- return cc
- }
- // SetLag sets the "lag" field.
- func (cc *ContactCreate) SetLag(s string) *ContactCreate {
- cc.mutation.SetLag(s)
- return cc
- }
- // SetNillableLag sets the "lag" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableLag(s *string) *ContactCreate {
- if s != nil {
- cc.SetLag(*s)
- }
- return cc
- }
- // SetGid sets the "gid" field.
- func (cc *ContactCreate) SetGid(s string) *ContactCreate {
- cc.mutation.SetGid(s)
- return cc
- }
- // SetNillableGid sets the "gid" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableGid(s *string) *ContactCreate {
- if s != nil {
- cc.SetGid(*s)
- }
- return cc
- }
- // SetGname sets the "gname" field.
- func (cc *ContactCreate) SetGname(s string) *ContactCreate {
- cc.mutation.SetGname(s)
- return cc
- }
- // SetNillableGname sets the "gname" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableGname(s *string) *ContactCreate {
- if s != nil {
- cc.SetGname(*s)
- }
- return cc
- }
- // SetV3 sets the "v3" field.
- func (cc *ContactCreate) SetV3(s string) *ContactCreate {
- cc.mutation.SetV3(s)
- return cc
- }
- // SetNillableV3 sets the "v3" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableV3(s *string) *ContactCreate {
- if s != nil {
- cc.SetV3(*s)
- }
- return cc
- }
- // SetID sets the "id" field.
- func (cc *ContactCreate) SetID(u uint64) *ContactCreate {
- cc.mutation.SetID(u)
- return cc
- }
- // Mutation returns the ContactMutation object of the builder.
- func (cc *ContactCreate) Mutation() *ContactMutation {
- return cc.mutation
- }
- // Save creates the Contact in the database.
- func (cc *ContactCreate) Save(ctx context.Context) (*Contact, error) {
- if err := cc.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (cc *ContactCreate) SaveX(ctx context.Context) *Contact {
- v, err := cc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (cc *ContactCreate) Exec(ctx context.Context) error {
- _, err := cc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cc *ContactCreate) ExecX(ctx context.Context) {
- if err := cc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cc *ContactCreate) defaults() error {
- if _, ok := cc.mutation.CreatedAt(); !ok {
- if contact.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized contact.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := contact.DefaultCreatedAt()
- cc.mutation.SetCreatedAt(v)
- }
- if _, ok := cc.mutation.UpdatedAt(); !ok {
- if contact.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized contact.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := contact.DefaultUpdatedAt()
- cc.mutation.SetUpdatedAt(v)
- }
- if _, ok := cc.mutation.Status(); !ok {
- v := contact.DefaultStatus
- cc.mutation.SetStatus(v)
- }
- if _, ok := cc.mutation.WxWxid(); !ok {
- v := contact.DefaultWxWxid
- cc.mutation.SetWxWxid(v)
- }
- if _, ok := cc.mutation.GetType(); !ok {
- v := contact.DefaultType
- cc.mutation.SetType(v)
- }
- if _, ok := cc.mutation.Wxid(); !ok {
- v := contact.DefaultWxid
- cc.mutation.SetWxid(v)
- }
- if _, ok := cc.mutation.Account(); !ok {
- v := contact.DefaultAccount
- cc.mutation.SetAccount(v)
- }
- if _, ok := cc.mutation.Nickname(); !ok {
- v := contact.DefaultNickname
- cc.mutation.SetNickname(v)
- }
- if _, ok := cc.mutation.Markname(); !ok {
- v := contact.DefaultMarkname
- cc.mutation.SetMarkname(v)
- }
- if _, ok := cc.mutation.Headimg(); !ok {
- v := contact.DefaultHeadimg
- cc.mutation.SetHeadimg(v)
- }
- if _, ok := cc.mutation.Sex(); !ok {
- v := contact.DefaultSex
- cc.mutation.SetSex(v)
- }
- if _, ok := cc.mutation.Starrole(); !ok {
- v := contact.DefaultStarrole
- cc.mutation.SetStarrole(v)
- }
- if _, ok := cc.mutation.Dontseeit(); !ok {
- v := contact.DefaultDontseeit
- cc.mutation.SetDontseeit(v)
- }
- if _, ok := cc.mutation.Dontseeme(); !ok {
- v := contact.DefaultDontseeme
- cc.mutation.SetDontseeme(v)
- }
- if _, ok := cc.mutation.Lag(); !ok {
- v := contact.DefaultLag
- cc.mutation.SetLag(v)
- }
- if _, ok := cc.mutation.Gid(); !ok {
- v := contact.DefaultGid
- cc.mutation.SetGid(v)
- }
- if _, ok := cc.mutation.Gname(); !ok {
- v := contact.DefaultGname
- cc.mutation.SetGname(v)
- }
- if _, ok := cc.mutation.V3(); !ok {
- v := contact.DefaultV3
- cc.mutation.SetV3(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (cc *ContactCreate) check() error {
- if _, ok := cc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Contact.created_at"`)}
- }
- if _, ok := cc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Contact.updated_at"`)}
- }
- if _, ok := cc.mutation.Wxid(); !ok {
- return &ValidationError{Name: "wxid", err: errors.New(`ent: missing required field "Contact.wxid"`)}
- }
- if _, ok := cc.mutation.Account(); !ok {
- return &ValidationError{Name: "account", err: errors.New(`ent: missing required field "Contact.account"`)}
- }
- if _, ok := cc.mutation.Nickname(); !ok {
- return &ValidationError{Name: "nickname", err: errors.New(`ent: missing required field "Contact.nickname"`)}
- }
- if _, ok := cc.mutation.Markname(); !ok {
- return &ValidationError{Name: "markname", err: errors.New(`ent: missing required field "Contact.markname"`)}
- }
- if _, ok := cc.mutation.Headimg(); !ok {
- return &ValidationError{Name: "headimg", err: errors.New(`ent: missing required field "Contact.headimg"`)}
- }
- if _, ok := cc.mutation.Sex(); !ok {
- return &ValidationError{Name: "sex", err: errors.New(`ent: missing required field "Contact.sex"`)}
- }
- if _, ok := cc.mutation.Starrole(); !ok {
- return &ValidationError{Name: "starrole", err: errors.New(`ent: missing required field "Contact.starrole"`)}
- }
- if _, ok := cc.mutation.Dontseeit(); !ok {
- return &ValidationError{Name: "dontseeit", err: errors.New(`ent: missing required field "Contact.dontseeit"`)}
- }
- if _, ok := cc.mutation.Dontseeme(); !ok {
- return &ValidationError{Name: "dontseeme", err: errors.New(`ent: missing required field "Contact.dontseeme"`)}
- }
- if _, ok := cc.mutation.Lag(); !ok {
- return &ValidationError{Name: "lag", err: errors.New(`ent: missing required field "Contact.lag"`)}
- }
- if _, ok := cc.mutation.Gid(); !ok {
- return &ValidationError{Name: "gid", err: errors.New(`ent: missing required field "Contact.gid"`)}
- }
- if _, ok := cc.mutation.Gname(); !ok {
- return &ValidationError{Name: "gname", err: errors.New(`ent: missing required field "Contact.gname"`)}
- }
- if _, ok := cc.mutation.V3(); !ok {
- return &ValidationError{Name: "v3", err: errors.New(`ent: missing required field "Contact.v3"`)}
- }
- return nil
- }
- func (cc *ContactCreate) sqlSave(ctx context.Context) (*Contact, error) {
- if err := cc.check(); err != nil {
- return nil, err
- }
- _node, _spec := cc.createSpec()
- if err := sqlgraph.CreateNode(ctx, cc.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)
- }
- cc.mutation.id = &_node.ID
- cc.mutation.done = true
- return _node, nil
- }
- func (cc *ContactCreate) createSpec() (*Contact, *sqlgraph.CreateSpec) {
- var (
- _node = &Contact{config: cc.config}
- _spec = sqlgraph.NewCreateSpec(contact.Table, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = cc.conflict
- if id, ok := cc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := cc.mutation.CreatedAt(); ok {
- _spec.SetField(contact.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := cc.mutation.UpdatedAt(); ok {
- _spec.SetField(contact.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := cc.mutation.Status(); ok {
- _spec.SetField(contact.FieldStatus, field.TypeUint8, value)
- _node.Status = value
- }
- if value, ok := cc.mutation.DeletedAt(); ok {
- _spec.SetField(contact.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if value, ok := cc.mutation.WxWxid(); ok {
- _spec.SetField(contact.FieldWxWxid, field.TypeString, value)
- _node.WxWxid = value
- }
- if value, ok := cc.mutation.GetType(); ok {
- _spec.SetField(contact.FieldType, field.TypeInt, value)
- _node.Type = value
- }
- if value, ok := cc.mutation.Wxid(); ok {
- _spec.SetField(contact.FieldWxid, field.TypeString, value)
- _node.Wxid = value
- }
- if value, ok := cc.mutation.Account(); ok {
- _spec.SetField(contact.FieldAccount, field.TypeString, value)
- _node.Account = value
- }
- if value, ok := cc.mutation.Nickname(); ok {
- _spec.SetField(contact.FieldNickname, field.TypeString, value)
- _node.Nickname = value
- }
- if value, ok := cc.mutation.Markname(); ok {
- _spec.SetField(contact.FieldMarkname, field.TypeString, value)
- _node.Markname = value
- }
- if value, ok := cc.mutation.Headimg(); ok {
- _spec.SetField(contact.FieldHeadimg, field.TypeString, value)
- _node.Headimg = value
- }
- if value, ok := cc.mutation.Sex(); ok {
- _spec.SetField(contact.FieldSex, field.TypeInt, value)
- _node.Sex = value
- }
- if value, ok := cc.mutation.Starrole(); ok {
- _spec.SetField(contact.FieldStarrole, field.TypeString, value)
- _node.Starrole = value
- }
- if value, ok := cc.mutation.Dontseeit(); ok {
- _spec.SetField(contact.FieldDontseeit, field.TypeInt, value)
- _node.Dontseeit = value
- }
- if value, ok := cc.mutation.Dontseeme(); ok {
- _spec.SetField(contact.FieldDontseeme, field.TypeInt, value)
- _node.Dontseeme = value
- }
- if value, ok := cc.mutation.Lag(); ok {
- _spec.SetField(contact.FieldLag, field.TypeString, value)
- _node.Lag = value
- }
- if value, ok := cc.mutation.Gid(); ok {
- _spec.SetField(contact.FieldGid, field.TypeString, value)
- _node.Gid = value
- }
- if value, ok := cc.mutation.Gname(); ok {
- _spec.SetField(contact.FieldGname, field.TypeString, value)
- _node.Gname = value
- }
- if value, ok := cc.mutation.V3(); ok {
- _spec.SetField(contact.FieldV3, field.TypeString, value)
- _node.V3 = value
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Contact.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.ContactUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (cc *ContactCreate) OnConflict(opts ...sql.ConflictOption) *ContactUpsertOne {
- cc.conflict = opts
- return &ContactUpsertOne{
- create: cc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Contact.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (cc *ContactCreate) OnConflictColumns(columns ...string) *ContactUpsertOne {
- cc.conflict = append(cc.conflict, sql.ConflictColumns(columns...))
- return &ContactUpsertOne{
- create: cc,
- }
- }
- type (
- // ContactUpsertOne is the builder for "upsert"-ing
- // one Contact node.
- ContactUpsertOne struct {
- create *ContactCreate
- }
- // ContactUpsert is the "OnConflict" setter.
- ContactUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *ContactUpsert) SetUpdatedAt(v time.Time) *ContactUpsert {
- u.Set(contact.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateUpdatedAt() *ContactUpsert {
- u.SetExcluded(contact.FieldUpdatedAt)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *ContactUpsert) SetStatus(v uint8) *ContactUpsert {
- u.Set(contact.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateStatus() *ContactUpsert {
- u.SetExcluded(contact.FieldStatus)
- return u
- }
- // AddStatus adds v to the "status" field.
- func (u *ContactUpsert) AddStatus(v uint8) *ContactUpsert {
- u.Add(contact.FieldStatus, v)
- return u
- }
- // ClearStatus clears the value of the "status" field.
- func (u *ContactUpsert) ClearStatus() *ContactUpsert {
- u.SetNull(contact.FieldStatus)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *ContactUpsert) SetDeletedAt(v time.Time) *ContactUpsert {
- u.Set(contact.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateDeletedAt() *ContactUpsert {
- u.SetExcluded(contact.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *ContactUpsert) ClearDeletedAt() *ContactUpsert {
- u.SetNull(contact.FieldDeletedAt)
- return u
- }
- // SetWxWxid sets the "wx_wxid" field.
- func (u *ContactUpsert) SetWxWxid(v string) *ContactUpsert {
- u.Set(contact.FieldWxWxid, v)
- return u
- }
- // UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateWxWxid() *ContactUpsert {
- u.SetExcluded(contact.FieldWxWxid)
- return u
- }
- // ClearWxWxid clears the value of the "wx_wxid" field.
- func (u *ContactUpsert) ClearWxWxid() *ContactUpsert {
- u.SetNull(contact.FieldWxWxid)
- return u
- }
- // SetType sets the "type" field.
- func (u *ContactUpsert) SetType(v int) *ContactUpsert {
- u.Set(contact.FieldType, v)
- return u
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateType() *ContactUpsert {
- u.SetExcluded(contact.FieldType)
- return u
- }
- // AddType adds v to the "type" field.
- func (u *ContactUpsert) AddType(v int) *ContactUpsert {
- u.Add(contact.FieldType, v)
- return u
- }
- // ClearType clears the value of the "type" field.
- func (u *ContactUpsert) ClearType() *ContactUpsert {
- u.SetNull(contact.FieldType)
- return u
- }
- // SetWxid sets the "wxid" field.
- func (u *ContactUpsert) SetWxid(v string) *ContactUpsert {
- u.Set(contact.FieldWxid, v)
- return u
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateWxid() *ContactUpsert {
- u.SetExcluded(contact.FieldWxid)
- return u
- }
- // SetAccount sets the "account" field.
- func (u *ContactUpsert) SetAccount(v string) *ContactUpsert {
- u.Set(contact.FieldAccount, v)
- return u
- }
- // UpdateAccount sets the "account" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateAccount() *ContactUpsert {
- u.SetExcluded(contact.FieldAccount)
- return u
- }
- // SetNickname sets the "nickname" field.
- func (u *ContactUpsert) SetNickname(v string) *ContactUpsert {
- u.Set(contact.FieldNickname, v)
- return u
- }
- // UpdateNickname sets the "nickname" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateNickname() *ContactUpsert {
- u.SetExcluded(contact.FieldNickname)
- return u
- }
- // SetMarkname sets the "markname" field.
- func (u *ContactUpsert) SetMarkname(v string) *ContactUpsert {
- u.Set(contact.FieldMarkname, v)
- return u
- }
- // UpdateMarkname sets the "markname" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateMarkname() *ContactUpsert {
- u.SetExcluded(contact.FieldMarkname)
- return u
- }
- // SetHeadimg sets the "headimg" field.
- func (u *ContactUpsert) SetHeadimg(v string) *ContactUpsert {
- u.Set(contact.FieldHeadimg, v)
- return u
- }
- // UpdateHeadimg sets the "headimg" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateHeadimg() *ContactUpsert {
- u.SetExcluded(contact.FieldHeadimg)
- return u
- }
- // SetSex sets the "sex" field.
- func (u *ContactUpsert) SetSex(v int) *ContactUpsert {
- u.Set(contact.FieldSex, v)
- return u
- }
- // UpdateSex sets the "sex" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateSex() *ContactUpsert {
- u.SetExcluded(contact.FieldSex)
- return u
- }
- // AddSex adds v to the "sex" field.
- func (u *ContactUpsert) AddSex(v int) *ContactUpsert {
- u.Add(contact.FieldSex, v)
- return u
- }
- // SetStarrole sets the "starrole" field.
- func (u *ContactUpsert) SetStarrole(v string) *ContactUpsert {
- u.Set(contact.FieldStarrole, v)
- return u
- }
- // UpdateStarrole sets the "starrole" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateStarrole() *ContactUpsert {
- u.SetExcluded(contact.FieldStarrole)
- return u
- }
- // SetDontseeit sets the "dontseeit" field.
- func (u *ContactUpsert) SetDontseeit(v int) *ContactUpsert {
- u.Set(contact.FieldDontseeit, v)
- return u
- }
- // UpdateDontseeit sets the "dontseeit" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateDontseeit() *ContactUpsert {
- u.SetExcluded(contact.FieldDontseeit)
- return u
- }
- // AddDontseeit adds v to the "dontseeit" field.
- func (u *ContactUpsert) AddDontseeit(v int) *ContactUpsert {
- u.Add(contact.FieldDontseeit, v)
- return u
- }
- // SetDontseeme sets the "dontseeme" field.
- func (u *ContactUpsert) SetDontseeme(v int) *ContactUpsert {
- u.Set(contact.FieldDontseeme, v)
- return u
- }
- // UpdateDontseeme sets the "dontseeme" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateDontseeme() *ContactUpsert {
- u.SetExcluded(contact.FieldDontseeme)
- return u
- }
- // AddDontseeme adds v to the "dontseeme" field.
- func (u *ContactUpsert) AddDontseeme(v int) *ContactUpsert {
- u.Add(contact.FieldDontseeme, v)
- return u
- }
- // SetLag sets the "lag" field.
- func (u *ContactUpsert) SetLag(v string) *ContactUpsert {
- u.Set(contact.FieldLag, v)
- return u
- }
- // UpdateLag sets the "lag" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateLag() *ContactUpsert {
- u.SetExcluded(contact.FieldLag)
- return u
- }
- // SetGid sets the "gid" field.
- func (u *ContactUpsert) SetGid(v string) *ContactUpsert {
- u.Set(contact.FieldGid, v)
- return u
- }
- // UpdateGid sets the "gid" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateGid() *ContactUpsert {
- u.SetExcluded(contact.FieldGid)
- return u
- }
- // SetGname sets the "gname" field.
- func (u *ContactUpsert) SetGname(v string) *ContactUpsert {
- u.Set(contact.FieldGname, v)
- return u
- }
- // UpdateGname sets the "gname" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateGname() *ContactUpsert {
- u.SetExcluded(contact.FieldGname)
- return u
- }
- // SetV3 sets the "v3" field.
- func (u *ContactUpsert) SetV3(v string) *ContactUpsert {
- u.Set(contact.FieldV3, v)
- return u
- }
- // UpdateV3 sets the "v3" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateV3() *ContactUpsert {
- u.SetExcluded(contact.FieldV3)
- 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.Contact.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(contact.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *ContactUpsertOne) UpdateNewValues() *ContactUpsertOne {
- 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(contact.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(contact.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Contact.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *ContactUpsertOne) Ignore() *ContactUpsertOne {
- 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 *ContactUpsertOne) DoNothing() *ContactUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the ContactCreate.OnConflict
- // documentation for more info.
- func (u *ContactUpsertOne) Update(set func(*ContactUpsert)) *ContactUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&ContactUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *ContactUpsertOne) SetUpdatedAt(v time.Time) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateUpdatedAt() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *ContactUpsertOne) SetStatus(v uint8) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *ContactUpsertOne) AddStatus(v uint8) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateStatus() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *ContactUpsertOne) ClearStatus() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.ClearStatus()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *ContactUpsertOne) SetDeletedAt(v time.Time) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateDeletedAt() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *ContactUpsertOne) ClearDeletedAt() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetWxWxid sets the "wx_wxid" field.
- func (u *ContactUpsertOne) SetWxWxid(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetWxWxid(v)
- })
- }
- // UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateWxWxid() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateWxWxid()
- })
- }
- // ClearWxWxid clears the value of the "wx_wxid" field.
- func (u *ContactUpsertOne) ClearWxWxid() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.ClearWxWxid()
- })
- }
- // SetType sets the "type" field.
- func (u *ContactUpsertOne) SetType(v int) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetType(v)
- })
- }
- // AddType adds v to the "type" field.
- func (u *ContactUpsertOne) AddType(v int) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.AddType(v)
- })
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateType() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateType()
- })
- }
- // ClearType clears the value of the "type" field.
- func (u *ContactUpsertOne) ClearType() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.ClearType()
- })
- }
- // SetWxid sets the "wxid" field.
- func (u *ContactUpsertOne) SetWxid(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetWxid(v)
- })
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateWxid() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateWxid()
- })
- }
- // SetAccount sets the "account" field.
- func (u *ContactUpsertOne) SetAccount(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetAccount(v)
- })
- }
- // UpdateAccount sets the "account" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateAccount() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateAccount()
- })
- }
- // SetNickname sets the "nickname" field.
- func (u *ContactUpsertOne) SetNickname(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetNickname(v)
- })
- }
- // UpdateNickname sets the "nickname" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateNickname() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateNickname()
- })
- }
- // SetMarkname sets the "markname" field.
- func (u *ContactUpsertOne) SetMarkname(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetMarkname(v)
- })
- }
- // UpdateMarkname sets the "markname" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateMarkname() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateMarkname()
- })
- }
- // SetHeadimg sets the "headimg" field.
- func (u *ContactUpsertOne) SetHeadimg(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetHeadimg(v)
- })
- }
- // UpdateHeadimg sets the "headimg" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateHeadimg() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateHeadimg()
- })
- }
- // SetSex sets the "sex" field.
- func (u *ContactUpsertOne) SetSex(v int) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetSex(v)
- })
- }
- // AddSex adds v to the "sex" field.
- func (u *ContactUpsertOne) AddSex(v int) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.AddSex(v)
- })
- }
- // UpdateSex sets the "sex" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateSex() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateSex()
- })
- }
- // SetStarrole sets the "starrole" field.
- func (u *ContactUpsertOne) SetStarrole(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetStarrole(v)
- })
- }
- // UpdateStarrole sets the "starrole" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateStarrole() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateStarrole()
- })
- }
- // SetDontseeit sets the "dontseeit" field.
- func (u *ContactUpsertOne) SetDontseeit(v int) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetDontseeit(v)
- })
- }
- // AddDontseeit adds v to the "dontseeit" field.
- func (u *ContactUpsertOne) AddDontseeit(v int) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.AddDontseeit(v)
- })
- }
- // UpdateDontseeit sets the "dontseeit" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateDontseeit() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateDontseeit()
- })
- }
- // SetDontseeme sets the "dontseeme" field.
- func (u *ContactUpsertOne) SetDontseeme(v int) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetDontseeme(v)
- })
- }
- // AddDontseeme adds v to the "dontseeme" field.
- func (u *ContactUpsertOne) AddDontseeme(v int) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.AddDontseeme(v)
- })
- }
- // UpdateDontseeme sets the "dontseeme" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateDontseeme() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateDontseeme()
- })
- }
- // SetLag sets the "lag" field.
- func (u *ContactUpsertOne) SetLag(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetLag(v)
- })
- }
- // UpdateLag sets the "lag" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateLag() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateLag()
- })
- }
- // SetGid sets the "gid" field.
- func (u *ContactUpsertOne) SetGid(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetGid(v)
- })
- }
- // UpdateGid sets the "gid" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateGid() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateGid()
- })
- }
- // SetGname sets the "gname" field.
- func (u *ContactUpsertOne) SetGname(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetGname(v)
- })
- }
- // UpdateGname sets the "gname" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateGname() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateGname()
- })
- }
- // SetV3 sets the "v3" field.
- func (u *ContactUpsertOne) SetV3(v string) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetV3(v)
- })
- }
- // UpdateV3 sets the "v3" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateV3() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateV3()
- })
- }
- // Exec executes the query.
- func (u *ContactUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for ContactCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *ContactUpsertOne) 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 *ContactUpsertOne) 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 *ContactUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // ContactCreateBulk is the builder for creating many Contact entities in bulk.
- type ContactCreateBulk struct {
- config
- err error
- builders []*ContactCreate
- conflict []sql.ConflictOption
- }
- // Save creates the Contact entities in the database.
- func (ccb *ContactCreateBulk) Save(ctx context.Context) ([]*Contact, error) {
- if ccb.err != nil {
- return nil, ccb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
- nodes := make([]*Contact, len(ccb.builders))
- mutators := make([]Mutator, len(ccb.builders))
- for i := range ccb.builders {
- func(i int, root context.Context) {
- builder := ccb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*ContactMutation)
- 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, ccb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = ccb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, ccb.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, ccb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (ccb *ContactCreateBulk) SaveX(ctx context.Context) []*Contact {
- v, err := ccb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (ccb *ContactCreateBulk) Exec(ctx context.Context) error {
- _, err := ccb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (ccb *ContactCreateBulk) ExecX(ctx context.Context) {
- if err := ccb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Contact.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.ContactUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (ccb *ContactCreateBulk) OnConflict(opts ...sql.ConflictOption) *ContactUpsertBulk {
- ccb.conflict = opts
- return &ContactUpsertBulk{
- create: ccb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Contact.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (ccb *ContactCreateBulk) OnConflictColumns(columns ...string) *ContactUpsertBulk {
- ccb.conflict = append(ccb.conflict, sql.ConflictColumns(columns...))
- return &ContactUpsertBulk{
- create: ccb,
- }
- }
- // ContactUpsertBulk is the builder for "upsert"-ing
- // a bulk of Contact nodes.
- type ContactUpsertBulk struct {
- create *ContactCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.Contact.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(contact.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *ContactUpsertBulk) UpdateNewValues() *ContactUpsertBulk {
- 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(contact.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(contact.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Contact.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *ContactUpsertBulk) Ignore() *ContactUpsertBulk {
- 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 *ContactUpsertBulk) DoNothing() *ContactUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the ContactCreateBulk.OnConflict
- // documentation for more info.
- func (u *ContactUpsertBulk) Update(set func(*ContactUpsert)) *ContactUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&ContactUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *ContactUpsertBulk) SetUpdatedAt(v time.Time) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateUpdatedAt() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *ContactUpsertBulk) SetStatus(v uint8) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *ContactUpsertBulk) AddStatus(v uint8) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateStatus() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *ContactUpsertBulk) ClearStatus() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.ClearStatus()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *ContactUpsertBulk) SetDeletedAt(v time.Time) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateDeletedAt() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *ContactUpsertBulk) ClearDeletedAt() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetWxWxid sets the "wx_wxid" field.
- func (u *ContactUpsertBulk) SetWxWxid(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetWxWxid(v)
- })
- }
- // UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateWxWxid() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateWxWxid()
- })
- }
- // ClearWxWxid clears the value of the "wx_wxid" field.
- func (u *ContactUpsertBulk) ClearWxWxid() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.ClearWxWxid()
- })
- }
- // SetType sets the "type" field.
- func (u *ContactUpsertBulk) SetType(v int) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetType(v)
- })
- }
- // AddType adds v to the "type" field.
- func (u *ContactUpsertBulk) AddType(v int) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.AddType(v)
- })
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateType() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateType()
- })
- }
- // ClearType clears the value of the "type" field.
- func (u *ContactUpsertBulk) ClearType() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.ClearType()
- })
- }
- // SetWxid sets the "wxid" field.
- func (u *ContactUpsertBulk) SetWxid(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetWxid(v)
- })
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateWxid() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateWxid()
- })
- }
- // SetAccount sets the "account" field.
- func (u *ContactUpsertBulk) SetAccount(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetAccount(v)
- })
- }
- // UpdateAccount sets the "account" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateAccount() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateAccount()
- })
- }
- // SetNickname sets the "nickname" field.
- func (u *ContactUpsertBulk) SetNickname(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetNickname(v)
- })
- }
- // UpdateNickname sets the "nickname" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateNickname() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateNickname()
- })
- }
- // SetMarkname sets the "markname" field.
- func (u *ContactUpsertBulk) SetMarkname(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetMarkname(v)
- })
- }
- // UpdateMarkname sets the "markname" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateMarkname() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateMarkname()
- })
- }
- // SetHeadimg sets the "headimg" field.
- func (u *ContactUpsertBulk) SetHeadimg(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetHeadimg(v)
- })
- }
- // UpdateHeadimg sets the "headimg" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateHeadimg() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateHeadimg()
- })
- }
- // SetSex sets the "sex" field.
- func (u *ContactUpsertBulk) SetSex(v int) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetSex(v)
- })
- }
- // AddSex adds v to the "sex" field.
- func (u *ContactUpsertBulk) AddSex(v int) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.AddSex(v)
- })
- }
- // UpdateSex sets the "sex" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateSex() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateSex()
- })
- }
- // SetStarrole sets the "starrole" field.
- func (u *ContactUpsertBulk) SetStarrole(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetStarrole(v)
- })
- }
- // UpdateStarrole sets the "starrole" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateStarrole() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateStarrole()
- })
- }
- // SetDontseeit sets the "dontseeit" field.
- func (u *ContactUpsertBulk) SetDontseeit(v int) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetDontseeit(v)
- })
- }
- // AddDontseeit adds v to the "dontseeit" field.
- func (u *ContactUpsertBulk) AddDontseeit(v int) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.AddDontseeit(v)
- })
- }
- // UpdateDontseeit sets the "dontseeit" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateDontseeit() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateDontseeit()
- })
- }
- // SetDontseeme sets the "dontseeme" field.
- func (u *ContactUpsertBulk) SetDontseeme(v int) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetDontseeme(v)
- })
- }
- // AddDontseeme adds v to the "dontseeme" field.
- func (u *ContactUpsertBulk) AddDontseeme(v int) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.AddDontseeme(v)
- })
- }
- // UpdateDontseeme sets the "dontseeme" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateDontseeme() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateDontseeme()
- })
- }
- // SetLag sets the "lag" field.
- func (u *ContactUpsertBulk) SetLag(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetLag(v)
- })
- }
- // UpdateLag sets the "lag" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateLag() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateLag()
- })
- }
- // SetGid sets the "gid" field.
- func (u *ContactUpsertBulk) SetGid(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetGid(v)
- })
- }
- // UpdateGid sets the "gid" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateGid() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateGid()
- })
- }
- // SetGname sets the "gname" field.
- func (u *ContactUpsertBulk) SetGname(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetGname(v)
- })
- }
- // UpdateGname sets the "gname" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateGname() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateGname()
- })
- }
- // SetV3 sets the "v3" field.
- func (u *ContactUpsertBulk) SetV3(v string) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetV3(v)
- })
- }
- // UpdateV3 sets the "v3" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateV3() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateV3()
- })
- }
- // Exec executes the query.
- func (u *ContactUpsertBulk) 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 ContactCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for ContactCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *ContactUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|