| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/Wei-Shaw/sub2api/ent/channelmonitor"
- "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- "github.com/Wei-Shaw/sub2api/internal/domain"
- )
- // ChannelMonitorHistoryUpdate is the builder for updating ChannelMonitorHistory entities.
- type ChannelMonitorHistoryUpdate struct {
- config
- hooks []Hook
- mutation *ChannelMonitorHistoryMutation
- }
- // Where appends a list predicates to the ChannelMonitorHistoryUpdate builder.
- func (_u *ChannelMonitorHistoryUpdate) Where(ps ...predicate.ChannelMonitorHistory) *ChannelMonitorHistoryUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetMonitorID sets the "monitor_id" field.
- func (_u *ChannelMonitorHistoryUpdate) SetMonitorID(v int64) *ChannelMonitorHistoryUpdate {
- _u.mutation.SetMonitorID(v)
- return _u
- }
- // SetNillableMonitorID sets the "monitor_id" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdate) SetNillableMonitorID(v *int64) *ChannelMonitorHistoryUpdate {
- if v != nil {
- _u.SetMonitorID(*v)
- }
- return _u
- }
- // SetModel sets the "model" field.
- func (_u *ChannelMonitorHistoryUpdate) SetModel(v string) *ChannelMonitorHistoryUpdate {
- _u.mutation.SetModel(v)
- return _u
- }
- // SetNillableModel sets the "model" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdate) SetNillableModel(v *string) *ChannelMonitorHistoryUpdate {
- if v != nil {
- _u.SetModel(*v)
- }
- return _u
- }
- // SetStatus sets the "status" field.
- func (_u *ChannelMonitorHistoryUpdate) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpdate {
- _u.mutation.SetStatus(v)
- return _u
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdate) SetNillableStatus(v *channelmonitorhistory.Status) *ChannelMonitorHistoryUpdate {
- if v != nil {
- _u.SetStatus(*v)
- }
- return _u
- }
- // SetLatencyMs sets the "latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdate) SetLatencyMs(v int) *ChannelMonitorHistoryUpdate {
- _u.mutation.ResetLatencyMs()
- _u.mutation.SetLatencyMs(v)
- return _u
- }
- // SetNillableLatencyMs sets the "latency_ms" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdate) SetNillableLatencyMs(v *int) *ChannelMonitorHistoryUpdate {
- if v != nil {
- _u.SetLatencyMs(*v)
- }
- return _u
- }
- // AddLatencyMs adds value to the "latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdate) AddLatencyMs(v int) *ChannelMonitorHistoryUpdate {
- _u.mutation.AddLatencyMs(v)
- return _u
- }
- // ClearLatencyMs clears the value of the "latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdate) ClearLatencyMs() *ChannelMonitorHistoryUpdate {
- _u.mutation.ClearLatencyMs()
- return _u
- }
- // SetPingLatencyMs sets the "ping_latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdate) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpdate {
- _u.mutation.ResetPingLatencyMs()
- _u.mutation.SetPingLatencyMs(v)
- return _u
- }
- // SetNillablePingLatencyMs sets the "ping_latency_ms" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdate) SetNillablePingLatencyMs(v *int) *ChannelMonitorHistoryUpdate {
- if v != nil {
- _u.SetPingLatencyMs(*v)
- }
- return _u
- }
- // AddPingLatencyMs adds value to the "ping_latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdate) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpdate {
- _u.mutation.AddPingLatencyMs(v)
- return _u
- }
- // ClearPingLatencyMs clears the value of the "ping_latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdate) ClearPingLatencyMs() *ChannelMonitorHistoryUpdate {
- _u.mutation.ClearPingLatencyMs()
- return _u
- }
- // SetMessage sets the "message" field.
- func (_u *ChannelMonitorHistoryUpdate) SetMessage(v string) *ChannelMonitorHistoryUpdate {
- _u.mutation.SetMessage(v)
- return _u
- }
- // SetNillableMessage sets the "message" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdate) SetNillableMessage(v *string) *ChannelMonitorHistoryUpdate {
- if v != nil {
- _u.SetMessage(*v)
- }
- return _u
- }
- // ClearMessage clears the value of the "message" field.
- func (_u *ChannelMonitorHistoryUpdate) ClearMessage() *ChannelMonitorHistoryUpdate {
- _u.mutation.ClearMessage()
- return _u
- }
- // SetQuota sets the "quota" field.
- func (_u *ChannelMonitorHistoryUpdate) SetQuota(v *domain.MonitorQuotaSnapshot) *ChannelMonitorHistoryUpdate {
- _u.mutation.SetQuota(v)
- return _u
- }
- // ClearQuota clears the value of the "quota" field.
- func (_u *ChannelMonitorHistoryUpdate) ClearQuota() *ChannelMonitorHistoryUpdate {
- _u.mutation.ClearQuota()
- return _u
- }
- // SetCheckedAt sets the "checked_at" field.
- func (_u *ChannelMonitorHistoryUpdate) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpdate {
- _u.mutation.SetCheckedAt(v)
- return _u
- }
- // SetNillableCheckedAt sets the "checked_at" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdate) SetNillableCheckedAt(v *time.Time) *ChannelMonitorHistoryUpdate {
- if v != nil {
- _u.SetCheckedAt(*v)
- }
- return _u
- }
- // SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
- func (_u *ChannelMonitorHistoryUpdate) SetMonitor(v *ChannelMonitor) *ChannelMonitorHistoryUpdate {
- return _u.SetMonitorID(v.ID)
- }
- // Mutation returns the ChannelMonitorHistoryMutation object of the builder.
- func (_u *ChannelMonitorHistoryUpdate) Mutation() *ChannelMonitorHistoryMutation {
- return _u.mutation
- }
- // ClearMonitor clears the "monitor" edge to the ChannelMonitor entity.
- func (_u *ChannelMonitorHistoryUpdate) ClearMonitor() *ChannelMonitorHistoryUpdate {
- _u.mutation.ClearMonitor()
- return _u
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *ChannelMonitorHistoryUpdate) Save(ctx context.Context) (int, error) {
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ChannelMonitorHistoryUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *ChannelMonitorHistoryUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ChannelMonitorHistoryUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ChannelMonitorHistoryUpdate) check() error {
- if v, ok := _u.mutation.Model(); ok {
- if err := channelmonitorhistory.ModelValidator(v); err != nil {
- return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.model": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Status(); ok {
- if err := channelmonitorhistory.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.status": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Message(); ok {
- if err := channelmonitorhistory.MessageValidator(v); err != nil {
- return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.message": %w`, err)}
- }
- }
- if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "ChannelMonitorHistory.monitor"`)
- }
- return nil
- }
- func (_u *ChannelMonitorHistoryUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(channelmonitorhistory.Table, channelmonitorhistory.Columns, sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64))
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.Model(); ok {
- _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value)
- }
- if value, ok := _u.mutation.Status(); ok {
- _spec.SetField(channelmonitorhistory.FieldStatus, field.TypeEnum, value)
- }
- if value, ok := _u.mutation.LatencyMs(); ok {
- _spec.SetField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedLatencyMs(); ok {
- _spec.AddField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
- }
- if _u.mutation.LatencyMsCleared() {
- _spec.ClearField(channelmonitorhistory.FieldLatencyMs, field.TypeInt)
- }
- if value, ok := _u.mutation.PingLatencyMs(); ok {
- _spec.SetField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedPingLatencyMs(); ok {
- _spec.AddField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
- }
- if _u.mutation.PingLatencyMsCleared() {
- _spec.ClearField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt)
- }
- if value, ok := _u.mutation.Message(); ok {
- _spec.SetField(channelmonitorhistory.FieldMessage, field.TypeString, value)
- }
- if _u.mutation.MessageCleared() {
- _spec.ClearField(channelmonitorhistory.FieldMessage, field.TypeString)
- }
- if value, ok := _u.mutation.Quota(); ok {
- _spec.SetField(channelmonitorhistory.FieldQuota, field.TypeJSON, value)
- }
- if _u.mutation.QuotaCleared() {
- _spec.ClearField(channelmonitorhistory.FieldQuota, field.TypeJSON)
- }
- if value, ok := _u.mutation.CheckedAt(); ok {
- _spec.SetField(channelmonitorhistory.FieldCheckedAt, field.TypeTime, value)
- }
- if _u.mutation.MonitorCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: channelmonitorhistory.MonitorTable,
- Columns: []string{channelmonitorhistory.MonitorColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.MonitorIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: channelmonitorhistory.MonitorTable,
- Columns: []string{channelmonitorhistory.MonitorColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{channelmonitorhistory.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // ChannelMonitorHistoryUpdateOne is the builder for updating a single ChannelMonitorHistory entity.
- type ChannelMonitorHistoryUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *ChannelMonitorHistoryMutation
- }
- // SetMonitorID sets the "monitor_id" field.
- func (_u *ChannelMonitorHistoryUpdateOne) SetMonitorID(v int64) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.SetMonitorID(v)
- return _u
- }
- // SetNillableMonitorID sets the "monitor_id" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdateOne) SetNillableMonitorID(v *int64) *ChannelMonitorHistoryUpdateOne {
- if v != nil {
- _u.SetMonitorID(*v)
- }
- return _u
- }
- // SetModel sets the "model" field.
- func (_u *ChannelMonitorHistoryUpdateOne) SetModel(v string) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.SetModel(v)
- return _u
- }
- // SetNillableModel sets the "model" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdateOne) SetNillableModel(v *string) *ChannelMonitorHistoryUpdateOne {
- if v != nil {
- _u.SetModel(*v)
- }
- return _u
- }
- // SetStatus sets the "status" field.
- func (_u *ChannelMonitorHistoryUpdateOne) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.SetStatus(v)
- return _u
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdateOne) SetNillableStatus(v *channelmonitorhistory.Status) *ChannelMonitorHistoryUpdateOne {
- if v != nil {
- _u.SetStatus(*v)
- }
- return _u
- }
- // SetLatencyMs sets the "latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdateOne) SetLatencyMs(v int) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.ResetLatencyMs()
- _u.mutation.SetLatencyMs(v)
- return _u
- }
- // SetNillableLatencyMs sets the "latency_ms" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdateOne) SetNillableLatencyMs(v *int) *ChannelMonitorHistoryUpdateOne {
- if v != nil {
- _u.SetLatencyMs(*v)
- }
- return _u
- }
- // AddLatencyMs adds value to the "latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdateOne) AddLatencyMs(v int) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.AddLatencyMs(v)
- return _u
- }
- // ClearLatencyMs clears the value of the "latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdateOne) ClearLatencyMs() *ChannelMonitorHistoryUpdateOne {
- _u.mutation.ClearLatencyMs()
- return _u
- }
- // SetPingLatencyMs sets the "ping_latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdateOne) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.ResetPingLatencyMs()
- _u.mutation.SetPingLatencyMs(v)
- return _u
- }
- // SetNillablePingLatencyMs sets the "ping_latency_ms" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdateOne) SetNillablePingLatencyMs(v *int) *ChannelMonitorHistoryUpdateOne {
- if v != nil {
- _u.SetPingLatencyMs(*v)
- }
- return _u
- }
- // AddPingLatencyMs adds value to the "ping_latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdateOne) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.AddPingLatencyMs(v)
- return _u
- }
- // ClearPingLatencyMs clears the value of the "ping_latency_ms" field.
- func (_u *ChannelMonitorHistoryUpdateOne) ClearPingLatencyMs() *ChannelMonitorHistoryUpdateOne {
- _u.mutation.ClearPingLatencyMs()
- return _u
- }
- // SetMessage sets the "message" field.
- func (_u *ChannelMonitorHistoryUpdateOne) SetMessage(v string) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.SetMessage(v)
- return _u
- }
- // SetNillableMessage sets the "message" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdateOne) SetNillableMessage(v *string) *ChannelMonitorHistoryUpdateOne {
- if v != nil {
- _u.SetMessage(*v)
- }
- return _u
- }
- // ClearMessage clears the value of the "message" field.
- func (_u *ChannelMonitorHistoryUpdateOne) ClearMessage() *ChannelMonitorHistoryUpdateOne {
- _u.mutation.ClearMessage()
- return _u
- }
- // SetQuota sets the "quota" field.
- func (_u *ChannelMonitorHistoryUpdateOne) SetQuota(v *domain.MonitorQuotaSnapshot) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.SetQuota(v)
- return _u
- }
- // ClearQuota clears the value of the "quota" field.
- func (_u *ChannelMonitorHistoryUpdateOne) ClearQuota() *ChannelMonitorHistoryUpdateOne {
- _u.mutation.ClearQuota()
- return _u
- }
- // SetCheckedAt sets the "checked_at" field.
- func (_u *ChannelMonitorHistoryUpdateOne) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.SetCheckedAt(v)
- return _u
- }
- // SetNillableCheckedAt sets the "checked_at" field if the given value is not nil.
- func (_u *ChannelMonitorHistoryUpdateOne) SetNillableCheckedAt(v *time.Time) *ChannelMonitorHistoryUpdateOne {
- if v != nil {
- _u.SetCheckedAt(*v)
- }
- return _u
- }
- // SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
- func (_u *ChannelMonitorHistoryUpdateOne) SetMonitor(v *ChannelMonitor) *ChannelMonitorHistoryUpdateOne {
- return _u.SetMonitorID(v.ID)
- }
- // Mutation returns the ChannelMonitorHistoryMutation object of the builder.
- func (_u *ChannelMonitorHistoryUpdateOne) Mutation() *ChannelMonitorHistoryMutation {
- return _u.mutation
- }
- // ClearMonitor clears the "monitor" edge to the ChannelMonitor entity.
- func (_u *ChannelMonitorHistoryUpdateOne) ClearMonitor() *ChannelMonitorHistoryUpdateOne {
- _u.mutation.ClearMonitor()
- return _u
- }
- // Where appends a list predicates to the ChannelMonitorHistoryUpdate builder.
- func (_u *ChannelMonitorHistoryUpdateOne) Where(ps ...predicate.ChannelMonitorHistory) *ChannelMonitorHistoryUpdateOne {
- _u.mutation.Where(ps...)
- return _u
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (_u *ChannelMonitorHistoryUpdateOne) Select(field string, fields ...string) *ChannelMonitorHistoryUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated ChannelMonitorHistory entity.
- func (_u *ChannelMonitorHistoryUpdateOne) Save(ctx context.Context) (*ChannelMonitorHistory, error) {
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ChannelMonitorHistoryUpdateOne) SaveX(ctx context.Context) *ChannelMonitorHistory {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *ChannelMonitorHistoryUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ChannelMonitorHistoryUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ChannelMonitorHistoryUpdateOne) check() error {
- if v, ok := _u.mutation.Model(); ok {
- if err := channelmonitorhistory.ModelValidator(v); err != nil {
- return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.model": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Status(); ok {
- if err := channelmonitorhistory.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.status": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Message(); ok {
- if err := channelmonitorhistory.MessageValidator(v); err != nil {
- return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.message": %w`, err)}
- }
- }
- if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "ChannelMonitorHistory.monitor"`)
- }
- return nil
- }
- func (_u *ChannelMonitorHistoryUpdateOne) sqlSave(ctx context.Context) (_node *ChannelMonitorHistory, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(channelmonitorhistory.Table, channelmonitorhistory.Columns, sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChannelMonitorHistory.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := _u.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, channelmonitorhistory.FieldID)
- for _, f := range fields {
- if !channelmonitorhistory.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != channelmonitorhistory.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.Model(); ok {
- _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value)
- }
- if value, ok := _u.mutation.Status(); ok {
- _spec.SetField(channelmonitorhistory.FieldStatus, field.TypeEnum, value)
- }
- if value, ok := _u.mutation.LatencyMs(); ok {
- _spec.SetField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedLatencyMs(); ok {
- _spec.AddField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
- }
- if _u.mutation.LatencyMsCleared() {
- _spec.ClearField(channelmonitorhistory.FieldLatencyMs, field.TypeInt)
- }
- if value, ok := _u.mutation.PingLatencyMs(); ok {
- _spec.SetField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedPingLatencyMs(); ok {
- _spec.AddField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
- }
- if _u.mutation.PingLatencyMsCleared() {
- _spec.ClearField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt)
- }
- if value, ok := _u.mutation.Message(); ok {
- _spec.SetField(channelmonitorhistory.FieldMessage, field.TypeString, value)
- }
- if _u.mutation.MessageCleared() {
- _spec.ClearField(channelmonitorhistory.FieldMessage, field.TypeString)
- }
- if value, ok := _u.mutation.Quota(); ok {
- _spec.SetField(channelmonitorhistory.FieldQuota, field.TypeJSON, value)
- }
- if _u.mutation.QuotaCleared() {
- _spec.ClearField(channelmonitorhistory.FieldQuota, field.TypeJSON)
- }
- if value, ok := _u.mutation.CheckedAt(); ok {
- _spec.SetField(channelmonitorhistory.FieldCheckedAt, field.TypeTime, value)
- }
- if _u.mutation.MonitorCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: channelmonitorhistory.MonitorTable,
- Columns: []string{channelmonitorhistory.MonitorColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.MonitorIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: channelmonitorhistory.MonitorTable,
- Columns: []string{channelmonitorhistory.MonitorColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &ChannelMonitorHistory{config: _u.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{channelmonitorhistory.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|