12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/agent"
- "wechat-api/ent/server"
- "wechat-api/ent/wx"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // WxCreate is the builder for creating a Wx entity.
- type WxCreate struct {
- config
- mutation *WxMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (wc *WxCreate) SetCreatedAt(t time.Time) *WxCreate {
- wc.mutation.SetCreatedAt(t)
- return wc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (wc *WxCreate) SetNillableCreatedAt(t *time.Time) *WxCreate {
- if t != nil {
- wc.SetCreatedAt(*t)
- }
- return wc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (wc *WxCreate) SetUpdatedAt(t time.Time) *WxCreate {
- wc.mutation.SetUpdatedAt(t)
- return wc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (wc *WxCreate) SetNillableUpdatedAt(t *time.Time) *WxCreate {
- if t != nil {
- wc.SetUpdatedAt(*t)
- }
- return wc
- }
- // SetStatus sets the "status" field.
- func (wc *WxCreate) SetStatus(u uint8) *WxCreate {
- wc.mutation.SetStatus(u)
- return wc
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (wc *WxCreate) SetNillableStatus(u *uint8) *WxCreate {
- if u != nil {
- wc.SetStatus(*u)
- }
- return wc
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (wc *WxCreate) SetDeletedAt(t time.Time) *WxCreate {
- wc.mutation.SetDeletedAt(t)
- return wc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (wc *WxCreate) SetNillableDeletedAt(t *time.Time) *WxCreate {
- if t != nil {
- wc.SetDeletedAt(*t)
- }
- return wc
- }
- // SetServerID sets the "server_id" field.
- func (wc *WxCreate) SetServerID(u uint64) *WxCreate {
- wc.mutation.SetServerID(u)
- return wc
- }
- // SetNillableServerID sets the "server_id" field if the given value is not nil.
- func (wc *WxCreate) SetNillableServerID(u *uint64) *WxCreate {
- if u != nil {
- wc.SetServerID(*u)
- }
- return wc
- }
- // SetPort sets the "port" field.
- func (wc *WxCreate) SetPort(s string) *WxCreate {
- wc.mutation.SetPort(s)
- return wc
- }
- // SetNillablePort sets the "port" field if the given value is not nil.
- func (wc *WxCreate) SetNillablePort(s *string) *WxCreate {
- if s != nil {
- wc.SetPort(*s)
- }
- return wc
- }
- // SetProcessID sets the "process_id" field.
- func (wc *WxCreate) SetProcessID(s string) *WxCreate {
- wc.mutation.SetProcessID(s)
- return wc
- }
- // SetNillableProcessID sets the "process_id" field if the given value is not nil.
- func (wc *WxCreate) SetNillableProcessID(s *string) *WxCreate {
- if s != nil {
- wc.SetProcessID(*s)
- }
- return wc
- }
- // SetCallback sets the "callback" field.
- func (wc *WxCreate) SetCallback(s string) *WxCreate {
- wc.mutation.SetCallback(s)
- return wc
- }
- // SetNillableCallback sets the "callback" field if the given value is not nil.
- func (wc *WxCreate) SetNillableCallback(s *string) *WxCreate {
- if s != nil {
- wc.SetCallback(*s)
- }
- return wc
- }
- // SetWxid sets the "wxid" field.
- func (wc *WxCreate) SetWxid(s string) *WxCreate {
- wc.mutation.SetWxid(s)
- return wc
- }
- // SetNillableWxid sets the "wxid" field if the given value is not nil.
- func (wc *WxCreate) SetNillableWxid(s *string) *WxCreate {
- if s != nil {
- wc.SetWxid(*s)
- }
- return wc
- }
- // SetAccount sets the "account" field.
- func (wc *WxCreate) SetAccount(s string) *WxCreate {
- wc.mutation.SetAccount(s)
- return wc
- }
- // SetNillableAccount sets the "account" field if the given value is not nil.
- func (wc *WxCreate) SetNillableAccount(s *string) *WxCreate {
- if s != nil {
- wc.SetAccount(*s)
- }
- return wc
- }
- // SetNickname sets the "nickname" field.
- func (wc *WxCreate) SetNickname(s string) *WxCreate {
- wc.mutation.SetNickname(s)
- return wc
- }
- // SetNillableNickname sets the "nickname" field if the given value is not nil.
- func (wc *WxCreate) SetNillableNickname(s *string) *WxCreate {
- if s != nil {
- wc.SetNickname(*s)
- }
- return wc
- }
- // SetTel sets the "tel" field.
- func (wc *WxCreate) SetTel(s string) *WxCreate {
- wc.mutation.SetTel(s)
- return wc
- }
- // SetNillableTel sets the "tel" field if the given value is not nil.
- func (wc *WxCreate) SetNillableTel(s *string) *WxCreate {
- if s != nil {
- wc.SetTel(*s)
- }
- return wc
- }
- // SetHeadBig sets the "head_big" field.
- func (wc *WxCreate) SetHeadBig(s string) *WxCreate {
- wc.mutation.SetHeadBig(s)
- return wc
- }
- // SetNillableHeadBig sets the "head_big" field if the given value is not nil.
- func (wc *WxCreate) SetNillableHeadBig(s *string) *WxCreate {
- if s != nil {
- wc.SetHeadBig(*s)
- }
- return wc
- }
- // SetOrganizationID sets the "organization_id" field.
- func (wc *WxCreate) SetOrganizationID(u uint64) *WxCreate {
- wc.mutation.SetOrganizationID(u)
- return wc
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (wc *WxCreate) SetNillableOrganizationID(u *uint64) *WxCreate {
- if u != nil {
- wc.SetOrganizationID(*u)
- }
- return wc
- }
- // SetAgentID sets the "agent_id" field.
- func (wc *WxCreate) SetAgentID(u uint64) *WxCreate {
- wc.mutation.SetAgentID(u)
- return wc
- }
- // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
- func (wc *WxCreate) SetNillableAgentID(u *uint64) *WxCreate {
- if u != nil {
- wc.SetAgentID(*u)
- }
- return wc
- }
- // SetAPIBase sets the "api_base" field.
- func (wc *WxCreate) SetAPIBase(s string) *WxCreate {
- wc.mutation.SetAPIBase(s)
- return wc
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (wc *WxCreate) SetNillableAPIBase(s *string) *WxCreate {
- if s != nil {
- wc.SetAPIBase(*s)
- }
- return wc
- }
- // SetAPIKey sets the "api_key" field.
- func (wc *WxCreate) SetAPIKey(s string) *WxCreate {
- wc.mutation.SetAPIKey(s)
- return wc
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (wc *WxCreate) SetNillableAPIKey(s *string) *WxCreate {
- if s != nil {
- wc.SetAPIKey(*s)
- }
- return wc
- }
- // SetID sets the "id" field.
- func (wc *WxCreate) SetID(u uint64) *WxCreate {
- wc.mutation.SetID(u)
- return wc
- }
- // SetServer sets the "server" edge to the Server entity.
- func (wc *WxCreate) SetServer(s *Server) *WxCreate {
- return wc.SetServerID(s.ID)
- }
- // SetAgent sets the "agent" edge to the Agent entity.
- func (wc *WxCreate) SetAgent(a *Agent) *WxCreate {
- return wc.SetAgentID(a.ID)
- }
- // Mutation returns the WxMutation object of the builder.
- func (wc *WxCreate) Mutation() *WxMutation {
- return wc.mutation
- }
- // Save creates the Wx in the database.
- func (wc *WxCreate) Save(ctx context.Context) (*Wx, error) {
- if err := wc.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, wc.sqlSave, wc.mutation, wc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (wc *WxCreate) SaveX(ctx context.Context) *Wx {
- v, err := wc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (wc *WxCreate) Exec(ctx context.Context) error {
- _, err := wc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wc *WxCreate) ExecX(ctx context.Context) {
- if err := wc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (wc *WxCreate) defaults() error {
- if _, ok := wc.mutation.CreatedAt(); !ok {
- if wx.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized wx.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := wx.DefaultCreatedAt()
- wc.mutation.SetCreatedAt(v)
- }
- if _, ok := wc.mutation.UpdatedAt(); !ok {
- if wx.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized wx.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := wx.DefaultUpdatedAt()
- wc.mutation.SetUpdatedAt(v)
- }
- if _, ok := wc.mutation.Status(); !ok {
- v := wx.DefaultStatus
- wc.mutation.SetStatus(v)
- }
- if _, ok := wc.mutation.ServerID(); !ok {
- v := wx.DefaultServerID
- wc.mutation.SetServerID(v)
- }
- if _, ok := wc.mutation.Port(); !ok {
- v := wx.DefaultPort
- wc.mutation.SetPort(v)
- }
- if _, ok := wc.mutation.ProcessID(); !ok {
- v := wx.DefaultProcessID
- wc.mutation.SetProcessID(v)
- }
- if _, ok := wc.mutation.Callback(); !ok {
- v := wx.DefaultCallback
- wc.mutation.SetCallback(v)
- }
- if _, ok := wc.mutation.Wxid(); !ok {
- v := wx.DefaultWxid
- wc.mutation.SetWxid(v)
- }
- if _, ok := wc.mutation.Account(); !ok {
- v := wx.DefaultAccount
- wc.mutation.SetAccount(v)
- }
- if _, ok := wc.mutation.Nickname(); !ok {
- v := wx.DefaultNickname
- wc.mutation.SetNickname(v)
- }
- if _, ok := wc.mutation.Tel(); !ok {
- v := wx.DefaultTel
- wc.mutation.SetTel(v)
- }
- if _, ok := wc.mutation.HeadBig(); !ok {
- v := wx.DefaultHeadBig
- wc.mutation.SetHeadBig(v)
- }
- if _, ok := wc.mutation.OrganizationID(); !ok {
- v := wx.DefaultOrganizationID
- wc.mutation.SetOrganizationID(v)
- }
- if _, ok := wc.mutation.AgentID(); !ok {
- v := wx.DefaultAgentID
- wc.mutation.SetAgentID(v)
- }
- if _, ok := wc.mutation.APIBase(); !ok {
- v := wx.DefaultAPIBase
- wc.mutation.SetAPIBase(v)
- }
- if _, ok := wc.mutation.APIKey(); !ok {
- v := wx.DefaultAPIKey
- wc.mutation.SetAPIKey(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (wc *WxCreate) check() error {
- if _, ok := wc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Wx.created_at"`)}
- }
- if _, ok := wc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Wx.updated_at"`)}
- }
- if _, ok := wc.mutation.Port(); !ok {
- return &ValidationError{Name: "port", err: errors.New(`ent: missing required field "Wx.port"`)}
- }
- if _, ok := wc.mutation.ProcessID(); !ok {
- return &ValidationError{Name: "process_id", err: errors.New(`ent: missing required field "Wx.process_id"`)}
- }
- if _, ok := wc.mutation.Callback(); !ok {
- return &ValidationError{Name: "callback", err: errors.New(`ent: missing required field "Wx.callback"`)}
- }
- if _, ok := wc.mutation.Wxid(); !ok {
- return &ValidationError{Name: "wxid", err: errors.New(`ent: missing required field "Wx.wxid"`)}
- }
- if _, ok := wc.mutation.Account(); !ok {
- return &ValidationError{Name: "account", err: errors.New(`ent: missing required field "Wx.account"`)}
- }
- if _, ok := wc.mutation.Nickname(); !ok {
- return &ValidationError{Name: "nickname", err: errors.New(`ent: missing required field "Wx.nickname"`)}
- }
- if _, ok := wc.mutation.Tel(); !ok {
- return &ValidationError{Name: "tel", err: errors.New(`ent: missing required field "Wx.tel"`)}
- }
- if _, ok := wc.mutation.HeadBig(); !ok {
- return &ValidationError{Name: "head_big", err: errors.New(`ent: missing required field "Wx.head_big"`)}
- }
- if _, ok := wc.mutation.AgentID(); !ok {
- return &ValidationError{Name: "agent_id", err: errors.New(`ent: missing required field "Wx.agent_id"`)}
- }
- if _, ok := wc.mutation.AgentID(); !ok {
- return &ValidationError{Name: "agent", err: errors.New(`ent: missing required edge "Wx.agent"`)}
- }
- return nil
- }
- func (wc *WxCreate) sqlSave(ctx context.Context) (*Wx, error) {
- if err := wc.check(); err != nil {
- return nil, err
- }
- _node, _spec := wc.createSpec()
- if err := sqlgraph.CreateNode(ctx, wc.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)
- }
- wc.mutation.id = &_node.ID
- wc.mutation.done = true
- return _node, nil
- }
- func (wc *WxCreate) createSpec() (*Wx, *sqlgraph.CreateSpec) {
- var (
- _node = &Wx{config: wc.config}
- _spec = sqlgraph.NewCreateSpec(wx.Table, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = wc.conflict
- if id, ok := wc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := wc.mutation.CreatedAt(); ok {
- _spec.SetField(wx.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := wc.mutation.UpdatedAt(); ok {
- _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := wc.mutation.Status(); ok {
- _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
- _node.Status = value
- }
- if value, ok := wc.mutation.DeletedAt(); ok {
- _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if value, ok := wc.mutation.Port(); ok {
- _spec.SetField(wx.FieldPort, field.TypeString, value)
- _node.Port = value
- }
- if value, ok := wc.mutation.ProcessID(); ok {
- _spec.SetField(wx.FieldProcessID, field.TypeString, value)
- _node.ProcessID = value
- }
- if value, ok := wc.mutation.Callback(); ok {
- _spec.SetField(wx.FieldCallback, field.TypeString, value)
- _node.Callback = value
- }
- if value, ok := wc.mutation.Wxid(); ok {
- _spec.SetField(wx.FieldWxid, field.TypeString, value)
- _node.Wxid = value
- }
- if value, ok := wc.mutation.Account(); ok {
- _spec.SetField(wx.FieldAccount, field.TypeString, value)
- _node.Account = value
- }
- if value, ok := wc.mutation.Nickname(); ok {
- _spec.SetField(wx.FieldNickname, field.TypeString, value)
- _node.Nickname = value
- }
- if value, ok := wc.mutation.Tel(); ok {
- _spec.SetField(wx.FieldTel, field.TypeString, value)
- _node.Tel = value
- }
- if value, ok := wc.mutation.HeadBig(); ok {
- _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
- _node.HeadBig = value
- }
- if value, ok := wc.mutation.OrganizationID(); ok {
- _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- if value, ok := wc.mutation.APIBase(); ok {
- _spec.SetField(wx.FieldAPIBase, field.TypeString, value)
- _node.APIBase = value
- }
- if value, ok := wc.mutation.APIKey(); ok {
- _spec.SetField(wx.FieldAPIKey, field.TypeString, value)
- _node.APIKey = value
- }
- if nodes := wc.mutation.ServerIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: wx.ServerTable,
- Columns: []string{wx.ServerColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _node.ServerID = nodes[0]
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := wc.mutation.AgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: wx.AgentTable,
- Columns: []string{wx.AgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _node.AgentID = nodes[0]
- _spec.Edges = append(_spec.Edges, edge)
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Wx.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.WxUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (wc *WxCreate) OnConflict(opts ...sql.ConflictOption) *WxUpsertOne {
- wc.conflict = opts
- return &WxUpsertOne{
- create: wc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Wx.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (wc *WxCreate) OnConflictColumns(columns ...string) *WxUpsertOne {
- wc.conflict = append(wc.conflict, sql.ConflictColumns(columns...))
- return &WxUpsertOne{
- create: wc,
- }
- }
- type (
- // WxUpsertOne is the builder for "upsert"-ing
- // one Wx node.
- WxUpsertOne struct {
- create *WxCreate
- }
- // WxUpsert is the "OnConflict" setter.
- WxUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WxUpsert) SetUpdatedAt(v time.Time) *WxUpsert {
- u.Set(wx.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WxUpsert) UpdateUpdatedAt() *WxUpsert {
- u.SetExcluded(wx.FieldUpdatedAt)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *WxUpsert) SetStatus(v uint8) *WxUpsert {
- u.Set(wx.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *WxUpsert) UpdateStatus() *WxUpsert {
- u.SetExcluded(wx.FieldStatus)
- return u
- }
- // AddStatus adds v to the "status" field.
- func (u *WxUpsert) AddStatus(v uint8) *WxUpsert {
- u.Add(wx.FieldStatus, v)
- return u
- }
- // ClearStatus clears the value of the "status" field.
- func (u *WxUpsert) ClearStatus() *WxUpsert {
- u.SetNull(wx.FieldStatus)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WxUpsert) SetDeletedAt(v time.Time) *WxUpsert {
- u.Set(wx.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WxUpsert) UpdateDeletedAt() *WxUpsert {
- u.SetExcluded(wx.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WxUpsert) ClearDeletedAt() *WxUpsert {
- u.SetNull(wx.FieldDeletedAt)
- return u
- }
- // SetServerID sets the "server_id" field.
- func (u *WxUpsert) SetServerID(v uint64) *WxUpsert {
- u.Set(wx.FieldServerID, v)
- return u
- }
- // UpdateServerID sets the "server_id" field to the value that was provided on create.
- func (u *WxUpsert) UpdateServerID() *WxUpsert {
- u.SetExcluded(wx.FieldServerID)
- return u
- }
- // ClearServerID clears the value of the "server_id" field.
- func (u *WxUpsert) ClearServerID() *WxUpsert {
- u.SetNull(wx.FieldServerID)
- return u
- }
- // SetPort sets the "port" field.
- func (u *WxUpsert) SetPort(v string) *WxUpsert {
- u.Set(wx.FieldPort, v)
- return u
- }
- // UpdatePort sets the "port" field to the value that was provided on create.
- func (u *WxUpsert) UpdatePort() *WxUpsert {
- u.SetExcluded(wx.FieldPort)
- return u
- }
- // SetProcessID sets the "process_id" field.
- func (u *WxUpsert) SetProcessID(v string) *WxUpsert {
- u.Set(wx.FieldProcessID, v)
- return u
- }
- // UpdateProcessID sets the "process_id" field to the value that was provided on create.
- func (u *WxUpsert) UpdateProcessID() *WxUpsert {
- u.SetExcluded(wx.FieldProcessID)
- return u
- }
- // SetCallback sets the "callback" field.
- func (u *WxUpsert) SetCallback(v string) *WxUpsert {
- u.Set(wx.FieldCallback, v)
- return u
- }
- // UpdateCallback sets the "callback" field to the value that was provided on create.
- func (u *WxUpsert) UpdateCallback() *WxUpsert {
- u.SetExcluded(wx.FieldCallback)
- return u
- }
- // SetWxid sets the "wxid" field.
- func (u *WxUpsert) SetWxid(v string) *WxUpsert {
- u.Set(wx.FieldWxid, v)
- return u
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *WxUpsert) UpdateWxid() *WxUpsert {
- u.SetExcluded(wx.FieldWxid)
- return u
- }
- // SetAccount sets the "account" field.
- func (u *WxUpsert) SetAccount(v string) *WxUpsert {
- u.Set(wx.FieldAccount, v)
- return u
- }
- // UpdateAccount sets the "account" field to the value that was provided on create.
- func (u *WxUpsert) UpdateAccount() *WxUpsert {
- u.SetExcluded(wx.FieldAccount)
- return u
- }
- // SetNickname sets the "nickname" field.
- func (u *WxUpsert) SetNickname(v string) *WxUpsert {
- u.Set(wx.FieldNickname, v)
- return u
- }
- // UpdateNickname sets the "nickname" field to the value that was provided on create.
- func (u *WxUpsert) UpdateNickname() *WxUpsert {
- u.SetExcluded(wx.FieldNickname)
- return u
- }
- // SetTel sets the "tel" field.
- func (u *WxUpsert) SetTel(v string) *WxUpsert {
- u.Set(wx.FieldTel, v)
- return u
- }
- // UpdateTel sets the "tel" field to the value that was provided on create.
- func (u *WxUpsert) UpdateTel() *WxUpsert {
- u.SetExcluded(wx.FieldTel)
- return u
- }
- // SetHeadBig sets the "head_big" field.
- func (u *WxUpsert) SetHeadBig(v string) *WxUpsert {
- u.Set(wx.FieldHeadBig, v)
- return u
- }
- // UpdateHeadBig sets the "head_big" field to the value that was provided on create.
- func (u *WxUpsert) UpdateHeadBig() *WxUpsert {
- u.SetExcluded(wx.FieldHeadBig)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *WxUpsert) SetOrganizationID(v uint64) *WxUpsert {
- u.Set(wx.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *WxUpsert) UpdateOrganizationID() *WxUpsert {
- u.SetExcluded(wx.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *WxUpsert) AddOrganizationID(v uint64) *WxUpsert {
- u.Add(wx.FieldOrganizationID, v)
- return u
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *WxUpsert) ClearOrganizationID() *WxUpsert {
- u.SetNull(wx.FieldOrganizationID)
- return u
- }
- // SetAgentID sets the "agent_id" field.
- func (u *WxUpsert) SetAgentID(v uint64) *WxUpsert {
- u.Set(wx.FieldAgentID, v)
- return u
- }
- // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
- func (u *WxUpsert) UpdateAgentID() *WxUpsert {
- u.SetExcluded(wx.FieldAgentID)
- return u
- }
- // SetAPIBase sets the "api_base" field.
- func (u *WxUpsert) SetAPIBase(v string) *WxUpsert {
- u.Set(wx.FieldAPIBase, v)
- return u
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *WxUpsert) UpdateAPIBase() *WxUpsert {
- u.SetExcluded(wx.FieldAPIBase)
- return u
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *WxUpsert) ClearAPIBase() *WxUpsert {
- u.SetNull(wx.FieldAPIBase)
- return u
- }
- // SetAPIKey sets the "api_key" field.
- func (u *WxUpsert) SetAPIKey(v string) *WxUpsert {
- u.Set(wx.FieldAPIKey, v)
- return u
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *WxUpsert) UpdateAPIKey() *WxUpsert {
- u.SetExcluded(wx.FieldAPIKey)
- return u
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *WxUpsert) ClearAPIKey() *WxUpsert {
- u.SetNull(wx.FieldAPIKey)
- 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.Wx.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(wx.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *WxUpsertOne) UpdateNewValues() *WxUpsertOne {
- 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(wx.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(wx.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Wx.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *WxUpsertOne) Ignore() *WxUpsertOne {
- 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 *WxUpsertOne) DoNothing() *WxUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the WxCreate.OnConflict
- // documentation for more info.
- func (u *WxUpsertOne) Update(set func(*WxUpsert)) *WxUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&WxUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WxUpsertOne) SetUpdatedAt(v time.Time) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateUpdatedAt() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *WxUpsertOne) SetStatus(v uint8) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *WxUpsertOne) AddStatus(v uint8) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateStatus() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *WxUpsertOne) ClearStatus() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.ClearStatus()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WxUpsertOne) SetDeletedAt(v time.Time) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateDeletedAt() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WxUpsertOne) ClearDeletedAt() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetServerID sets the "server_id" field.
- func (u *WxUpsertOne) SetServerID(v uint64) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetServerID(v)
- })
- }
- // UpdateServerID sets the "server_id" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateServerID() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateServerID()
- })
- }
- // ClearServerID clears the value of the "server_id" field.
- func (u *WxUpsertOne) ClearServerID() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.ClearServerID()
- })
- }
- // SetPort sets the "port" field.
- func (u *WxUpsertOne) SetPort(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetPort(v)
- })
- }
- // UpdatePort sets the "port" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdatePort() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdatePort()
- })
- }
- // SetProcessID sets the "process_id" field.
- func (u *WxUpsertOne) SetProcessID(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetProcessID(v)
- })
- }
- // UpdateProcessID sets the "process_id" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateProcessID() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateProcessID()
- })
- }
- // SetCallback sets the "callback" field.
- func (u *WxUpsertOne) SetCallback(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetCallback(v)
- })
- }
- // UpdateCallback sets the "callback" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateCallback() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateCallback()
- })
- }
- // SetWxid sets the "wxid" field.
- func (u *WxUpsertOne) SetWxid(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetWxid(v)
- })
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateWxid() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateWxid()
- })
- }
- // SetAccount sets the "account" field.
- func (u *WxUpsertOne) SetAccount(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetAccount(v)
- })
- }
- // UpdateAccount sets the "account" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateAccount() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateAccount()
- })
- }
- // SetNickname sets the "nickname" field.
- func (u *WxUpsertOne) SetNickname(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetNickname(v)
- })
- }
- // UpdateNickname sets the "nickname" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateNickname() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateNickname()
- })
- }
- // SetTel sets the "tel" field.
- func (u *WxUpsertOne) SetTel(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetTel(v)
- })
- }
- // UpdateTel sets the "tel" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateTel() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateTel()
- })
- }
- // SetHeadBig sets the "head_big" field.
- func (u *WxUpsertOne) SetHeadBig(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetHeadBig(v)
- })
- }
- // UpdateHeadBig sets the "head_big" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateHeadBig() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateHeadBig()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *WxUpsertOne) SetOrganizationID(v uint64) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *WxUpsertOne) AddOrganizationID(v uint64) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateOrganizationID() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *WxUpsertOne) ClearOrganizationID() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.ClearOrganizationID()
- })
- }
- // SetAgentID sets the "agent_id" field.
- func (u *WxUpsertOne) SetAgentID(v uint64) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetAgentID(v)
- })
- }
- // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateAgentID() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateAgentID()
- })
- }
- // SetAPIBase sets the "api_base" field.
- func (u *WxUpsertOne) SetAPIBase(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetAPIBase(v)
- })
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateAPIBase() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateAPIBase()
- })
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *WxUpsertOne) ClearAPIBase() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.ClearAPIBase()
- })
- }
- // SetAPIKey sets the "api_key" field.
- func (u *WxUpsertOne) SetAPIKey(v string) *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.SetAPIKey(v)
- })
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *WxUpsertOne) UpdateAPIKey() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.UpdateAPIKey()
- })
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *WxUpsertOne) ClearAPIKey() *WxUpsertOne {
- return u.Update(func(s *WxUpsert) {
- s.ClearAPIKey()
- })
- }
- // Exec executes the query.
- func (u *WxUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for WxCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *WxUpsertOne) 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 *WxUpsertOne) 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 *WxUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // WxCreateBulk is the builder for creating many Wx entities in bulk.
- type WxCreateBulk struct {
- config
- err error
- builders []*WxCreate
- conflict []sql.ConflictOption
- }
- // Save creates the Wx entities in the database.
- func (wcb *WxCreateBulk) Save(ctx context.Context) ([]*Wx, error) {
- if wcb.err != nil {
- return nil, wcb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(wcb.builders))
- nodes := make([]*Wx, len(wcb.builders))
- mutators := make([]Mutator, len(wcb.builders))
- for i := range wcb.builders {
- func(i int, root context.Context) {
- builder := wcb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*WxMutation)
- 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, wcb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = wcb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, wcb.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, wcb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (wcb *WxCreateBulk) SaveX(ctx context.Context) []*Wx {
- v, err := wcb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (wcb *WxCreateBulk) Exec(ctx context.Context) error {
- _, err := wcb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wcb *WxCreateBulk) ExecX(ctx context.Context) {
- if err := wcb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Wx.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.WxUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (wcb *WxCreateBulk) OnConflict(opts ...sql.ConflictOption) *WxUpsertBulk {
- wcb.conflict = opts
- return &WxUpsertBulk{
- create: wcb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Wx.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (wcb *WxCreateBulk) OnConflictColumns(columns ...string) *WxUpsertBulk {
- wcb.conflict = append(wcb.conflict, sql.ConflictColumns(columns...))
- return &WxUpsertBulk{
- create: wcb,
- }
- }
- // WxUpsertBulk is the builder for "upsert"-ing
- // a bulk of Wx nodes.
- type WxUpsertBulk struct {
- create *WxCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.Wx.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(wx.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *WxUpsertBulk) UpdateNewValues() *WxUpsertBulk {
- 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(wx.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(wx.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Wx.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *WxUpsertBulk) Ignore() *WxUpsertBulk {
- 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 *WxUpsertBulk) DoNothing() *WxUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the WxCreateBulk.OnConflict
- // documentation for more info.
- func (u *WxUpsertBulk) Update(set func(*WxUpsert)) *WxUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&WxUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WxUpsertBulk) SetUpdatedAt(v time.Time) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateUpdatedAt() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *WxUpsertBulk) SetStatus(v uint8) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *WxUpsertBulk) AddStatus(v uint8) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateStatus() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *WxUpsertBulk) ClearStatus() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.ClearStatus()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WxUpsertBulk) SetDeletedAt(v time.Time) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateDeletedAt() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WxUpsertBulk) ClearDeletedAt() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetServerID sets the "server_id" field.
- func (u *WxUpsertBulk) SetServerID(v uint64) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetServerID(v)
- })
- }
- // UpdateServerID sets the "server_id" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateServerID() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateServerID()
- })
- }
- // ClearServerID clears the value of the "server_id" field.
- func (u *WxUpsertBulk) ClearServerID() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.ClearServerID()
- })
- }
- // SetPort sets the "port" field.
- func (u *WxUpsertBulk) SetPort(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetPort(v)
- })
- }
- // UpdatePort sets the "port" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdatePort() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdatePort()
- })
- }
- // SetProcessID sets the "process_id" field.
- func (u *WxUpsertBulk) SetProcessID(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetProcessID(v)
- })
- }
- // UpdateProcessID sets the "process_id" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateProcessID() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateProcessID()
- })
- }
- // SetCallback sets the "callback" field.
- func (u *WxUpsertBulk) SetCallback(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetCallback(v)
- })
- }
- // UpdateCallback sets the "callback" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateCallback() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateCallback()
- })
- }
- // SetWxid sets the "wxid" field.
- func (u *WxUpsertBulk) SetWxid(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetWxid(v)
- })
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateWxid() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateWxid()
- })
- }
- // SetAccount sets the "account" field.
- func (u *WxUpsertBulk) SetAccount(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetAccount(v)
- })
- }
- // UpdateAccount sets the "account" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateAccount() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateAccount()
- })
- }
- // SetNickname sets the "nickname" field.
- func (u *WxUpsertBulk) SetNickname(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetNickname(v)
- })
- }
- // UpdateNickname sets the "nickname" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateNickname() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateNickname()
- })
- }
- // SetTel sets the "tel" field.
- func (u *WxUpsertBulk) SetTel(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetTel(v)
- })
- }
- // UpdateTel sets the "tel" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateTel() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateTel()
- })
- }
- // SetHeadBig sets the "head_big" field.
- func (u *WxUpsertBulk) SetHeadBig(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetHeadBig(v)
- })
- }
- // UpdateHeadBig sets the "head_big" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateHeadBig() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateHeadBig()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *WxUpsertBulk) SetOrganizationID(v uint64) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *WxUpsertBulk) AddOrganizationID(v uint64) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateOrganizationID() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *WxUpsertBulk) ClearOrganizationID() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.ClearOrganizationID()
- })
- }
- // SetAgentID sets the "agent_id" field.
- func (u *WxUpsertBulk) SetAgentID(v uint64) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetAgentID(v)
- })
- }
- // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateAgentID() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateAgentID()
- })
- }
- // SetAPIBase sets the "api_base" field.
- func (u *WxUpsertBulk) SetAPIBase(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetAPIBase(v)
- })
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateAPIBase() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateAPIBase()
- })
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *WxUpsertBulk) ClearAPIBase() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.ClearAPIBase()
- })
- }
- // SetAPIKey sets the "api_key" field.
- func (u *WxUpsertBulk) SetAPIKey(v string) *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.SetAPIKey(v)
- })
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *WxUpsertBulk) UpdateAPIKey() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.UpdateAPIKey()
- })
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *WxUpsertBulk) ClearAPIKey() *WxUpsertBulk {
- return u.Update(func(s *WxUpsert) {
- s.ClearAPIKey()
- })
- }
- // Exec executes the query.
- func (u *WxUpsertBulk) 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 WxCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for WxCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *WxUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|