123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/custom_types"
- "wechat-api/ent/predicate"
- "wechat-api/ent/sopnode"
- "wechat-api/ent/sopstage"
- "wechat-api/ent/soptask"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/dialect/sql/sqljson"
- "entgo.io/ent/schema/field"
- )
- // SopStageUpdate is the builder for updating SopStage entities.
- type SopStageUpdate struct {
- config
- hooks []Hook
- mutation *SopStageMutation
- }
- // Where appends a list predicates to the SopStageUpdate builder.
- func (ssu *SopStageUpdate) Where(ps ...predicate.SopStage) *SopStageUpdate {
- ssu.mutation.Where(ps...)
- return ssu
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (ssu *SopStageUpdate) SetUpdatedAt(t time.Time) *SopStageUpdate {
- ssu.mutation.SetUpdatedAt(t)
- return ssu
- }
- // SetStatus sets the "status" field.
- func (ssu *SopStageUpdate) SetStatus(u uint8) *SopStageUpdate {
- ssu.mutation.ResetStatus()
- ssu.mutation.SetStatus(u)
- return ssu
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (ssu *SopStageUpdate) SetNillableStatus(u *uint8) *SopStageUpdate {
- if u != nil {
- ssu.SetStatus(*u)
- }
- return ssu
- }
- // AddStatus adds u to the "status" field.
- func (ssu *SopStageUpdate) AddStatus(u int8) *SopStageUpdate {
- ssu.mutation.AddStatus(u)
- return ssu
- }
- // ClearStatus clears the value of the "status" field.
- func (ssu *SopStageUpdate) ClearStatus() *SopStageUpdate {
- ssu.mutation.ClearStatus()
- return ssu
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (ssu *SopStageUpdate) SetDeletedAt(t time.Time) *SopStageUpdate {
- ssu.mutation.SetDeletedAt(t)
- return ssu
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (ssu *SopStageUpdate) SetNillableDeletedAt(t *time.Time) *SopStageUpdate {
- if t != nil {
- ssu.SetDeletedAt(*t)
- }
- return ssu
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (ssu *SopStageUpdate) ClearDeletedAt() *SopStageUpdate {
- ssu.mutation.ClearDeletedAt()
- return ssu
- }
- // SetTaskID sets the "task_id" field.
- func (ssu *SopStageUpdate) SetTaskID(u uint64) *SopStageUpdate {
- ssu.mutation.SetTaskID(u)
- return ssu
- }
- // SetNillableTaskID sets the "task_id" field if the given value is not nil.
- func (ssu *SopStageUpdate) SetNillableTaskID(u *uint64) *SopStageUpdate {
- if u != nil {
- ssu.SetTaskID(*u)
- }
- return ssu
- }
- // SetName sets the "name" field.
- func (ssu *SopStageUpdate) SetName(s string) *SopStageUpdate {
- ssu.mutation.SetName(s)
- return ssu
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (ssu *SopStageUpdate) SetNillableName(s *string) *SopStageUpdate {
- if s != nil {
- ssu.SetName(*s)
- }
- return ssu
- }
- // SetConditionType sets the "condition_type" field.
- func (ssu *SopStageUpdate) SetConditionType(i int) *SopStageUpdate {
- ssu.mutation.ResetConditionType()
- ssu.mutation.SetConditionType(i)
- return ssu
- }
- // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
- func (ssu *SopStageUpdate) SetNillableConditionType(i *int) *SopStageUpdate {
- if i != nil {
- ssu.SetConditionType(*i)
- }
- return ssu
- }
- // AddConditionType adds i to the "condition_type" field.
- func (ssu *SopStageUpdate) AddConditionType(i int) *SopStageUpdate {
- ssu.mutation.AddConditionType(i)
- return ssu
- }
- // SetConditionOperator sets the "condition_operator" field.
- func (ssu *SopStageUpdate) SetConditionOperator(i int) *SopStageUpdate {
- ssu.mutation.ResetConditionOperator()
- ssu.mutation.SetConditionOperator(i)
- return ssu
- }
- // SetNillableConditionOperator sets the "condition_operator" field if the given value is not nil.
- func (ssu *SopStageUpdate) SetNillableConditionOperator(i *int) *SopStageUpdate {
- if i != nil {
- ssu.SetConditionOperator(*i)
- }
- return ssu
- }
- // AddConditionOperator adds i to the "condition_operator" field.
- func (ssu *SopStageUpdate) AddConditionOperator(i int) *SopStageUpdate {
- ssu.mutation.AddConditionOperator(i)
- return ssu
- }
- // SetConditionList sets the "condition_list" field.
- func (ssu *SopStageUpdate) SetConditionList(ct []custom_types.Condition) *SopStageUpdate {
- ssu.mutation.SetConditionList(ct)
- return ssu
- }
- // AppendConditionList appends ct to the "condition_list" field.
- func (ssu *SopStageUpdate) AppendConditionList(ct []custom_types.Condition) *SopStageUpdate {
- ssu.mutation.AppendConditionList(ct)
- return ssu
- }
- // SetActionMessage sets the "action_message" field.
- func (ssu *SopStageUpdate) SetActionMessage(ct []custom_types.Action) *SopStageUpdate {
- ssu.mutation.SetActionMessage(ct)
- return ssu
- }
- // AppendActionMessage appends ct to the "action_message" field.
- func (ssu *SopStageUpdate) AppendActionMessage(ct []custom_types.Action) *SopStageUpdate {
- ssu.mutation.AppendActionMessage(ct)
- return ssu
- }
- // ClearActionMessage clears the value of the "action_message" field.
- func (ssu *SopStageUpdate) ClearActionMessage() *SopStageUpdate {
- ssu.mutation.ClearActionMessage()
- return ssu
- }
- // SetActionLabel sets the "action_label" field.
- func (ssu *SopStageUpdate) SetActionLabel(i []int) *SopStageUpdate {
- ssu.mutation.SetActionLabel(i)
- return ssu
- }
- // AppendActionLabel appends i to the "action_label" field.
- func (ssu *SopStageUpdate) AppendActionLabel(i []int) *SopStageUpdate {
- ssu.mutation.AppendActionLabel(i)
- return ssu
- }
- // ClearActionLabel clears the value of the "action_label" field.
- func (ssu *SopStageUpdate) ClearActionLabel() *SopStageUpdate {
- ssu.mutation.ClearActionLabel()
- return ssu
- }
- // SetIndexSort sets the "index_sort" field.
- func (ssu *SopStageUpdate) SetIndexSort(i int) *SopStageUpdate {
- ssu.mutation.ResetIndexSort()
- ssu.mutation.SetIndexSort(i)
- return ssu
- }
- // SetNillableIndexSort sets the "index_sort" field if the given value is not nil.
- func (ssu *SopStageUpdate) SetNillableIndexSort(i *int) *SopStageUpdate {
- if i != nil {
- ssu.SetIndexSort(*i)
- }
- return ssu
- }
- // AddIndexSort adds i to the "index_sort" field.
- func (ssu *SopStageUpdate) AddIndexSort(i int) *SopStageUpdate {
- ssu.mutation.AddIndexSort(i)
- return ssu
- }
- // ClearIndexSort clears the value of the "index_sort" field.
- func (ssu *SopStageUpdate) ClearIndexSort() *SopStageUpdate {
- ssu.mutation.ClearIndexSort()
- return ssu
- }
- // SetSopTaskID sets the "sop_task" edge to the SopTask entity by ID.
- func (ssu *SopStageUpdate) SetSopTaskID(id uint64) *SopStageUpdate {
- ssu.mutation.SetSopTaskID(id)
- return ssu
- }
- // SetSopTask sets the "sop_task" edge to the SopTask entity.
- func (ssu *SopStageUpdate) SetSopTask(s *SopTask) *SopStageUpdate {
- return ssu.SetSopTaskID(s.ID)
- }
- // AddStageNodeIDs adds the "stage_nodes" edge to the SopNode entity by IDs.
- func (ssu *SopStageUpdate) AddStageNodeIDs(ids ...uint64) *SopStageUpdate {
- ssu.mutation.AddStageNodeIDs(ids...)
- return ssu
- }
- // AddStageNodes adds the "stage_nodes" edges to the SopNode entity.
- func (ssu *SopStageUpdate) AddStageNodes(s ...*SopNode) *SopStageUpdate {
- ids := make([]uint64, len(s))
- for i := range s {
- ids[i] = s[i].ID
- }
- return ssu.AddStageNodeIDs(ids...)
- }
- // Mutation returns the SopStageMutation object of the builder.
- func (ssu *SopStageUpdate) Mutation() *SopStageMutation {
- return ssu.mutation
- }
- // ClearSopTask clears the "sop_task" edge to the SopTask entity.
- func (ssu *SopStageUpdate) ClearSopTask() *SopStageUpdate {
- ssu.mutation.ClearSopTask()
- return ssu
- }
- // ClearStageNodes clears all "stage_nodes" edges to the SopNode entity.
- func (ssu *SopStageUpdate) ClearStageNodes() *SopStageUpdate {
- ssu.mutation.ClearStageNodes()
- return ssu
- }
- // RemoveStageNodeIDs removes the "stage_nodes" edge to SopNode entities by IDs.
- func (ssu *SopStageUpdate) RemoveStageNodeIDs(ids ...uint64) *SopStageUpdate {
- ssu.mutation.RemoveStageNodeIDs(ids...)
- return ssu
- }
- // RemoveStageNodes removes "stage_nodes" edges to SopNode entities.
- func (ssu *SopStageUpdate) RemoveStageNodes(s ...*SopNode) *SopStageUpdate {
- ids := make([]uint64, len(s))
- for i := range s {
- ids[i] = s[i].ID
- }
- return ssu.RemoveStageNodeIDs(ids...)
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (ssu *SopStageUpdate) Save(ctx context.Context) (int, error) {
- if err := ssu.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, ssu.sqlSave, ssu.mutation, ssu.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (ssu *SopStageUpdate) SaveX(ctx context.Context) int {
- affected, err := ssu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (ssu *SopStageUpdate) Exec(ctx context.Context) error {
- _, err := ssu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (ssu *SopStageUpdate) ExecX(ctx context.Context) {
- if err := ssu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (ssu *SopStageUpdate) defaults() error {
- if _, ok := ssu.mutation.UpdatedAt(); !ok {
- if sopstage.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized sopstage.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := sopstage.UpdateDefaultUpdatedAt()
- ssu.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (ssu *SopStageUpdate) check() error {
- if _, ok := ssu.mutation.SopTaskID(); ssu.mutation.SopTaskCleared() && !ok {
- return errors.New(`ent: clearing a required unique edge "SopStage.sop_task"`)
- }
- return nil
- }
- func (ssu *SopStageUpdate) sqlSave(ctx context.Context) (n int, err error) {
- if err := ssu.check(); err != nil {
- return n, err
- }
- _spec := sqlgraph.NewUpdateSpec(sopstage.Table, sopstage.Columns, sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64))
- if ps := ssu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := ssu.mutation.UpdatedAt(); ok {
- _spec.SetField(sopstage.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := ssu.mutation.Status(); ok {
- _spec.SetField(sopstage.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := ssu.mutation.AddedStatus(); ok {
- _spec.AddField(sopstage.FieldStatus, field.TypeUint8, value)
- }
- if ssu.mutation.StatusCleared() {
- _spec.ClearField(sopstage.FieldStatus, field.TypeUint8)
- }
- if value, ok := ssu.mutation.DeletedAt(); ok {
- _spec.SetField(sopstage.FieldDeletedAt, field.TypeTime, value)
- }
- if ssu.mutation.DeletedAtCleared() {
- _spec.ClearField(sopstage.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := ssu.mutation.Name(); ok {
- _spec.SetField(sopstage.FieldName, field.TypeString, value)
- }
- if value, ok := ssu.mutation.ConditionType(); ok {
- _spec.SetField(sopstage.FieldConditionType, field.TypeInt, value)
- }
- if value, ok := ssu.mutation.AddedConditionType(); ok {
- _spec.AddField(sopstage.FieldConditionType, field.TypeInt, value)
- }
- if value, ok := ssu.mutation.ConditionOperator(); ok {
- _spec.SetField(sopstage.FieldConditionOperator, field.TypeInt, value)
- }
- if value, ok := ssu.mutation.AddedConditionOperator(); ok {
- _spec.AddField(sopstage.FieldConditionOperator, field.TypeInt, value)
- }
- if value, ok := ssu.mutation.ConditionList(); ok {
- _spec.SetField(sopstage.FieldConditionList, field.TypeJSON, value)
- }
- if value, ok := ssu.mutation.AppendedConditionList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopstage.FieldConditionList, value)
- })
- }
- if value, ok := ssu.mutation.ActionMessage(); ok {
- _spec.SetField(sopstage.FieldActionMessage, field.TypeJSON, value)
- }
- if value, ok := ssu.mutation.AppendedActionMessage(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopstage.FieldActionMessage, value)
- })
- }
- if ssu.mutation.ActionMessageCleared() {
- _spec.ClearField(sopstage.FieldActionMessage, field.TypeJSON)
- }
- if value, ok := ssu.mutation.ActionLabel(); ok {
- _spec.SetField(sopstage.FieldActionLabel, field.TypeJSON, value)
- }
- if value, ok := ssu.mutation.AppendedActionLabel(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopstage.FieldActionLabel, value)
- })
- }
- if ssu.mutation.ActionLabelCleared() {
- _spec.ClearField(sopstage.FieldActionLabel, field.TypeJSON)
- }
- if value, ok := ssu.mutation.IndexSort(); ok {
- _spec.SetField(sopstage.FieldIndexSort, field.TypeInt, value)
- }
- if value, ok := ssu.mutation.AddedIndexSort(); ok {
- _spec.AddField(sopstage.FieldIndexSort, field.TypeInt, value)
- }
- if ssu.mutation.IndexSortCleared() {
- _spec.ClearField(sopstage.FieldIndexSort, field.TypeInt)
- }
- if ssu.mutation.SopTaskCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: sopstage.SopTaskTable,
- Columns: []string{sopstage.SopTaskColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := ssu.mutation.SopTaskIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: sopstage.SopTaskTable,
- Columns: []string{sopstage.SopTaskColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if ssu.mutation.StageNodesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopstage.StageNodesTable,
- Columns: []string{sopstage.StageNodesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := ssu.mutation.RemovedStageNodesIDs(); len(nodes) > 0 && !ssu.mutation.StageNodesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopstage.StageNodesTable,
- Columns: []string{sopstage.StageNodesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.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 := ssu.mutation.StageNodesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopstage.StageNodesTable,
- Columns: []string{sopstage.StageNodesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.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, ssu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{sopstage.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- ssu.mutation.done = true
- return n, nil
- }
- // SopStageUpdateOne is the builder for updating a single SopStage entity.
- type SopStageUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *SopStageMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (ssuo *SopStageUpdateOne) SetUpdatedAt(t time.Time) *SopStageUpdateOne {
- ssuo.mutation.SetUpdatedAt(t)
- return ssuo
- }
- // SetStatus sets the "status" field.
- func (ssuo *SopStageUpdateOne) SetStatus(u uint8) *SopStageUpdateOne {
- ssuo.mutation.ResetStatus()
- ssuo.mutation.SetStatus(u)
- return ssuo
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (ssuo *SopStageUpdateOne) SetNillableStatus(u *uint8) *SopStageUpdateOne {
- if u != nil {
- ssuo.SetStatus(*u)
- }
- return ssuo
- }
- // AddStatus adds u to the "status" field.
- func (ssuo *SopStageUpdateOne) AddStatus(u int8) *SopStageUpdateOne {
- ssuo.mutation.AddStatus(u)
- return ssuo
- }
- // ClearStatus clears the value of the "status" field.
- func (ssuo *SopStageUpdateOne) ClearStatus() *SopStageUpdateOne {
- ssuo.mutation.ClearStatus()
- return ssuo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (ssuo *SopStageUpdateOne) SetDeletedAt(t time.Time) *SopStageUpdateOne {
- ssuo.mutation.SetDeletedAt(t)
- return ssuo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (ssuo *SopStageUpdateOne) SetNillableDeletedAt(t *time.Time) *SopStageUpdateOne {
- if t != nil {
- ssuo.SetDeletedAt(*t)
- }
- return ssuo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (ssuo *SopStageUpdateOne) ClearDeletedAt() *SopStageUpdateOne {
- ssuo.mutation.ClearDeletedAt()
- return ssuo
- }
- // SetTaskID sets the "task_id" field.
- func (ssuo *SopStageUpdateOne) SetTaskID(u uint64) *SopStageUpdateOne {
- ssuo.mutation.SetTaskID(u)
- return ssuo
- }
- // SetNillableTaskID sets the "task_id" field if the given value is not nil.
- func (ssuo *SopStageUpdateOne) SetNillableTaskID(u *uint64) *SopStageUpdateOne {
- if u != nil {
- ssuo.SetTaskID(*u)
- }
- return ssuo
- }
- // SetName sets the "name" field.
- func (ssuo *SopStageUpdateOne) SetName(s string) *SopStageUpdateOne {
- ssuo.mutation.SetName(s)
- return ssuo
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (ssuo *SopStageUpdateOne) SetNillableName(s *string) *SopStageUpdateOne {
- if s != nil {
- ssuo.SetName(*s)
- }
- return ssuo
- }
- // SetConditionType sets the "condition_type" field.
- func (ssuo *SopStageUpdateOne) SetConditionType(i int) *SopStageUpdateOne {
- ssuo.mutation.ResetConditionType()
- ssuo.mutation.SetConditionType(i)
- return ssuo
- }
- // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
- func (ssuo *SopStageUpdateOne) SetNillableConditionType(i *int) *SopStageUpdateOne {
- if i != nil {
- ssuo.SetConditionType(*i)
- }
- return ssuo
- }
- // AddConditionType adds i to the "condition_type" field.
- func (ssuo *SopStageUpdateOne) AddConditionType(i int) *SopStageUpdateOne {
- ssuo.mutation.AddConditionType(i)
- return ssuo
- }
- // SetConditionOperator sets the "condition_operator" field.
- func (ssuo *SopStageUpdateOne) SetConditionOperator(i int) *SopStageUpdateOne {
- ssuo.mutation.ResetConditionOperator()
- ssuo.mutation.SetConditionOperator(i)
- return ssuo
- }
- // SetNillableConditionOperator sets the "condition_operator" field if the given value is not nil.
- func (ssuo *SopStageUpdateOne) SetNillableConditionOperator(i *int) *SopStageUpdateOne {
- if i != nil {
- ssuo.SetConditionOperator(*i)
- }
- return ssuo
- }
- // AddConditionOperator adds i to the "condition_operator" field.
- func (ssuo *SopStageUpdateOne) AddConditionOperator(i int) *SopStageUpdateOne {
- ssuo.mutation.AddConditionOperator(i)
- return ssuo
- }
- // SetConditionList sets the "condition_list" field.
- func (ssuo *SopStageUpdateOne) SetConditionList(ct []custom_types.Condition) *SopStageUpdateOne {
- ssuo.mutation.SetConditionList(ct)
- return ssuo
- }
- // AppendConditionList appends ct to the "condition_list" field.
- func (ssuo *SopStageUpdateOne) AppendConditionList(ct []custom_types.Condition) *SopStageUpdateOne {
- ssuo.mutation.AppendConditionList(ct)
- return ssuo
- }
- // SetActionMessage sets the "action_message" field.
- func (ssuo *SopStageUpdateOne) SetActionMessage(ct []custom_types.Action) *SopStageUpdateOne {
- ssuo.mutation.SetActionMessage(ct)
- return ssuo
- }
- // AppendActionMessage appends ct to the "action_message" field.
- func (ssuo *SopStageUpdateOne) AppendActionMessage(ct []custom_types.Action) *SopStageUpdateOne {
- ssuo.mutation.AppendActionMessage(ct)
- return ssuo
- }
- // ClearActionMessage clears the value of the "action_message" field.
- func (ssuo *SopStageUpdateOne) ClearActionMessage() *SopStageUpdateOne {
- ssuo.mutation.ClearActionMessage()
- return ssuo
- }
- // SetActionLabel sets the "action_label" field.
- func (ssuo *SopStageUpdateOne) SetActionLabel(i []int) *SopStageUpdateOne {
- ssuo.mutation.SetActionLabel(i)
- return ssuo
- }
- // AppendActionLabel appends i to the "action_label" field.
- func (ssuo *SopStageUpdateOne) AppendActionLabel(i []int) *SopStageUpdateOne {
- ssuo.mutation.AppendActionLabel(i)
- return ssuo
- }
- // ClearActionLabel clears the value of the "action_label" field.
- func (ssuo *SopStageUpdateOne) ClearActionLabel() *SopStageUpdateOne {
- ssuo.mutation.ClearActionLabel()
- return ssuo
- }
- // SetIndexSort sets the "index_sort" field.
- func (ssuo *SopStageUpdateOne) SetIndexSort(i int) *SopStageUpdateOne {
- ssuo.mutation.ResetIndexSort()
- ssuo.mutation.SetIndexSort(i)
- return ssuo
- }
- // SetNillableIndexSort sets the "index_sort" field if the given value is not nil.
- func (ssuo *SopStageUpdateOne) SetNillableIndexSort(i *int) *SopStageUpdateOne {
- if i != nil {
- ssuo.SetIndexSort(*i)
- }
- return ssuo
- }
- // AddIndexSort adds i to the "index_sort" field.
- func (ssuo *SopStageUpdateOne) AddIndexSort(i int) *SopStageUpdateOne {
- ssuo.mutation.AddIndexSort(i)
- return ssuo
- }
- // ClearIndexSort clears the value of the "index_sort" field.
- func (ssuo *SopStageUpdateOne) ClearIndexSort() *SopStageUpdateOne {
- ssuo.mutation.ClearIndexSort()
- return ssuo
- }
- // SetSopTaskID sets the "sop_task" edge to the SopTask entity by ID.
- func (ssuo *SopStageUpdateOne) SetSopTaskID(id uint64) *SopStageUpdateOne {
- ssuo.mutation.SetSopTaskID(id)
- return ssuo
- }
- // SetSopTask sets the "sop_task" edge to the SopTask entity.
- func (ssuo *SopStageUpdateOne) SetSopTask(s *SopTask) *SopStageUpdateOne {
- return ssuo.SetSopTaskID(s.ID)
- }
- // AddStageNodeIDs adds the "stage_nodes" edge to the SopNode entity by IDs.
- func (ssuo *SopStageUpdateOne) AddStageNodeIDs(ids ...uint64) *SopStageUpdateOne {
- ssuo.mutation.AddStageNodeIDs(ids...)
- return ssuo
- }
- // AddStageNodes adds the "stage_nodes" edges to the SopNode entity.
- func (ssuo *SopStageUpdateOne) AddStageNodes(s ...*SopNode) *SopStageUpdateOne {
- ids := make([]uint64, len(s))
- for i := range s {
- ids[i] = s[i].ID
- }
- return ssuo.AddStageNodeIDs(ids...)
- }
- // Mutation returns the SopStageMutation object of the builder.
- func (ssuo *SopStageUpdateOne) Mutation() *SopStageMutation {
- return ssuo.mutation
- }
- // ClearSopTask clears the "sop_task" edge to the SopTask entity.
- func (ssuo *SopStageUpdateOne) ClearSopTask() *SopStageUpdateOne {
- ssuo.mutation.ClearSopTask()
- return ssuo
- }
- // ClearStageNodes clears all "stage_nodes" edges to the SopNode entity.
- func (ssuo *SopStageUpdateOne) ClearStageNodes() *SopStageUpdateOne {
- ssuo.mutation.ClearStageNodes()
- return ssuo
- }
- // RemoveStageNodeIDs removes the "stage_nodes" edge to SopNode entities by IDs.
- func (ssuo *SopStageUpdateOne) RemoveStageNodeIDs(ids ...uint64) *SopStageUpdateOne {
- ssuo.mutation.RemoveStageNodeIDs(ids...)
- return ssuo
- }
- // RemoveStageNodes removes "stage_nodes" edges to SopNode entities.
- func (ssuo *SopStageUpdateOne) RemoveStageNodes(s ...*SopNode) *SopStageUpdateOne {
- ids := make([]uint64, len(s))
- for i := range s {
- ids[i] = s[i].ID
- }
- return ssuo.RemoveStageNodeIDs(ids...)
- }
- // Where appends a list predicates to the SopStageUpdate builder.
- func (ssuo *SopStageUpdateOne) Where(ps ...predicate.SopStage) *SopStageUpdateOne {
- ssuo.mutation.Where(ps...)
- return ssuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (ssuo *SopStageUpdateOne) Select(field string, fields ...string) *SopStageUpdateOne {
- ssuo.fields = append([]string{field}, fields...)
- return ssuo
- }
- // Save executes the query and returns the updated SopStage entity.
- func (ssuo *SopStageUpdateOne) Save(ctx context.Context) (*SopStage, error) {
- if err := ssuo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, ssuo.sqlSave, ssuo.mutation, ssuo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (ssuo *SopStageUpdateOne) SaveX(ctx context.Context) *SopStage {
- node, err := ssuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (ssuo *SopStageUpdateOne) Exec(ctx context.Context) error {
- _, err := ssuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (ssuo *SopStageUpdateOne) ExecX(ctx context.Context) {
- if err := ssuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (ssuo *SopStageUpdateOne) defaults() error {
- if _, ok := ssuo.mutation.UpdatedAt(); !ok {
- if sopstage.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized sopstage.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := sopstage.UpdateDefaultUpdatedAt()
- ssuo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (ssuo *SopStageUpdateOne) check() error {
- if _, ok := ssuo.mutation.SopTaskID(); ssuo.mutation.SopTaskCleared() && !ok {
- return errors.New(`ent: clearing a required unique edge "SopStage.sop_task"`)
- }
- return nil
- }
- func (ssuo *SopStageUpdateOne) sqlSave(ctx context.Context) (_node *SopStage, err error) {
- if err := ssuo.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(sopstage.Table, sopstage.Columns, sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64))
- id, ok := ssuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SopStage.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := ssuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, sopstage.FieldID)
- for _, f := range fields {
- if !sopstage.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != sopstage.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := ssuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := ssuo.mutation.UpdatedAt(); ok {
- _spec.SetField(sopstage.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := ssuo.mutation.Status(); ok {
- _spec.SetField(sopstage.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := ssuo.mutation.AddedStatus(); ok {
- _spec.AddField(sopstage.FieldStatus, field.TypeUint8, value)
- }
- if ssuo.mutation.StatusCleared() {
- _spec.ClearField(sopstage.FieldStatus, field.TypeUint8)
- }
- if value, ok := ssuo.mutation.DeletedAt(); ok {
- _spec.SetField(sopstage.FieldDeletedAt, field.TypeTime, value)
- }
- if ssuo.mutation.DeletedAtCleared() {
- _spec.ClearField(sopstage.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := ssuo.mutation.Name(); ok {
- _spec.SetField(sopstage.FieldName, field.TypeString, value)
- }
- if value, ok := ssuo.mutation.ConditionType(); ok {
- _spec.SetField(sopstage.FieldConditionType, field.TypeInt, value)
- }
- if value, ok := ssuo.mutation.AddedConditionType(); ok {
- _spec.AddField(sopstage.FieldConditionType, field.TypeInt, value)
- }
- if value, ok := ssuo.mutation.ConditionOperator(); ok {
- _spec.SetField(sopstage.FieldConditionOperator, field.TypeInt, value)
- }
- if value, ok := ssuo.mutation.AddedConditionOperator(); ok {
- _spec.AddField(sopstage.FieldConditionOperator, field.TypeInt, value)
- }
- if value, ok := ssuo.mutation.ConditionList(); ok {
- _spec.SetField(sopstage.FieldConditionList, field.TypeJSON, value)
- }
- if value, ok := ssuo.mutation.AppendedConditionList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopstage.FieldConditionList, value)
- })
- }
- if value, ok := ssuo.mutation.ActionMessage(); ok {
- _spec.SetField(sopstage.FieldActionMessage, field.TypeJSON, value)
- }
- if value, ok := ssuo.mutation.AppendedActionMessage(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopstage.FieldActionMessage, value)
- })
- }
- if ssuo.mutation.ActionMessageCleared() {
- _spec.ClearField(sopstage.FieldActionMessage, field.TypeJSON)
- }
- if value, ok := ssuo.mutation.ActionLabel(); ok {
- _spec.SetField(sopstage.FieldActionLabel, field.TypeJSON, value)
- }
- if value, ok := ssuo.mutation.AppendedActionLabel(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, sopstage.FieldActionLabel, value)
- })
- }
- if ssuo.mutation.ActionLabelCleared() {
- _spec.ClearField(sopstage.FieldActionLabel, field.TypeJSON)
- }
- if value, ok := ssuo.mutation.IndexSort(); ok {
- _spec.SetField(sopstage.FieldIndexSort, field.TypeInt, value)
- }
- if value, ok := ssuo.mutation.AddedIndexSort(); ok {
- _spec.AddField(sopstage.FieldIndexSort, field.TypeInt, value)
- }
- if ssuo.mutation.IndexSortCleared() {
- _spec.ClearField(sopstage.FieldIndexSort, field.TypeInt)
- }
- if ssuo.mutation.SopTaskCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: sopstage.SopTaskTable,
- Columns: []string{sopstage.SopTaskColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := ssuo.mutation.SopTaskIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: sopstage.SopTaskTable,
- Columns: []string{sopstage.SopTaskColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if ssuo.mutation.StageNodesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopstage.StageNodesTable,
- Columns: []string{sopstage.StageNodesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := ssuo.mutation.RemovedStageNodesIDs(); len(nodes) > 0 && !ssuo.mutation.StageNodesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopstage.StageNodesTable,
- Columns: []string{sopstage.StageNodesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.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 := ssuo.mutation.StageNodesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: sopstage.StageNodesTable,
- Columns: []string{sopstage.StageNodesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &SopStage{config: ssuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, ssuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{sopstage.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- ssuo.mutation.done = true
- return _node, nil
- }
|