123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/agent"
- "wechat-api/ent/predicate"
- "wechat-api/ent/server"
- "wechat-api/ent/wx"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/dialect/sql/sqljson"
- "entgo.io/ent/schema/field"
- )
- // WxUpdate is the builder for updating Wx entities.
- type WxUpdate struct {
- config
- hooks []Hook
- mutation *WxMutation
- }
- // Where appends a list predicates to the WxUpdate builder.
- func (wu *WxUpdate) Where(ps ...predicate.Wx) *WxUpdate {
- wu.mutation.Where(ps...)
- return wu
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (wu *WxUpdate) SetUpdatedAt(t time.Time) *WxUpdate {
- wu.mutation.SetUpdatedAt(t)
- return wu
- }
- // SetStatus sets the "status" field.
- func (wu *WxUpdate) SetStatus(u uint8) *WxUpdate {
- wu.mutation.ResetStatus()
- wu.mutation.SetStatus(u)
- return wu
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableStatus(u *uint8) *WxUpdate {
- if u != nil {
- wu.SetStatus(*u)
- }
- return wu
- }
- // AddStatus adds u to the "status" field.
- func (wu *WxUpdate) AddStatus(u int8) *WxUpdate {
- wu.mutation.AddStatus(u)
- return wu
- }
- // ClearStatus clears the value of the "status" field.
- func (wu *WxUpdate) ClearStatus() *WxUpdate {
- wu.mutation.ClearStatus()
- return wu
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (wu *WxUpdate) SetDeletedAt(t time.Time) *WxUpdate {
- wu.mutation.SetDeletedAt(t)
- return wu
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableDeletedAt(t *time.Time) *WxUpdate {
- if t != nil {
- wu.SetDeletedAt(*t)
- }
- return wu
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (wu *WxUpdate) ClearDeletedAt() *WxUpdate {
- wu.mutation.ClearDeletedAt()
- return wu
- }
- // SetServerID sets the "server_id" field.
- func (wu *WxUpdate) SetServerID(u uint64) *WxUpdate {
- wu.mutation.SetServerID(u)
- return wu
- }
- // SetNillableServerID sets the "server_id" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableServerID(u *uint64) *WxUpdate {
- if u != nil {
- wu.SetServerID(*u)
- }
- return wu
- }
- // ClearServerID clears the value of the "server_id" field.
- func (wu *WxUpdate) ClearServerID() *WxUpdate {
- wu.mutation.ClearServerID()
- return wu
- }
- // SetPort sets the "port" field.
- func (wu *WxUpdate) SetPort(s string) *WxUpdate {
- wu.mutation.SetPort(s)
- return wu
- }
- // SetNillablePort sets the "port" field if the given value is not nil.
- func (wu *WxUpdate) SetNillablePort(s *string) *WxUpdate {
- if s != nil {
- wu.SetPort(*s)
- }
- return wu
- }
- // SetProcessID sets the "process_id" field.
- func (wu *WxUpdate) SetProcessID(s string) *WxUpdate {
- wu.mutation.SetProcessID(s)
- return wu
- }
- // SetNillableProcessID sets the "process_id" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableProcessID(s *string) *WxUpdate {
- if s != nil {
- wu.SetProcessID(*s)
- }
- return wu
- }
- // SetCallback sets the "callback" field.
- func (wu *WxUpdate) SetCallback(s string) *WxUpdate {
- wu.mutation.SetCallback(s)
- return wu
- }
- // SetNillableCallback sets the "callback" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableCallback(s *string) *WxUpdate {
- if s != nil {
- wu.SetCallback(*s)
- }
- return wu
- }
- // SetWxid sets the "wxid" field.
- func (wu *WxUpdate) SetWxid(s string) *WxUpdate {
- wu.mutation.SetWxid(s)
- return wu
- }
- // SetNillableWxid sets the "wxid" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableWxid(s *string) *WxUpdate {
- if s != nil {
- wu.SetWxid(*s)
- }
- return wu
- }
- // SetAccount sets the "account" field.
- func (wu *WxUpdate) SetAccount(s string) *WxUpdate {
- wu.mutation.SetAccount(s)
- return wu
- }
- // SetNillableAccount sets the "account" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableAccount(s *string) *WxUpdate {
- if s != nil {
- wu.SetAccount(*s)
- }
- return wu
- }
- // SetNickname sets the "nickname" field.
- func (wu *WxUpdate) SetNickname(s string) *WxUpdate {
- wu.mutation.SetNickname(s)
- return wu
- }
- // SetNillableNickname sets the "nickname" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableNickname(s *string) *WxUpdate {
- if s != nil {
- wu.SetNickname(*s)
- }
- return wu
- }
- // SetTel sets the "tel" field.
- func (wu *WxUpdate) SetTel(s string) *WxUpdate {
- wu.mutation.SetTel(s)
- return wu
- }
- // SetNillableTel sets the "tel" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableTel(s *string) *WxUpdate {
- if s != nil {
- wu.SetTel(*s)
- }
- return wu
- }
- // SetHeadBig sets the "head_big" field.
- func (wu *WxUpdate) SetHeadBig(s string) *WxUpdate {
- wu.mutation.SetHeadBig(s)
- return wu
- }
- // SetNillableHeadBig sets the "head_big" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableHeadBig(s *string) *WxUpdate {
- if s != nil {
- wu.SetHeadBig(*s)
- }
- return wu
- }
- // SetOrganizationID sets the "organization_id" field.
- func (wu *WxUpdate) SetOrganizationID(u uint64) *WxUpdate {
- wu.mutation.ResetOrganizationID()
- wu.mutation.SetOrganizationID(u)
- return wu
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableOrganizationID(u *uint64) *WxUpdate {
- if u != nil {
- wu.SetOrganizationID(*u)
- }
- return wu
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (wu *WxUpdate) AddOrganizationID(u int64) *WxUpdate {
- wu.mutation.AddOrganizationID(u)
- return wu
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (wu *WxUpdate) ClearOrganizationID() *WxUpdate {
- wu.mutation.ClearOrganizationID()
- return wu
- }
- // SetAgentID sets the "agent_id" field.
- func (wu *WxUpdate) SetAgentID(u uint64) *WxUpdate {
- wu.mutation.SetAgentID(u)
- return wu
- }
- // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableAgentID(u *uint64) *WxUpdate {
- if u != nil {
- wu.SetAgentID(*u)
- }
- return wu
- }
- // SetAPIBase sets the "api_base" field.
- func (wu *WxUpdate) SetAPIBase(s string) *WxUpdate {
- wu.mutation.SetAPIBase(s)
- return wu
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableAPIBase(s *string) *WxUpdate {
- if s != nil {
- wu.SetAPIBase(*s)
- }
- return wu
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (wu *WxUpdate) ClearAPIBase() *WxUpdate {
- wu.mutation.ClearAPIBase()
- return wu
- }
- // SetAPIKey sets the "api_key" field.
- func (wu *WxUpdate) SetAPIKey(s string) *WxUpdate {
- wu.mutation.SetAPIKey(s)
- return wu
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (wu *WxUpdate) SetNillableAPIKey(s *string) *WxUpdate {
- if s != nil {
- wu.SetAPIKey(*s)
- }
- return wu
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (wu *WxUpdate) ClearAPIKey() *WxUpdate {
- wu.mutation.ClearAPIKey()
- return wu
- }
- // SetAllowList sets the "allow_list" field.
- func (wu *WxUpdate) SetAllowList(s []string) *WxUpdate {
- wu.mutation.SetAllowList(s)
- return wu
- }
- // AppendAllowList appends s to the "allow_list" field.
- func (wu *WxUpdate) AppendAllowList(s []string) *WxUpdate {
- wu.mutation.AppendAllowList(s)
- return wu
- }
- // SetGroupAllowList sets the "group_allow_list" field.
- func (wu *WxUpdate) SetGroupAllowList(s []string) *WxUpdate {
- wu.mutation.SetGroupAllowList(s)
- return wu
- }
- // AppendGroupAllowList appends s to the "group_allow_list" field.
- func (wu *WxUpdate) AppendGroupAllowList(s []string) *WxUpdate {
- wu.mutation.AppendGroupAllowList(s)
- return wu
- }
- // SetBlockList sets the "block_list" field.
- func (wu *WxUpdate) SetBlockList(s []string) *WxUpdate {
- wu.mutation.SetBlockList(s)
- return wu
- }
- // AppendBlockList appends s to the "block_list" field.
- func (wu *WxUpdate) AppendBlockList(s []string) *WxUpdate {
- wu.mutation.AppendBlockList(s)
- return wu
- }
- // SetGroupBlockList sets the "group_block_list" field.
- func (wu *WxUpdate) SetGroupBlockList(s []string) *WxUpdate {
- wu.mutation.SetGroupBlockList(s)
- return wu
- }
- // AppendGroupBlockList appends s to the "group_block_list" field.
- func (wu *WxUpdate) AppendGroupBlockList(s []string) *WxUpdate {
- wu.mutation.AppendGroupBlockList(s)
- return wu
- }
- // SetServer sets the "server" edge to the Server entity.
- func (wu *WxUpdate) SetServer(s *Server) *WxUpdate {
- return wu.SetServerID(s.ID)
- }
- // SetAgent sets the "agent" edge to the Agent entity.
- func (wu *WxUpdate) SetAgent(a *Agent) *WxUpdate {
- return wu.SetAgentID(a.ID)
- }
- // Mutation returns the WxMutation object of the builder.
- func (wu *WxUpdate) Mutation() *WxMutation {
- return wu.mutation
- }
- // ClearServer clears the "server" edge to the Server entity.
- func (wu *WxUpdate) ClearServer() *WxUpdate {
- wu.mutation.ClearServer()
- return wu
- }
- // ClearAgent clears the "agent" edge to the Agent entity.
- func (wu *WxUpdate) ClearAgent() *WxUpdate {
- wu.mutation.ClearAgent()
- return wu
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (wu *WxUpdate) Save(ctx context.Context) (int, error) {
- if err := wu.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, wu.sqlSave, wu.mutation, wu.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (wu *WxUpdate) SaveX(ctx context.Context) int {
- affected, err := wu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (wu *WxUpdate) Exec(ctx context.Context) error {
- _, err := wu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wu *WxUpdate) ExecX(ctx context.Context) {
- if err := wu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (wu *WxUpdate) defaults() error {
- if _, ok := wu.mutation.UpdatedAt(); !ok {
- if wx.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized wx.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := wx.UpdateDefaultUpdatedAt()
- wu.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (wu *WxUpdate) check() error {
- if _, ok := wu.mutation.AgentID(); wu.mutation.AgentCleared() && !ok {
- return errors.New(`ent: clearing a required unique edge "Wx.agent"`)
- }
- return nil
- }
- func (wu *WxUpdate) sqlSave(ctx context.Context) (n int, err error) {
- if err := wu.check(); err != nil {
- return n, err
- }
- _spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
- if ps := wu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := wu.mutation.UpdatedAt(); ok {
- _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := wu.mutation.Status(); ok {
- _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := wu.mutation.AddedStatus(); ok {
- _spec.AddField(wx.FieldStatus, field.TypeUint8, value)
- }
- if wu.mutation.StatusCleared() {
- _spec.ClearField(wx.FieldStatus, field.TypeUint8)
- }
- if value, ok := wu.mutation.DeletedAt(); ok {
- _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
- }
- if wu.mutation.DeletedAtCleared() {
- _spec.ClearField(wx.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := wu.mutation.Port(); ok {
- _spec.SetField(wx.FieldPort, field.TypeString, value)
- }
- if value, ok := wu.mutation.ProcessID(); ok {
- _spec.SetField(wx.FieldProcessID, field.TypeString, value)
- }
- if value, ok := wu.mutation.Callback(); ok {
- _spec.SetField(wx.FieldCallback, field.TypeString, value)
- }
- if value, ok := wu.mutation.Wxid(); ok {
- _spec.SetField(wx.FieldWxid, field.TypeString, value)
- }
- if value, ok := wu.mutation.Account(); ok {
- _spec.SetField(wx.FieldAccount, field.TypeString, value)
- }
- if value, ok := wu.mutation.Nickname(); ok {
- _spec.SetField(wx.FieldNickname, field.TypeString, value)
- }
- if value, ok := wu.mutation.Tel(); ok {
- _spec.SetField(wx.FieldTel, field.TypeString, value)
- }
- if value, ok := wu.mutation.HeadBig(); ok {
- _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
- }
- if value, ok := wu.mutation.OrganizationID(); ok {
- _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := wu.mutation.AddedOrganizationID(); ok {
- _spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
- }
- if wu.mutation.OrganizationIDCleared() {
- _spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
- }
- if value, ok := wu.mutation.APIBase(); ok {
- _spec.SetField(wx.FieldAPIBase, field.TypeString, value)
- }
- if wu.mutation.APIBaseCleared() {
- _spec.ClearField(wx.FieldAPIBase, field.TypeString)
- }
- if value, ok := wu.mutation.APIKey(); ok {
- _spec.SetField(wx.FieldAPIKey, field.TypeString, value)
- }
- if wu.mutation.APIKeyCleared() {
- _spec.ClearField(wx.FieldAPIKey, field.TypeString)
- }
- if value, ok := wu.mutation.AllowList(); ok {
- _spec.SetField(wx.FieldAllowList, field.TypeJSON, value)
- }
- if value, ok := wu.mutation.AppendedAllowList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, wx.FieldAllowList, value)
- })
- }
- if value, ok := wu.mutation.GroupAllowList(); ok {
- _spec.SetField(wx.FieldGroupAllowList, field.TypeJSON, value)
- }
- if value, ok := wu.mutation.AppendedGroupAllowList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, wx.FieldGroupAllowList, value)
- })
- }
- if value, ok := wu.mutation.BlockList(); ok {
- _spec.SetField(wx.FieldBlockList, field.TypeJSON, value)
- }
- if value, ok := wu.mutation.AppendedBlockList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, wx.FieldBlockList, value)
- })
- }
- if value, ok := wu.mutation.GroupBlockList(); ok {
- _spec.SetField(wx.FieldGroupBlockList, field.TypeJSON, value)
- }
- if value, ok := wu.mutation.AppendedGroupBlockList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, wx.FieldGroupBlockList, value)
- })
- }
- if wu.mutation.ServerCleared() {
- 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),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := wu.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)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if wu.mutation.AgentCleared() {
- 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),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := wu.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)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{wx.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- wu.mutation.done = true
- return n, nil
- }
- // WxUpdateOne is the builder for updating a single Wx entity.
- type WxUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *WxMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (wuo *WxUpdateOne) SetUpdatedAt(t time.Time) *WxUpdateOne {
- wuo.mutation.SetUpdatedAt(t)
- return wuo
- }
- // SetStatus sets the "status" field.
- func (wuo *WxUpdateOne) SetStatus(u uint8) *WxUpdateOne {
- wuo.mutation.ResetStatus()
- wuo.mutation.SetStatus(u)
- return wuo
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableStatus(u *uint8) *WxUpdateOne {
- if u != nil {
- wuo.SetStatus(*u)
- }
- return wuo
- }
- // AddStatus adds u to the "status" field.
- func (wuo *WxUpdateOne) AddStatus(u int8) *WxUpdateOne {
- wuo.mutation.AddStatus(u)
- return wuo
- }
- // ClearStatus clears the value of the "status" field.
- func (wuo *WxUpdateOne) ClearStatus() *WxUpdateOne {
- wuo.mutation.ClearStatus()
- return wuo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (wuo *WxUpdateOne) SetDeletedAt(t time.Time) *WxUpdateOne {
- wuo.mutation.SetDeletedAt(t)
- return wuo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableDeletedAt(t *time.Time) *WxUpdateOne {
- if t != nil {
- wuo.SetDeletedAt(*t)
- }
- return wuo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (wuo *WxUpdateOne) ClearDeletedAt() *WxUpdateOne {
- wuo.mutation.ClearDeletedAt()
- return wuo
- }
- // SetServerID sets the "server_id" field.
- func (wuo *WxUpdateOne) SetServerID(u uint64) *WxUpdateOne {
- wuo.mutation.SetServerID(u)
- return wuo
- }
- // SetNillableServerID sets the "server_id" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableServerID(u *uint64) *WxUpdateOne {
- if u != nil {
- wuo.SetServerID(*u)
- }
- return wuo
- }
- // ClearServerID clears the value of the "server_id" field.
- func (wuo *WxUpdateOne) ClearServerID() *WxUpdateOne {
- wuo.mutation.ClearServerID()
- return wuo
- }
- // SetPort sets the "port" field.
- func (wuo *WxUpdateOne) SetPort(s string) *WxUpdateOne {
- wuo.mutation.SetPort(s)
- return wuo
- }
- // SetNillablePort sets the "port" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillablePort(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetPort(*s)
- }
- return wuo
- }
- // SetProcessID sets the "process_id" field.
- func (wuo *WxUpdateOne) SetProcessID(s string) *WxUpdateOne {
- wuo.mutation.SetProcessID(s)
- return wuo
- }
- // SetNillableProcessID sets the "process_id" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableProcessID(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetProcessID(*s)
- }
- return wuo
- }
- // SetCallback sets the "callback" field.
- func (wuo *WxUpdateOne) SetCallback(s string) *WxUpdateOne {
- wuo.mutation.SetCallback(s)
- return wuo
- }
- // SetNillableCallback sets the "callback" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableCallback(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetCallback(*s)
- }
- return wuo
- }
- // SetWxid sets the "wxid" field.
- func (wuo *WxUpdateOne) SetWxid(s string) *WxUpdateOne {
- wuo.mutation.SetWxid(s)
- return wuo
- }
- // SetNillableWxid sets the "wxid" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableWxid(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetWxid(*s)
- }
- return wuo
- }
- // SetAccount sets the "account" field.
- func (wuo *WxUpdateOne) SetAccount(s string) *WxUpdateOne {
- wuo.mutation.SetAccount(s)
- return wuo
- }
- // SetNillableAccount sets the "account" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableAccount(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetAccount(*s)
- }
- return wuo
- }
- // SetNickname sets the "nickname" field.
- func (wuo *WxUpdateOne) SetNickname(s string) *WxUpdateOne {
- wuo.mutation.SetNickname(s)
- return wuo
- }
- // SetNillableNickname sets the "nickname" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableNickname(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetNickname(*s)
- }
- return wuo
- }
- // SetTel sets the "tel" field.
- func (wuo *WxUpdateOne) SetTel(s string) *WxUpdateOne {
- wuo.mutation.SetTel(s)
- return wuo
- }
- // SetNillableTel sets the "tel" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableTel(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetTel(*s)
- }
- return wuo
- }
- // SetHeadBig sets the "head_big" field.
- func (wuo *WxUpdateOne) SetHeadBig(s string) *WxUpdateOne {
- wuo.mutation.SetHeadBig(s)
- return wuo
- }
- // SetNillableHeadBig sets the "head_big" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableHeadBig(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetHeadBig(*s)
- }
- return wuo
- }
- // SetOrganizationID sets the "organization_id" field.
- func (wuo *WxUpdateOne) SetOrganizationID(u uint64) *WxUpdateOne {
- wuo.mutation.ResetOrganizationID()
- wuo.mutation.SetOrganizationID(u)
- return wuo
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableOrganizationID(u *uint64) *WxUpdateOne {
- if u != nil {
- wuo.SetOrganizationID(*u)
- }
- return wuo
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (wuo *WxUpdateOne) AddOrganizationID(u int64) *WxUpdateOne {
- wuo.mutation.AddOrganizationID(u)
- return wuo
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (wuo *WxUpdateOne) ClearOrganizationID() *WxUpdateOne {
- wuo.mutation.ClearOrganizationID()
- return wuo
- }
- // SetAgentID sets the "agent_id" field.
- func (wuo *WxUpdateOne) SetAgentID(u uint64) *WxUpdateOne {
- wuo.mutation.SetAgentID(u)
- return wuo
- }
- // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableAgentID(u *uint64) *WxUpdateOne {
- if u != nil {
- wuo.SetAgentID(*u)
- }
- return wuo
- }
- // SetAPIBase sets the "api_base" field.
- func (wuo *WxUpdateOne) SetAPIBase(s string) *WxUpdateOne {
- wuo.mutation.SetAPIBase(s)
- return wuo
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableAPIBase(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetAPIBase(*s)
- }
- return wuo
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (wuo *WxUpdateOne) ClearAPIBase() *WxUpdateOne {
- wuo.mutation.ClearAPIBase()
- return wuo
- }
- // SetAPIKey sets the "api_key" field.
- func (wuo *WxUpdateOne) SetAPIKey(s string) *WxUpdateOne {
- wuo.mutation.SetAPIKey(s)
- return wuo
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (wuo *WxUpdateOne) SetNillableAPIKey(s *string) *WxUpdateOne {
- if s != nil {
- wuo.SetAPIKey(*s)
- }
- return wuo
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (wuo *WxUpdateOne) ClearAPIKey() *WxUpdateOne {
- wuo.mutation.ClearAPIKey()
- return wuo
- }
- // SetAllowList sets the "allow_list" field.
- func (wuo *WxUpdateOne) SetAllowList(s []string) *WxUpdateOne {
- wuo.mutation.SetAllowList(s)
- return wuo
- }
- // AppendAllowList appends s to the "allow_list" field.
- func (wuo *WxUpdateOne) AppendAllowList(s []string) *WxUpdateOne {
- wuo.mutation.AppendAllowList(s)
- return wuo
- }
- // SetGroupAllowList sets the "group_allow_list" field.
- func (wuo *WxUpdateOne) SetGroupAllowList(s []string) *WxUpdateOne {
- wuo.mutation.SetGroupAllowList(s)
- return wuo
- }
- // AppendGroupAllowList appends s to the "group_allow_list" field.
- func (wuo *WxUpdateOne) AppendGroupAllowList(s []string) *WxUpdateOne {
- wuo.mutation.AppendGroupAllowList(s)
- return wuo
- }
- // SetBlockList sets the "block_list" field.
- func (wuo *WxUpdateOne) SetBlockList(s []string) *WxUpdateOne {
- wuo.mutation.SetBlockList(s)
- return wuo
- }
- // AppendBlockList appends s to the "block_list" field.
- func (wuo *WxUpdateOne) AppendBlockList(s []string) *WxUpdateOne {
- wuo.mutation.AppendBlockList(s)
- return wuo
- }
- // SetGroupBlockList sets the "group_block_list" field.
- func (wuo *WxUpdateOne) SetGroupBlockList(s []string) *WxUpdateOne {
- wuo.mutation.SetGroupBlockList(s)
- return wuo
- }
- // AppendGroupBlockList appends s to the "group_block_list" field.
- func (wuo *WxUpdateOne) AppendGroupBlockList(s []string) *WxUpdateOne {
- wuo.mutation.AppendGroupBlockList(s)
- return wuo
- }
- // SetServer sets the "server" edge to the Server entity.
- func (wuo *WxUpdateOne) SetServer(s *Server) *WxUpdateOne {
- return wuo.SetServerID(s.ID)
- }
- // SetAgent sets the "agent" edge to the Agent entity.
- func (wuo *WxUpdateOne) SetAgent(a *Agent) *WxUpdateOne {
- return wuo.SetAgentID(a.ID)
- }
- // Mutation returns the WxMutation object of the builder.
- func (wuo *WxUpdateOne) Mutation() *WxMutation {
- return wuo.mutation
- }
- // ClearServer clears the "server" edge to the Server entity.
- func (wuo *WxUpdateOne) ClearServer() *WxUpdateOne {
- wuo.mutation.ClearServer()
- return wuo
- }
- // ClearAgent clears the "agent" edge to the Agent entity.
- func (wuo *WxUpdateOne) ClearAgent() *WxUpdateOne {
- wuo.mutation.ClearAgent()
- return wuo
- }
- // Where appends a list predicates to the WxUpdate builder.
- func (wuo *WxUpdateOne) Where(ps ...predicate.Wx) *WxUpdateOne {
- wuo.mutation.Where(ps...)
- return wuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (wuo *WxUpdateOne) Select(field string, fields ...string) *WxUpdateOne {
- wuo.fields = append([]string{field}, fields...)
- return wuo
- }
- // Save executes the query and returns the updated Wx entity.
- func (wuo *WxUpdateOne) Save(ctx context.Context) (*Wx, error) {
- if err := wuo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, wuo.sqlSave, wuo.mutation, wuo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (wuo *WxUpdateOne) SaveX(ctx context.Context) *Wx {
- node, err := wuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (wuo *WxUpdateOne) Exec(ctx context.Context) error {
- _, err := wuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wuo *WxUpdateOne) ExecX(ctx context.Context) {
- if err := wuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (wuo *WxUpdateOne) defaults() error {
- if _, ok := wuo.mutation.UpdatedAt(); !ok {
- if wx.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized wx.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := wx.UpdateDefaultUpdatedAt()
- wuo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (wuo *WxUpdateOne) check() error {
- if _, ok := wuo.mutation.AgentID(); wuo.mutation.AgentCleared() && !ok {
- return errors.New(`ent: clearing a required unique edge "Wx.agent"`)
- }
- return nil
- }
- func (wuo *WxUpdateOne) sqlSave(ctx context.Context) (_node *Wx, err error) {
- if err := wuo.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
- id, ok := wuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Wx.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := wuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, wx.FieldID)
- for _, f := range fields {
- if !wx.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != wx.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := wuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := wuo.mutation.UpdatedAt(); ok {
- _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := wuo.mutation.Status(); ok {
- _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := wuo.mutation.AddedStatus(); ok {
- _spec.AddField(wx.FieldStatus, field.TypeUint8, value)
- }
- if wuo.mutation.StatusCleared() {
- _spec.ClearField(wx.FieldStatus, field.TypeUint8)
- }
- if value, ok := wuo.mutation.DeletedAt(); ok {
- _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
- }
- if wuo.mutation.DeletedAtCleared() {
- _spec.ClearField(wx.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := wuo.mutation.Port(); ok {
- _spec.SetField(wx.FieldPort, field.TypeString, value)
- }
- if value, ok := wuo.mutation.ProcessID(); ok {
- _spec.SetField(wx.FieldProcessID, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Callback(); ok {
- _spec.SetField(wx.FieldCallback, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Wxid(); ok {
- _spec.SetField(wx.FieldWxid, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Account(); ok {
- _spec.SetField(wx.FieldAccount, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Nickname(); ok {
- _spec.SetField(wx.FieldNickname, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Tel(); ok {
- _spec.SetField(wx.FieldTel, field.TypeString, value)
- }
- if value, ok := wuo.mutation.HeadBig(); ok {
- _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
- }
- if value, ok := wuo.mutation.OrganizationID(); ok {
- _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := wuo.mutation.AddedOrganizationID(); ok {
- _spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
- }
- if wuo.mutation.OrganizationIDCleared() {
- _spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
- }
- if value, ok := wuo.mutation.APIBase(); ok {
- _spec.SetField(wx.FieldAPIBase, field.TypeString, value)
- }
- if wuo.mutation.APIBaseCleared() {
- _spec.ClearField(wx.FieldAPIBase, field.TypeString)
- }
- if value, ok := wuo.mutation.APIKey(); ok {
- _spec.SetField(wx.FieldAPIKey, field.TypeString, value)
- }
- if wuo.mutation.APIKeyCleared() {
- _spec.ClearField(wx.FieldAPIKey, field.TypeString)
- }
- if value, ok := wuo.mutation.AllowList(); ok {
- _spec.SetField(wx.FieldAllowList, field.TypeJSON, value)
- }
- if value, ok := wuo.mutation.AppendedAllowList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, wx.FieldAllowList, value)
- })
- }
- if value, ok := wuo.mutation.GroupAllowList(); ok {
- _spec.SetField(wx.FieldGroupAllowList, field.TypeJSON, value)
- }
- if value, ok := wuo.mutation.AppendedGroupAllowList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, wx.FieldGroupAllowList, value)
- })
- }
- if value, ok := wuo.mutation.BlockList(); ok {
- _spec.SetField(wx.FieldBlockList, field.TypeJSON, value)
- }
- if value, ok := wuo.mutation.AppendedBlockList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, wx.FieldBlockList, value)
- })
- }
- if value, ok := wuo.mutation.GroupBlockList(); ok {
- _spec.SetField(wx.FieldGroupBlockList, field.TypeJSON, value)
- }
- if value, ok := wuo.mutation.AppendedGroupBlockList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, wx.FieldGroupBlockList, value)
- })
- }
- if wuo.mutation.ServerCleared() {
- 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),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := wuo.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)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if wuo.mutation.AgentCleared() {
- 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),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := wuo.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)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &Wx{config: wuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{wx.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- wuo.mutation.done = true
- return _node, nil
- }
|