123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972 |
- // 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
- }
- // 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
- }
- // SetActionLabel sets the "action_label" field.
- func (snu *SopNodeUpdate) SetActionLabel(u []uint64) *SopNodeUpdate {
- snu.mutation.SetActionLabel(u)
- return snu
- }
- // AppendActionLabel appends u to the "action_label" field.
- func (snu *SopNodeUpdate) AppendActionLabel(u []uint64) *SopNodeUpdate {
- snu.mutation.AppendActionLabel(u)
- return snu
- }
- // ClearActionLabel clears the value of the "action_label" field.
- func (snu *SopNodeUpdate) ClearActionLabel() *SopNodeUpdate {
- snu.mutation.ClearActionLabel()
- 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.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.ActionLabel(); ok {
- _spec.SetField(sopnode.FieldActionLabel, field.TypeJSON, value)
- }
- if value, ok := snu.mutation.AppendedActionLabel(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldActionLabel, value)
- })
- }
- if snu.mutation.ActionLabelCleared() {
- _spec.ClearField(sopnode.FieldActionLabel, 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
- }
- // 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
- }
- // SetActionLabel sets the "action_label" field.
- func (snuo *SopNodeUpdateOne) SetActionLabel(u []uint64) *SopNodeUpdateOne {
- snuo.mutation.SetActionLabel(u)
- return snuo
- }
- // AppendActionLabel appends u to the "action_label" field.
- func (snuo *SopNodeUpdateOne) AppendActionLabel(u []uint64) *SopNodeUpdateOne {
- snuo.mutation.AppendActionLabel(u)
- return snuo
- }
- // ClearActionLabel clears the value of the "action_label" field.
- func (snuo *SopNodeUpdateOne) ClearActionLabel() *SopNodeUpdateOne {
- snuo.mutation.ClearActionLabel()
- 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.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.ActionLabel(); ok {
- _spec.SetField(sopnode.FieldActionLabel, field.TypeJSON, value)
- }
- if value, ok := snuo.mutation.AppendedActionLabel(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopnode.FieldActionLabel, value)
- })
- }
- if snuo.mutation.ActionLabelCleared() {
- _spec.ClearField(sopnode.FieldActionLabel, 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
- }
|