12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/custom_types"
- "wechat-api/ent/messagerecords"
- "wechat-api/ent/predicate"
- "wechat-api/ent/sopnode"
- "wechat-api/ent/sopstage"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/dialect/sql/sqljson"
- "entgo.io/ent/schema/field"
- )
- // SopNodeUpdate is the builder for updating SopNode entities.
- type SopNodeUpdate struct {
- config
- hooks []Hook
- mutation *SopNodeMutation
- }
- // Where appends a list predicates to the SopNodeUpdate builder.
- func (snu *SopNodeUpdate) Where(ps ...predicate.SopNode) *SopNodeUpdate {
- snu.mutation.Where(ps...)
- return snu
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (snu *SopNodeUpdate) SetUpdatedAt(t time.Time) *SopNodeUpdate {
- snu.mutation.SetUpdatedAt(t)
- return snu
- }
- // SetStatus sets the "status" field.
- func (snu *SopNodeUpdate) SetStatus(u uint8) *SopNodeUpdate {
- snu.mutation.ResetStatus()
- snu.mutation.SetStatus(u)
- return snu
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (snu *SopNodeUpdate) SetNillableStatus(u *uint8) *SopNodeUpdate {
- if u != nil {
- snu.SetStatus(*u)
- }
- return snu
- }
- // AddStatus adds u to the "status" field.
- func (snu *SopNodeUpdate) AddStatus(u int8) *SopNodeUpdate {
- snu.mutation.AddStatus(u)
- return snu
- }
- // ClearStatus clears the value of the "status" field.
- func (snu *SopNodeUpdate) ClearStatus() *SopNodeUpdate {
- snu.mutation.ClearStatus()
- return snu
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (snu *SopNodeUpdate) SetDeletedAt(t time.Time) *SopNodeUpdate {
- snu.mutation.SetDeletedAt(t)
- return snu
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (snu *SopNodeUpdate) SetNillableDeletedAt(t *time.Time) *SopNodeUpdate {
- if t != nil {
- snu.SetDeletedAt(*t)
- }
- return snu
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (snu *SopNodeUpdate) ClearDeletedAt() *SopNodeUpdate {
- snu.mutation.ClearDeletedAt()
- return snu
- }
- // SetStageID sets the "stage_id" field.
- func (snu *SopNodeUpdate) SetStageID(u uint64) *SopNodeUpdate {
- snu.mutation.SetStageID(u)
- return snu
- }
- // SetNillableStageID sets the "stage_id" field if the given value is not nil.
- func (snu *SopNodeUpdate) SetNillableStageID(u *uint64) *SopNodeUpdate {
- if u != nil {
- snu.SetStageID(*u)
- }
- return snu
- }
- // SetParentID sets the "parent_id" field.
- func (snu *SopNodeUpdate) SetParentID(u uint64) *SopNodeUpdate {
- snu.mutation.ResetParentID()
- snu.mutation.SetParentID(u)
- return snu
- }
- // SetNillableParentID sets the "parent_id" field if the given value is not nil.
- func (snu *SopNodeUpdate) SetNillableParentID(u *uint64) *SopNodeUpdate {
- if u != nil {
- snu.SetParentID(*u)
- }
- return snu
- }
- // AddParentID adds u to the "parent_id" field.
- func (snu *SopNodeUpdate) AddParentID(u int64) *SopNodeUpdate {
- snu.mutation.AddParentID(u)
- return snu
- }
- // SetName sets the "name" field.
- func (snu *SopNodeUpdate) SetName(s string) *SopNodeUpdate {
- snu.mutation.SetName(s)
- return snu
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (snu *SopNodeUpdate) SetNillableName(s *string) *SopNodeUpdate {
- if s != nil {
- snu.SetName(*s)
- }
- return snu
- }
- // SetConditionType sets the "condition_type" field.
- func (snu *SopNodeUpdate) SetConditionType(i int) *SopNodeUpdate {
- snu.mutation.ResetConditionType()
- snu.mutation.SetConditionType(i)
- return snu
- }
- // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
- func (snu *SopNodeUpdate) SetNillableConditionType(i *int) *SopNodeUpdate {
- if i != nil {
- snu.SetConditionType(*i)
- }
- return snu
- }
- // AddConditionType adds i to the "condition_type" field.
- func (snu *SopNodeUpdate) AddConditionType(i int) *SopNodeUpdate {
- snu.mutation.AddConditionType(i)
- return snu
- }
- // SetConditionList sets the "condition_list" field.
- func (snu *SopNodeUpdate) SetConditionList(s []string) *SopNodeUpdate {
- snu.mutation.SetConditionList(s)
- return snu
- }
- // AppendConditionList appends s to the "condition_list" field.
- func (snu *SopNodeUpdate) AppendConditionList(s []string) *SopNodeUpdate {
- snu.mutation.AppendConditionList(s)
- return snu
- }
- // ClearConditionList clears the value of the "condition_list" field.
- func (snu *SopNodeUpdate) ClearConditionList() *SopNodeUpdate {
- snu.mutation.ClearConditionList()
- return snu
- }
- // SetNoReplyCondition sets the "no_reply_condition" field.
- func (snu *SopNodeUpdate) SetNoReplyCondition(u uint64) *SopNodeUpdate {
- snu.mutation.ResetNoReplyCondition()
- snu.mutation.SetNoReplyCondition(u)
- return snu
- }
- // SetNillableNoReplyCondition sets the "no_reply_condition" field if the given value is not nil.
- func (snu *SopNodeUpdate) SetNillableNoReplyCondition(u *uint64) *SopNodeUpdate {
- if u != nil {
- snu.SetNoReplyCondition(*u)
- }
- return snu
- }
- // AddNoReplyCondition adds u to the "no_reply_condition" field.
- func (snu *SopNodeUpdate) AddNoReplyCondition(u int64) *SopNodeUpdate {
- snu.mutation.AddNoReplyCondition(u)
- return snu
- }
- // SetNoReplyUnit sets the "no_reply_unit" field.
- func (snu *SopNodeUpdate) SetNoReplyUnit(s string) *SopNodeUpdate {
- snu.mutation.SetNoReplyUnit(s)
- return snu
- }
- // SetNillableNoReplyUnit sets the "no_reply_unit" field if the given value is not nil.
- func (snu *SopNodeUpdate) SetNillableNoReplyUnit(s *string) *SopNodeUpdate {
- if s != nil {
- snu.SetNoReplyUnit(*s)
- }
- return snu
- }
- // SetActionMessage sets the "action_message" field.
- func (snu *SopNodeUpdate) SetActionMessage(ct []custom_types.Action) *SopNodeUpdate {
- snu.mutation.SetActionMessage(ct)
- return snu
- }
- // AppendActionMessage appends ct to the "action_message" field.
- func (snu *SopNodeUpdate) AppendActionMessage(ct []custom_types.Action) *SopNodeUpdate {
- snu.mutation.AppendActionMessage(ct)
- return snu
- }
- // ClearActionMessage clears the value of the "action_message" field.
- func (snu *SopNodeUpdate) ClearActionMessage() *SopNodeUpdate {
- snu.mutation.ClearActionMessage()
- return snu
- }
- // SetActionLabelAdd sets the "action_label_add" field.
- func (snu *SopNodeUpdate) SetActionLabelAdd(u []uint64) *SopNodeUpdate {
- snu.mutation.SetActionLabelAdd(u)
- return snu
- }
- // AppendActionLabelAdd appends u to the "action_label_add" field.
- func (snu *SopNodeUpdate) AppendActionLabelAdd(u []uint64) *SopNodeUpdate {
- snu.mutation.AppendActionLabelAdd(u)
- return snu
- }
- // ClearActionLabelAdd clears the value of the "action_label_add" field.
- func (snu *SopNodeUpdate) ClearActionLabelAdd() *SopNodeUpdate {
- snu.mutation.ClearActionLabelAdd()
- return snu
- }
- // SetActionLabelDel sets the "action_label_del" field.
- func (snu *SopNodeUpdate) SetActionLabelDel(u []uint64) *SopNodeUpdate {
- snu.mutation.SetActionLabelDel(u)
- return snu
- }
- // AppendActionLabelDel appends u to the "action_label_del" field.
- func (snu *SopNodeUpdate) AppendActionLabelDel(u []uint64) *SopNodeUpdate {
- snu.mutation.AppendActionLabelDel(u)
- return snu
- }
- // ClearActionLabelDel clears the value of the "action_label_del" field.
- func (snu *SopNodeUpdate) ClearActionLabelDel() *SopNodeUpdate {
- snu.mutation.ClearActionLabelDel()
- return snu
- }
- // SetActionForward sets the "action_forward" field.
- func (snu *SopNodeUpdate) SetActionForward(ctf *custom_types.ActionForward) *SopNodeUpdate {
- snu.mutation.SetActionForward(ctf)
- return snu
- }
- // ClearActionForward clears the value of the "action_forward" field.
- func (snu *SopNodeUpdate) ClearActionForward() *SopNodeUpdate {
- snu.mutation.ClearActionForward()
- return snu
- }
- // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
- func (snu *SopNodeUpdate) SetSopStageID(id uint64) *SopNodeUpdate {
- snu.mutation.SetSopStageID(id)
- return snu
- }
- // SetSopStage sets the "sop_stage" edge to the SopStage entity.
- func (snu *SopNodeUpdate) SetSopStage(s *SopStage) *SopNodeUpdate {
- return snu.SetSopStageID(s.ID)
- }
- // AddNodeMessageIDs adds the "node_messages" edge to the MessageRecords entity by IDs.
- func (snu *SopNodeUpdate) AddNodeMessageIDs(ids ...uint64) *SopNodeUpdate {
- snu.mutation.AddNodeMessageIDs(ids...)
- return snu
- }
- // AddNodeMessages adds the "node_messages" edges to the MessageRecords entity.
- func (snu *SopNodeUpdate) AddNodeMessages(m ...*MessageRecords) *SopNodeUpdate {
- ids := make([]uint64, len(m))
- for i := range m {
- ids[i] = m[i].ID
- }
- return snu.AddNodeMessageIDs(ids...)
- }
- // Mutation returns the SopNodeMutation object of the builder.
- func (snu *SopNodeUpdate) Mutation() *SopNodeMutation {
- return snu.mutation
- }
- // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
- func (snu *SopNodeUpdate) ClearSopStage() *SopNodeUpdate {
- snu.mutation.ClearSopStage()
- return snu
- }
- // ClearNodeMessages clears all "node_messages" edges to the MessageRecords entity.
- func (snu *SopNodeUpdate) ClearNodeMessages() *SopNodeUpdate {
- snu.mutation.ClearNodeMessages()
- return snu
- }
- // RemoveNodeMessageIDs removes the "node_messages" edge to MessageRecords entities by IDs.
- func (snu *SopNodeUpdate) RemoveNodeMessageIDs(ids ...uint64) *SopNodeUpdate {
- snu.mutation.RemoveNodeMessageIDs(ids...)
- return snu
- }
- // RemoveNodeMessages removes "node_messages" edges to MessageRecords entities.
- func (snu *SopNodeUpdate) RemoveNodeMessages(m ...*MessageRecords) *SopNodeUpdate {
- ids := make([]uint64, len(m))
- for i := range m {
- ids[i] = m[i].ID
- }
- return snu.RemoveNodeMessageIDs(ids...)
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (snu *SopNodeUpdate) Save(ctx context.Context) (int, error) {
- if err := snu.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, snu.sqlSave, snu.mutation, snu.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (snu *SopNodeUpdate) SaveX(ctx context.Context) int {
- affected, err := snu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (snu *SopNodeUpdate) Exec(ctx context.Context) error {
- _, err := snu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (snu *SopNodeUpdate) ExecX(ctx context.Context) {
- if err := snu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (snu *SopNodeUpdate) defaults() error {
- if _, ok := snu.mutation.UpdatedAt(); !ok {
- if sopnode.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized sopnode.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := sopnode.UpdateDefaultUpdatedAt()
- snu.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (snu *SopNodeUpdate) check() error {
- if _, ok := snu.mutation.SopStageID(); snu.mutation.SopStageCleared() && !ok {
- return errors.New(`ent: clearing a required unique edge "SopNode.sop_stage"`)
- }
- return nil
- }
- func (snu *SopNodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
- if err := snu.check(); err != nil {
- return n, err
- }
- _spec := sqlgraph.NewUpdateSpec(sopnode.Table, sopnode.Columns, sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64))
- if ps := snu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := snu.mutation.UpdatedAt(); ok {
- _spec.SetField(sopnode.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := snu.mutation.Status(); ok {
- _spec.SetField(sopnode.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := snu.mutation.AddedStatus(); ok {
- _spec.AddField(sopnode.FieldStatus, field.TypeUint8, value)
- }
- if snu.mutation.StatusCleared() {
- _spec.ClearField(sopnode.FieldStatus, field.TypeUint8)
- }
- if value, ok := snu.mutation.DeletedAt(); ok {
- _spec.SetField(sopnode.FieldDeletedAt, field.TypeTime, value)
- }
- if snu.mutation.DeletedAtCleared() {
- _spec.ClearField(sopnode.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := snu.mutation.ParentID(); ok {
- _spec.SetField(sopnode.FieldParentID, field.TypeUint64, value)
- }
- if value, ok := snu.mutation.AddedParentID(); ok {
- _spec.AddField(sopnode.FieldParentID, field.TypeUint64, value)
- }
- if value, ok := snu.mutation.Name(); ok {
- _spec.SetField(sopnode.FieldName, field.TypeString, value)
- }
- if value, ok := snu.mutation.ConditionType(); ok {
- _spec.SetField(sopnode.FieldConditionType, field.TypeInt, value)
- }
- if value, ok := snu.mutation.AddedConditionType(); ok {
- _spec.AddField(sopnode.FieldConditionType, field.TypeInt, value)
- }
- if value, ok := snu.mutation.ConditionList(); ok {
- _spec.SetField(sopnode.FieldConditionList, field.TypeJSON, value)
- }
- if value, ok := snu.mutation.AppendedConditionList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldConditionList, value)
- })
- }
- if snu.mutation.ConditionListCleared() {
- _spec.ClearField(sopnode.FieldConditionList, field.TypeJSON)
- }
- if value, ok := snu.mutation.NoReplyCondition(); ok {
- _spec.SetField(sopnode.FieldNoReplyCondition, field.TypeUint64, value)
- }
- if value, ok := snu.mutation.AddedNoReplyCondition(); ok {
- _spec.AddField(sopnode.FieldNoReplyCondition, field.TypeUint64, value)
- }
- if value, ok := snu.mutation.NoReplyUnit(); ok {
- _spec.SetField(sopnode.FieldNoReplyUnit, field.TypeString, value)
- }
- if value, ok := snu.mutation.ActionMessage(); ok {
- _spec.SetField(sopnode.FieldActionMessage, field.TypeJSON, value)
- }
- if value, ok := snu.mutation.AppendedActionMessage(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldActionMessage, value)
- })
- }
- if snu.mutation.ActionMessageCleared() {
- _spec.ClearField(sopnode.FieldActionMessage, field.TypeJSON)
- }
- if value, ok := snu.mutation.ActionLabelAdd(); ok {
- _spec.SetField(sopnode.FieldActionLabelAdd, field.TypeJSON, value)
- }
- if value, ok := snu.mutation.AppendedActionLabelAdd(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldActionLabelAdd, value)
- })
- }
- if snu.mutation.ActionLabelAddCleared() {
- _spec.ClearField(sopnode.FieldActionLabelAdd, field.TypeJSON)
- }
- if value, ok := snu.mutation.ActionLabelDel(); ok {
- _spec.SetField(sopnode.FieldActionLabelDel, field.TypeJSON, value)
- }
- if value, ok := snu.mutation.AppendedActionLabelDel(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldActionLabelDel, value)
- })
- }
- if snu.mutation.ActionLabelDelCleared() {
- _spec.ClearField(sopnode.FieldActionLabelDel, field.TypeJSON)
- }
- if value, ok := snu.mutation.ActionForward(); ok {
- _spec.SetField(sopnode.FieldActionForward, field.TypeJSON, value)
- }
- if snu.mutation.ActionForwardCleared() {
- _spec.ClearField(sopnode.FieldActionForward, field.TypeJSON)
- }
- if snu.mutation.SopStageCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: sopnode.SopStageTable,
- Columns: []string{sopnode.SopStageColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := snu.mutation.SopStageIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: sopnode.SopStageTable,
- Columns: []string{sopnode.SopStageColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if snu.mutation.NodeMessagesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopnode.NodeMessagesTable,
- Columns: []string{sopnode.NodeMessagesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := snu.mutation.RemovedNodeMessagesIDs(); len(nodes) > 0 && !snu.mutation.NodeMessagesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopnode.NodeMessagesTable,
- Columns: []string{sopnode.NodeMessagesColumn},
- 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.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := snu.mutation.NodeMessagesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopnode.NodeMessagesTable,
- Columns: []string{sopnode.NodeMessagesColumn},
- 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.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, snu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{sopnode.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- snu.mutation.done = true
- return n, nil
- }
- // SopNodeUpdateOne is the builder for updating a single SopNode entity.
- type SopNodeUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *SopNodeMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (snuo *SopNodeUpdateOne) SetUpdatedAt(t time.Time) *SopNodeUpdateOne {
- snuo.mutation.SetUpdatedAt(t)
- return snuo
- }
- // SetStatus sets the "status" field.
- func (snuo *SopNodeUpdateOne) SetStatus(u uint8) *SopNodeUpdateOne {
- snuo.mutation.ResetStatus()
- snuo.mutation.SetStatus(u)
- return snuo
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (snuo *SopNodeUpdateOne) SetNillableStatus(u *uint8) *SopNodeUpdateOne {
- if u != nil {
- snuo.SetStatus(*u)
- }
- return snuo
- }
- // AddStatus adds u to the "status" field.
- func (snuo *SopNodeUpdateOne) AddStatus(u int8) *SopNodeUpdateOne {
- snuo.mutation.AddStatus(u)
- return snuo
- }
- // ClearStatus clears the value of the "status" field.
- func (snuo *SopNodeUpdateOne) ClearStatus() *SopNodeUpdateOne {
- snuo.mutation.ClearStatus()
- return snuo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (snuo *SopNodeUpdateOne) SetDeletedAt(t time.Time) *SopNodeUpdateOne {
- snuo.mutation.SetDeletedAt(t)
- return snuo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (snuo *SopNodeUpdateOne) SetNillableDeletedAt(t *time.Time) *SopNodeUpdateOne {
- if t != nil {
- snuo.SetDeletedAt(*t)
- }
- return snuo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (snuo *SopNodeUpdateOne) ClearDeletedAt() *SopNodeUpdateOne {
- snuo.mutation.ClearDeletedAt()
- return snuo
- }
- // SetStageID sets the "stage_id" field.
- func (snuo *SopNodeUpdateOne) SetStageID(u uint64) *SopNodeUpdateOne {
- snuo.mutation.SetStageID(u)
- return snuo
- }
- // SetNillableStageID sets the "stage_id" field if the given value is not nil.
- func (snuo *SopNodeUpdateOne) SetNillableStageID(u *uint64) *SopNodeUpdateOne {
- if u != nil {
- snuo.SetStageID(*u)
- }
- return snuo
- }
- // SetParentID sets the "parent_id" field.
- func (snuo *SopNodeUpdateOne) SetParentID(u uint64) *SopNodeUpdateOne {
- snuo.mutation.ResetParentID()
- snuo.mutation.SetParentID(u)
- return snuo
- }
- // SetNillableParentID sets the "parent_id" field if the given value is not nil.
- func (snuo *SopNodeUpdateOne) SetNillableParentID(u *uint64) *SopNodeUpdateOne {
- if u != nil {
- snuo.SetParentID(*u)
- }
- return snuo
- }
- // AddParentID adds u to the "parent_id" field.
- func (snuo *SopNodeUpdateOne) AddParentID(u int64) *SopNodeUpdateOne {
- snuo.mutation.AddParentID(u)
- return snuo
- }
- // SetName sets the "name" field.
- func (snuo *SopNodeUpdateOne) SetName(s string) *SopNodeUpdateOne {
- snuo.mutation.SetName(s)
- return snuo
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (snuo *SopNodeUpdateOne) SetNillableName(s *string) *SopNodeUpdateOne {
- if s != nil {
- snuo.SetName(*s)
- }
- return snuo
- }
- // SetConditionType sets the "condition_type" field.
- func (snuo *SopNodeUpdateOne) SetConditionType(i int) *SopNodeUpdateOne {
- snuo.mutation.ResetConditionType()
- snuo.mutation.SetConditionType(i)
- return snuo
- }
- // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
- func (snuo *SopNodeUpdateOne) SetNillableConditionType(i *int) *SopNodeUpdateOne {
- if i != nil {
- snuo.SetConditionType(*i)
- }
- return snuo
- }
- // AddConditionType adds i to the "condition_type" field.
- func (snuo *SopNodeUpdateOne) AddConditionType(i int) *SopNodeUpdateOne {
- snuo.mutation.AddConditionType(i)
- return snuo
- }
- // SetConditionList sets the "condition_list" field.
- func (snuo *SopNodeUpdateOne) SetConditionList(s []string) *SopNodeUpdateOne {
- snuo.mutation.SetConditionList(s)
- return snuo
- }
- // AppendConditionList appends s to the "condition_list" field.
- func (snuo *SopNodeUpdateOne) AppendConditionList(s []string) *SopNodeUpdateOne {
- snuo.mutation.AppendConditionList(s)
- return snuo
- }
- // ClearConditionList clears the value of the "condition_list" field.
- func (snuo *SopNodeUpdateOne) ClearConditionList() *SopNodeUpdateOne {
- snuo.mutation.ClearConditionList()
- return snuo
- }
- // SetNoReplyCondition sets the "no_reply_condition" field.
- func (snuo *SopNodeUpdateOne) SetNoReplyCondition(u uint64) *SopNodeUpdateOne {
- snuo.mutation.ResetNoReplyCondition()
- snuo.mutation.SetNoReplyCondition(u)
- return snuo
- }
- // SetNillableNoReplyCondition sets the "no_reply_condition" field if the given value is not nil.
- func (snuo *SopNodeUpdateOne) SetNillableNoReplyCondition(u *uint64) *SopNodeUpdateOne {
- if u != nil {
- snuo.SetNoReplyCondition(*u)
- }
- return snuo
- }
- // AddNoReplyCondition adds u to the "no_reply_condition" field.
- func (snuo *SopNodeUpdateOne) AddNoReplyCondition(u int64) *SopNodeUpdateOne {
- snuo.mutation.AddNoReplyCondition(u)
- return snuo
- }
- // SetNoReplyUnit sets the "no_reply_unit" field.
- func (snuo *SopNodeUpdateOne) SetNoReplyUnit(s string) *SopNodeUpdateOne {
- snuo.mutation.SetNoReplyUnit(s)
- return snuo
- }
- // SetNillableNoReplyUnit sets the "no_reply_unit" field if the given value is not nil.
- func (snuo *SopNodeUpdateOne) SetNillableNoReplyUnit(s *string) *SopNodeUpdateOne {
- if s != nil {
- snuo.SetNoReplyUnit(*s)
- }
- return snuo
- }
- // SetActionMessage sets the "action_message" field.
- func (snuo *SopNodeUpdateOne) SetActionMessage(ct []custom_types.Action) *SopNodeUpdateOne {
- snuo.mutation.SetActionMessage(ct)
- return snuo
- }
- // AppendActionMessage appends ct to the "action_message" field.
- func (snuo *SopNodeUpdateOne) AppendActionMessage(ct []custom_types.Action) *SopNodeUpdateOne {
- snuo.mutation.AppendActionMessage(ct)
- return snuo
- }
- // ClearActionMessage clears the value of the "action_message" field.
- func (snuo *SopNodeUpdateOne) ClearActionMessage() *SopNodeUpdateOne {
- snuo.mutation.ClearActionMessage()
- return snuo
- }
- // SetActionLabelAdd sets the "action_label_add" field.
- func (snuo *SopNodeUpdateOne) SetActionLabelAdd(u []uint64) *SopNodeUpdateOne {
- snuo.mutation.SetActionLabelAdd(u)
- return snuo
- }
- // AppendActionLabelAdd appends u to the "action_label_add" field.
- func (snuo *SopNodeUpdateOne) AppendActionLabelAdd(u []uint64) *SopNodeUpdateOne {
- snuo.mutation.AppendActionLabelAdd(u)
- return snuo
- }
- // ClearActionLabelAdd clears the value of the "action_label_add" field.
- func (snuo *SopNodeUpdateOne) ClearActionLabelAdd() *SopNodeUpdateOne {
- snuo.mutation.ClearActionLabelAdd()
- return snuo
- }
- // SetActionLabelDel sets the "action_label_del" field.
- func (snuo *SopNodeUpdateOne) SetActionLabelDel(u []uint64) *SopNodeUpdateOne {
- snuo.mutation.SetActionLabelDel(u)
- return snuo
- }
- // AppendActionLabelDel appends u to the "action_label_del" field.
- func (snuo *SopNodeUpdateOne) AppendActionLabelDel(u []uint64) *SopNodeUpdateOne {
- snuo.mutation.AppendActionLabelDel(u)
- return snuo
- }
- // ClearActionLabelDel clears the value of the "action_label_del" field.
- func (snuo *SopNodeUpdateOne) ClearActionLabelDel() *SopNodeUpdateOne {
- snuo.mutation.ClearActionLabelDel()
- return snuo
- }
- // SetActionForward sets the "action_forward" field.
- func (snuo *SopNodeUpdateOne) SetActionForward(ctf *custom_types.ActionForward) *SopNodeUpdateOne {
- snuo.mutation.SetActionForward(ctf)
- return snuo
- }
- // ClearActionForward clears the value of the "action_forward" field.
- func (snuo *SopNodeUpdateOne) ClearActionForward() *SopNodeUpdateOne {
- snuo.mutation.ClearActionForward()
- return snuo
- }
- // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
- func (snuo *SopNodeUpdateOne) SetSopStageID(id uint64) *SopNodeUpdateOne {
- snuo.mutation.SetSopStageID(id)
- return snuo
- }
- // SetSopStage sets the "sop_stage" edge to the SopStage entity.
- func (snuo *SopNodeUpdateOne) SetSopStage(s *SopStage) *SopNodeUpdateOne {
- return snuo.SetSopStageID(s.ID)
- }
- // AddNodeMessageIDs adds the "node_messages" edge to the MessageRecords entity by IDs.
- func (snuo *SopNodeUpdateOne) AddNodeMessageIDs(ids ...uint64) *SopNodeUpdateOne {
- snuo.mutation.AddNodeMessageIDs(ids...)
- return snuo
- }
- // AddNodeMessages adds the "node_messages" edges to the MessageRecords entity.
- func (snuo *SopNodeUpdateOne) AddNodeMessages(m ...*MessageRecords) *SopNodeUpdateOne {
- ids := make([]uint64, len(m))
- for i := range m {
- ids[i] = m[i].ID
- }
- return snuo.AddNodeMessageIDs(ids...)
- }
- // Mutation returns the SopNodeMutation object of the builder.
- func (snuo *SopNodeUpdateOne) Mutation() *SopNodeMutation {
- return snuo.mutation
- }
- // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
- func (snuo *SopNodeUpdateOne) ClearSopStage() *SopNodeUpdateOne {
- snuo.mutation.ClearSopStage()
- return snuo
- }
- // ClearNodeMessages clears all "node_messages" edges to the MessageRecords entity.
- func (snuo *SopNodeUpdateOne) ClearNodeMessages() *SopNodeUpdateOne {
- snuo.mutation.ClearNodeMessages()
- return snuo
- }
- // RemoveNodeMessageIDs removes the "node_messages" edge to MessageRecords entities by IDs.
- func (snuo *SopNodeUpdateOne) RemoveNodeMessageIDs(ids ...uint64) *SopNodeUpdateOne {
- snuo.mutation.RemoveNodeMessageIDs(ids...)
- return snuo
- }
- // RemoveNodeMessages removes "node_messages" edges to MessageRecords entities.
- func (snuo *SopNodeUpdateOne) RemoveNodeMessages(m ...*MessageRecords) *SopNodeUpdateOne {
- ids := make([]uint64, len(m))
- for i := range m {
- ids[i] = m[i].ID
- }
- return snuo.RemoveNodeMessageIDs(ids...)
- }
- // Where appends a list predicates to the SopNodeUpdate builder.
- func (snuo *SopNodeUpdateOne) Where(ps ...predicate.SopNode) *SopNodeUpdateOne {
- snuo.mutation.Where(ps...)
- return snuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (snuo *SopNodeUpdateOne) Select(field string, fields ...string) *SopNodeUpdateOne {
- snuo.fields = append([]string{field}, fields...)
- return snuo
- }
- // Save executes the query and returns the updated SopNode entity.
- func (snuo *SopNodeUpdateOne) Save(ctx context.Context) (*SopNode, error) {
- if err := snuo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, snuo.sqlSave, snuo.mutation, snuo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (snuo *SopNodeUpdateOne) SaveX(ctx context.Context) *SopNode {
- node, err := snuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (snuo *SopNodeUpdateOne) Exec(ctx context.Context) error {
- _, err := snuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (snuo *SopNodeUpdateOne) ExecX(ctx context.Context) {
- if err := snuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (snuo *SopNodeUpdateOne) defaults() error {
- if _, ok := snuo.mutation.UpdatedAt(); !ok {
- if sopnode.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized sopnode.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := sopnode.UpdateDefaultUpdatedAt()
- snuo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (snuo *SopNodeUpdateOne) check() error {
- if _, ok := snuo.mutation.SopStageID(); snuo.mutation.SopStageCleared() && !ok {
- return errors.New(`ent: clearing a required unique edge "SopNode.sop_stage"`)
- }
- return nil
- }
- func (snuo *SopNodeUpdateOne) sqlSave(ctx context.Context) (_node *SopNode, err error) {
- if err := snuo.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(sopnode.Table, sopnode.Columns, sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64))
- id, ok := snuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SopNode.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := snuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, sopnode.FieldID)
- for _, f := range fields {
- if !sopnode.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != sopnode.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := snuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := snuo.mutation.UpdatedAt(); ok {
- _spec.SetField(sopnode.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := snuo.mutation.Status(); ok {
- _spec.SetField(sopnode.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := snuo.mutation.AddedStatus(); ok {
- _spec.AddField(sopnode.FieldStatus, field.TypeUint8, value)
- }
- if snuo.mutation.StatusCleared() {
- _spec.ClearField(sopnode.FieldStatus, field.TypeUint8)
- }
- if value, ok := snuo.mutation.DeletedAt(); ok {
- _spec.SetField(sopnode.FieldDeletedAt, field.TypeTime, value)
- }
- if snuo.mutation.DeletedAtCleared() {
- _spec.ClearField(sopnode.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := snuo.mutation.ParentID(); ok {
- _spec.SetField(sopnode.FieldParentID, field.TypeUint64, value)
- }
- if value, ok := snuo.mutation.AddedParentID(); ok {
- _spec.AddField(sopnode.FieldParentID, field.TypeUint64, value)
- }
- if value, ok := snuo.mutation.Name(); ok {
- _spec.SetField(sopnode.FieldName, field.TypeString, value)
- }
- if value, ok := snuo.mutation.ConditionType(); ok {
- _spec.SetField(sopnode.FieldConditionType, field.TypeInt, value)
- }
- if value, ok := snuo.mutation.AddedConditionType(); ok {
- _spec.AddField(sopnode.FieldConditionType, field.TypeInt, value)
- }
- if value, ok := snuo.mutation.ConditionList(); ok {
- _spec.SetField(sopnode.FieldConditionList, field.TypeJSON, value)
- }
- if value, ok := snuo.mutation.AppendedConditionList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldConditionList, value)
- })
- }
- if snuo.mutation.ConditionListCleared() {
- _spec.ClearField(sopnode.FieldConditionList, field.TypeJSON)
- }
- if value, ok := snuo.mutation.NoReplyCondition(); ok {
- _spec.SetField(sopnode.FieldNoReplyCondition, field.TypeUint64, value)
- }
- if value, ok := snuo.mutation.AddedNoReplyCondition(); ok {
- _spec.AddField(sopnode.FieldNoReplyCondition, field.TypeUint64, value)
- }
- if value, ok := snuo.mutation.NoReplyUnit(); ok {
- _spec.SetField(sopnode.FieldNoReplyUnit, field.TypeString, value)
- }
- if value, ok := snuo.mutation.ActionMessage(); ok {
- _spec.SetField(sopnode.FieldActionMessage, field.TypeJSON, value)
- }
- if value, ok := snuo.mutation.AppendedActionMessage(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldActionMessage, value)
- })
- }
- if snuo.mutation.ActionMessageCleared() {
- _spec.ClearField(sopnode.FieldActionMessage, field.TypeJSON)
- }
- if value, ok := snuo.mutation.ActionLabelAdd(); ok {
- _spec.SetField(sopnode.FieldActionLabelAdd, field.TypeJSON, value)
- }
- if value, ok := snuo.mutation.AppendedActionLabelAdd(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldActionLabelAdd, value)
- })
- }
- if snuo.mutation.ActionLabelAddCleared() {
- _spec.ClearField(sopnode.FieldActionLabelAdd, field.TypeJSON)
- }
- if value, ok := snuo.mutation.ActionLabelDel(); ok {
- _spec.SetField(sopnode.FieldActionLabelDel, field.TypeJSON, value)
- }
- if value, ok := snuo.mutation.AppendedActionLabelDel(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldActionLabelDel, value)
- })
- }
- if snuo.mutation.ActionLabelDelCleared() {
- _spec.ClearField(sopnode.FieldActionLabelDel, field.TypeJSON)
- }
- if value, ok := snuo.mutation.ActionForward(); ok {
- _spec.SetField(sopnode.FieldActionForward, field.TypeJSON, value)
- }
- if snuo.mutation.ActionForwardCleared() {
- _spec.ClearField(sopnode.FieldActionForward, field.TypeJSON)
- }
- if snuo.mutation.SopStageCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: sopnode.SopStageTable,
- Columns: []string{sopnode.SopStageColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := snuo.mutation.SopStageIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: sopnode.SopStageTable,
- Columns: []string{sopnode.SopStageColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if snuo.mutation.NodeMessagesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopnode.NodeMessagesTable,
- Columns: []string{sopnode.NodeMessagesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := snuo.mutation.RemovedNodeMessagesIDs(); len(nodes) > 0 && !snuo.mutation.NodeMessagesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopnode.NodeMessagesTable,
- Columns: []string{sopnode.NodeMessagesColumn},
- 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.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := snuo.mutation.NodeMessagesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopnode.NodeMessagesTable,
- Columns: []string{sopnode.NodeMessagesColumn},
- 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.Add = append(_spec.Edges.Add, edge)
- }
- _node = &SopNode{config: snuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, snuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{sopnode.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- snuo.mutation.done = true
- return _node, nil
- }
|