1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/contact"
- "wechat-api/ent/labelrelationship"
- "wechat-api/ent/messagerecords"
- "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
- }
- // SetOrganizationID sets the "organization_id" field.
- func (cc *ContactCreate) SetOrganizationID(u uint64) *ContactCreate {
- cc.mutation.SetOrganizationID(u)
- return cc
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (cc *ContactCreate) SetNillableOrganizationID(u *uint64) *ContactCreate {
- if u != nil {
- cc.SetOrganizationID(*u)
- }
- return cc
- }
- // SetID sets the "id" field.
- func (cc *ContactCreate) SetID(u uint64) *ContactCreate {
- cc.mutation.SetID(u)
- return cc
- }
- // AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by IDs.
- func (cc *ContactCreate) AddContactRelationshipIDs(ids ...uint64) *ContactCreate {
- cc.mutation.AddContactRelationshipIDs(ids...)
- return cc
- }
- // AddContactRelationships adds the "contact_relationships" edges to the LabelRelationship entity.
- func (cc *ContactCreate) AddContactRelationships(l ...*LabelRelationship) *ContactCreate {
- ids := make([]uint64, len(l))
- for i := range l {
- ids[i] = l[i].ID
- }
- return cc.AddContactRelationshipIDs(ids...)
- }
- // AddContactMessageIDs adds the "contact_messages" edge to the MessageRecords entity by IDs.
- func (cc *ContactCreate) AddContactMessageIDs(ids ...uint64) *ContactCreate {
- cc.mutation.AddContactMessageIDs(ids...)
- return cc
- }
- // AddContactMessages adds the "contact_messages" edges to the MessageRecords entity.
- func (cc *ContactCreate) AddContactMessages(m ...*MessageRecords) *ContactCreate {
- ids := make([]uint64, len(m))
- for i := range m {
- ids[i] = m[i].ID
- }
- return cc.AddContactMessageIDs(ids...)
- }
- // 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)
- }
- if _, ok := cc.mutation.OrganizationID(); !ok {
- v := contact.DefaultOrganizationID
- cc.mutation.SetOrganizationID(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
- }
- if value, ok := cc.mutation.OrganizationID(); ok {
- _spec.SetField(contact.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- if nodes := cc.mutation.ContactRelationshipsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: contact.ContactRelationshipsTable,
- Columns: []string{contact.ContactRelationshipsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := cc.mutation.ContactMessagesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: contact.ContactMessagesTable,
- Columns: []string{contact.ContactMessagesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges = append(_spec.Edges, edge)
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.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
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *ContactUpsert) SetOrganizationID(v uint64) *ContactUpsert {
- u.Set(contact.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *ContactUpsert) UpdateOrganizationID() *ContactUpsert {
- u.SetExcluded(contact.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *ContactUpsert) AddOrganizationID(v uint64) *ContactUpsert {
- u.Add(contact.FieldOrganizationID, v)
- return u
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *ContactUpsert) ClearOrganizationID() *ContactUpsert {
- u.SetNull(contact.FieldOrganizationID)
- 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()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *ContactUpsertOne) SetOrganizationID(v uint64) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *ContactUpsertOne) AddOrganizationID(v uint64) *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *ContactUpsertOne) UpdateOrganizationID() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *ContactUpsertOne) ClearOrganizationID() *ContactUpsertOne {
- return u.Update(func(s *ContactUpsert) {
- s.ClearOrganizationID()
- })
- }
- // 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()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *ContactUpsertBulk) SetOrganizationID(v uint64) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *ContactUpsertBulk) AddOrganizationID(v uint64) *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *ContactUpsertBulk) UpdateOrganizationID() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *ContactUpsertBulk) ClearOrganizationID() *ContactUpsertBulk {
- return u.Update(func(s *ContactUpsert) {
- s.ClearOrganizationID()
- })
- }
- // 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)
- }
- }
|