| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961 |
- // 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/channelmonitordailyrollup"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- )
- // ChannelMonitorDailyRollupUpdate is the builder for updating ChannelMonitorDailyRollup entities.
- type ChannelMonitorDailyRollupUpdate struct {
- config
- hooks []Hook
- mutation *ChannelMonitorDailyRollupMutation
- }
- // Where appends a list predicates to the ChannelMonitorDailyRollupUpdate builder.
- func (_u *ChannelMonitorDailyRollupUpdate) Where(ps ...predicate.ChannelMonitorDailyRollup) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetMonitorID sets the "monitor_id" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.SetMonitorID(v)
- return _u
- }
- // SetNillableMonitorID sets the "monitor_id" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableMonitorID(v *int64) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetMonitorID(*v)
- }
- return _u
- }
- // SetModel sets the "model" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetModel(v string) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.SetModel(v)
- return _u
- }
- // SetNillableModel sets the "model" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableModel(v *string) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetModel(*v)
- }
- return _u
- }
- // SetBucketDate sets the "bucket_date" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetBucketDate(v time.Time) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.SetBucketDate(v)
- return _u
- }
- // SetNillableBucketDate sets the "bucket_date" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableBucketDate(v *time.Time) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetBucketDate(*v)
- }
- return _u
- }
- // SetTotalChecks sets the "total_checks" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetTotalChecks(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetTotalChecks()
- _u.mutation.SetTotalChecks(v)
- return _u
- }
- // SetNillableTotalChecks sets the "total_checks" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableTotalChecks(v *int) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetTotalChecks(*v)
- }
- return _u
- }
- // AddTotalChecks adds value to the "total_checks" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddTotalChecks(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddTotalChecks(v)
- return _u
- }
- // SetOkCount sets the "ok_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetOkCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetOkCount()
- _u.mutation.SetOkCount(v)
- return _u
- }
- // SetNillableOkCount sets the "ok_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableOkCount(v *int) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetOkCount(*v)
- }
- return _u
- }
- // AddOkCount adds value to the "ok_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddOkCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddOkCount(v)
- return _u
- }
- // SetOperationalCount sets the "operational_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetOperationalCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetOperationalCount()
- _u.mutation.SetOperationalCount(v)
- return _u
- }
- // SetNillableOperationalCount sets the "operational_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableOperationalCount(v *int) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetOperationalCount(*v)
- }
- return _u
- }
- // AddOperationalCount adds value to the "operational_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddOperationalCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddOperationalCount(v)
- return _u
- }
- // SetDegradedCount sets the "degraded_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetDegradedCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetDegradedCount()
- _u.mutation.SetDegradedCount(v)
- return _u
- }
- // SetNillableDegradedCount sets the "degraded_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableDegradedCount(v *int) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetDegradedCount(*v)
- }
- return _u
- }
- // AddDegradedCount adds value to the "degraded_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddDegradedCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddDegradedCount(v)
- return _u
- }
- // SetFailedCount sets the "failed_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetFailedCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetFailedCount()
- _u.mutation.SetFailedCount(v)
- return _u
- }
- // SetNillableFailedCount sets the "failed_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableFailedCount(v *int) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetFailedCount(*v)
- }
- return _u
- }
- // AddFailedCount adds value to the "failed_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddFailedCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddFailedCount(v)
- return _u
- }
- // SetErrorCount sets the "error_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetErrorCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetErrorCount()
- _u.mutation.SetErrorCount(v)
- return _u
- }
- // SetNillableErrorCount sets the "error_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableErrorCount(v *int) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetErrorCount(*v)
- }
- return _u
- }
- // AddErrorCount adds value to the "error_count" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddErrorCount(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddErrorCount(v)
- return _u
- }
- // SetSumLatencyMs sets the "sum_latency_ms" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetSumLatencyMs(v int64) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetSumLatencyMs()
- _u.mutation.SetSumLatencyMs(v)
- return _u
- }
- // SetNillableSumLatencyMs sets the "sum_latency_ms" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableSumLatencyMs(v *int64) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetSumLatencyMs(*v)
- }
- return _u
- }
- // AddSumLatencyMs adds value to the "sum_latency_ms" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddSumLatencyMs(v int64) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddSumLatencyMs(v)
- return _u
- }
- // SetCountLatency sets the "count_latency" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetCountLatency(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetCountLatency()
- _u.mutation.SetCountLatency(v)
- return _u
- }
- // SetNillableCountLatency sets the "count_latency" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableCountLatency(v *int) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetCountLatency(*v)
- }
- return _u
- }
- // AddCountLatency adds value to the "count_latency" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddCountLatency(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddCountLatency(v)
- return _u
- }
- // SetSumPingLatencyMs sets the "sum_ping_latency_ms" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetSumPingLatencyMs(v int64) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetSumPingLatencyMs()
- _u.mutation.SetSumPingLatencyMs(v)
- return _u
- }
- // SetNillableSumPingLatencyMs sets the "sum_ping_latency_ms" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableSumPingLatencyMs(v *int64) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetSumPingLatencyMs(*v)
- }
- return _u
- }
- // AddSumPingLatencyMs adds value to the "sum_ping_latency_ms" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddSumPingLatencyMs(v int64) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddSumPingLatencyMs(v)
- return _u
- }
- // SetCountPingLatency sets the "count_ping_latency" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetCountPingLatency(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ResetCountPingLatency()
- _u.mutation.SetCountPingLatency(v)
- return _u
- }
- // SetNillableCountPingLatency sets the "count_ping_latency" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdate) SetNillableCountPingLatency(v *int) *ChannelMonitorDailyRollupUpdate {
- if v != nil {
- _u.SetCountPingLatency(*v)
- }
- return _u
- }
- // AddCountPingLatency adds value to the "count_ping_latency" field.
- func (_u *ChannelMonitorDailyRollupUpdate) AddCountPingLatency(v int) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.AddCountPingLatency(v)
- return _u
- }
- // SetComputedAt sets the "computed_at" field.
- func (_u *ChannelMonitorDailyRollupUpdate) SetComputedAt(v time.Time) *ChannelMonitorDailyRollupUpdate {
- _u.mutation.SetComputedAt(v)
- return _u
- }
- // SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
- func (_u *ChannelMonitorDailyRollupUpdate) SetMonitor(v *ChannelMonitor) *ChannelMonitorDailyRollupUpdate {
- return _u.SetMonitorID(v.ID)
- }
- // Mutation returns the ChannelMonitorDailyRollupMutation object of the builder.
- func (_u *ChannelMonitorDailyRollupUpdate) Mutation() *ChannelMonitorDailyRollupMutation {
- return _u.mutation
- }
- // ClearMonitor clears the "monitor" edge to the ChannelMonitor entity.
- func (_u *ChannelMonitorDailyRollupUpdate) ClearMonitor() *ChannelMonitorDailyRollupUpdate {
- _u.mutation.ClearMonitor()
- return _u
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *ChannelMonitorDailyRollupUpdate) Save(ctx context.Context) (int, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ChannelMonitorDailyRollupUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *ChannelMonitorDailyRollupUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ChannelMonitorDailyRollupUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *ChannelMonitorDailyRollupUpdate) defaults() {
- if _, ok := _u.mutation.ComputedAt(); !ok {
- v := channelmonitordailyrollup.UpdateDefaultComputedAt()
- _u.mutation.SetComputedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ChannelMonitorDailyRollupUpdate) check() error {
- if v, ok := _u.mutation.Model(); ok {
- if err := channelmonitordailyrollup.ModelValidator(v); err != nil {
- return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorDailyRollup.model": %w`, err)}
- }
- }
- if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "ChannelMonitorDailyRollup.monitor"`)
- }
- return nil
- }
- func (_u *ChannelMonitorDailyRollupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(channelmonitordailyrollup.Table, channelmonitordailyrollup.Columns, sqlgraph.NewFieldSpec(channelmonitordailyrollup.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(channelmonitordailyrollup.FieldModel, field.TypeString, value)
- }
- if value, ok := _u.mutation.BucketDate(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldBucketDate, field.TypeTime, value)
- }
- if value, ok := _u.mutation.TotalChecks(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldTotalChecks, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedTotalChecks(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldTotalChecks, field.TypeInt, value)
- }
- if value, ok := _u.mutation.OkCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldOkCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedOkCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldOkCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.OperationalCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldOperationalCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedOperationalCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldOperationalCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.DegradedCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldDegradedCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedDegradedCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldDegradedCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.FailedCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldFailedCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedFailedCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldFailedCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.ErrorCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldErrorCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedErrorCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldErrorCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.SumLatencyMs(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldSumLatencyMs, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedSumLatencyMs(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldSumLatencyMs, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.CountLatency(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldCountLatency, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedCountLatency(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldCountLatency, field.TypeInt, value)
- }
- if value, ok := _u.mutation.SumPingLatencyMs(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldSumPingLatencyMs, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedSumPingLatencyMs(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldSumPingLatencyMs, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.CountPingLatency(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldCountPingLatency, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedCountPingLatency(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldCountPingLatency, field.TypeInt, value)
- }
- if value, ok := _u.mutation.ComputedAt(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldComputedAt, field.TypeTime, value)
- }
- if _u.mutation.MonitorCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: channelmonitordailyrollup.MonitorTable,
- Columns: []string{channelmonitordailyrollup.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: channelmonitordailyrollup.MonitorTable,
- Columns: []string{channelmonitordailyrollup.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{channelmonitordailyrollup.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // ChannelMonitorDailyRollupUpdateOne is the builder for updating a single ChannelMonitorDailyRollup entity.
- type ChannelMonitorDailyRollupUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *ChannelMonitorDailyRollupMutation
- }
- // SetMonitorID sets the "monitor_id" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.SetMonitorID(v)
- return _u
- }
- // SetNillableMonitorID sets the "monitor_id" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableMonitorID(v *int64) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetMonitorID(*v)
- }
- return _u
- }
- // SetModel sets the "model" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetModel(v string) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.SetModel(v)
- return _u
- }
- // SetNillableModel sets the "model" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableModel(v *string) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetModel(*v)
- }
- return _u
- }
- // SetBucketDate sets the "bucket_date" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetBucketDate(v time.Time) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.SetBucketDate(v)
- return _u
- }
- // SetNillableBucketDate sets the "bucket_date" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableBucketDate(v *time.Time) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetBucketDate(*v)
- }
- return _u
- }
- // SetTotalChecks sets the "total_checks" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetTotalChecks(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetTotalChecks()
- _u.mutation.SetTotalChecks(v)
- return _u
- }
- // SetNillableTotalChecks sets the "total_checks" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableTotalChecks(v *int) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetTotalChecks(*v)
- }
- return _u
- }
- // AddTotalChecks adds value to the "total_checks" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddTotalChecks(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddTotalChecks(v)
- return _u
- }
- // SetOkCount sets the "ok_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetOkCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetOkCount()
- _u.mutation.SetOkCount(v)
- return _u
- }
- // SetNillableOkCount sets the "ok_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableOkCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetOkCount(*v)
- }
- return _u
- }
- // AddOkCount adds value to the "ok_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddOkCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddOkCount(v)
- return _u
- }
- // SetOperationalCount sets the "operational_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetOperationalCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetOperationalCount()
- _u.mutation.SetOperationalCount(v)
- return _u
- }
- // SetNillableOperationalCount sets the "operational_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableOperationalCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetOperationalCount(*v)
- }
- return _u
- }
- // AddOperationalCount adds value to the "operational_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddOperationalCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddOperationalCount(v)
- return _u
- }
- // SetDegradedCount sets the "degraded_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetDegradedCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetDegradedCount()
- _u.mutation.SetDegradedCount(v)
- return _u
- }
- // SetNillableDegradedCount sets the "degraded_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableDegradedCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetDegradedCount(*v)
- }
- return _u
- }
- // AddDegradedCount adds value to the "degraded_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddDegradedCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddDegradedCount(v)
- return _u
- }
- // SetFailedCount sets the "failed_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetFailedCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetFailedCount()
- _u.mutation.SetFailedCount(v)
- return _u
- }
- // SetNillableFailedCount sets the "failed_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableFailedCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetFailedCount(*v)
- }
- return _u
- }
- // AddFailedCount adds value to the "failed_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddFailedCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddFailedCount(v)
- return _u
- }
- // SetErrorCount sets the "error_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetErrorCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetErrorCount()
- _u.mutation.SetErrorCount(v)
- return _u
- }
- // SetNillableErrorCount sets the "error_count" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableErrorCount(v *int) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetErrorCount(*v)
- }
- return _u
- }
- // AddErrorCount adds value to the "error_count" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddErrorCount(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddErrorCount(v)
- return _u
- }
- // SetSumLatencyMs sets the "sum_latency_ms" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetSumLatencyMs(v int64) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetSumLatencyMs()
- _u.mutation.SetSumLatencyMs(v)
- return _u
- }
- // SetNillableSumLatencyMs sets the "sum_latency_ms" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableSumLatencyMs(v *int64) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetSumLatencyMs(*v)
- }
- return _u
- }
- // AddSumLatencyMs adds value to the "sum_latency_ms" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddSumLatencyMs(v int64) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddSumLatencyMs(v)
- return _u
- }
- // SetCountLatency sets the "count_latency" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetCountLatency(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetCountLatency()
- _u.mutation.SetCountLatency(v)
- return _u
- }
- // SetNillableCountLatency sets the "count_latency" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableCountLatency(v *int) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetCountLatency(*v)
- }
- return _u
- }
- // AddCountLatency adds value to the "count_latency" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddCountLatency(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddCountLatency(v)
- return _u
- }
- // SetSumPingLatencyMs sets the "sum_ping_latency_ms" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetSumPingLatencyMs(v int64) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetSumPingLatencyMs()
- _u.mutation.SetSumPingLatencyMs(v)
- return _u
- }
- // SetNillableSumPingLatencyMs sets the "sum_ping_latency_ms" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableSumPingLatencyMs(v *int64) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetSumPingLatencyMs(*v)
- }
- return _u
- }
- // AddSumPingLatencyMs adds value to the "sum_ping_latency_ms" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddSumPingLatencyMs(v int64) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddSumPingLatencyMs(v)
- return _u
- }
- // SetCountPingLatency sets the "count_ping_latency" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetCountPingLatency(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ResetCountPingLatency()
- _u.mutation.SetCountPingLatency(v)
- return _u
- }
- // SetNillableCountPingLatency sets the "count_ping_latency" field if the given value is not nil.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableCountPingLatency(v *int) *ChannelMonitorDailyRollupUpdateOne {
- if v != nil {
- _u.SetCountPingLatency(*v)
- }
- return _u
- }
- // AddCountPingLatency adds value to the "count_ping_latency" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) AddCountPingLatency(v int) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.AddCountPingLatency(v)
- return _u
- }
- // SetComputedAt sets the "computed_at" field.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetComputedAt(v time.Time) *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.SetComputedAt(v)
- return _u
- }
- // SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SetMonitor(v *ChannelMonitor) *ChannelMonitorDailyRollupUpdateOne {
- return _u.SetMonitorID(v.ID)
- }
- // Mutation returns the ChannelMonitorDailyRollupMutation object of the builder.
- func (_u *ChannelMonitorDailyRollupUpdateOne) Mutation() *ChannelMonitorDailyRollupMutation {
- return _u.mutation
- }
- // ClearMonitor clears the "monitor" edge to the ChannelMonitor entity.
- func (_u *ChannelMonitorDailyRollupUpdateOne) ClearMonitor() *ChannelMonitorDailyRollupUpdateOne {
- _u.mutation.ClearMonitor()
- return _u
- }
- // Where appends a list predicates to the ChannelMonitorDailyRollupUpdate builder.
- func (_u *ChannelMonitorDailyRollupUpdateOne) Where(ps ...predicate.ChannelMonitorDailyRollup) *ChannelMonitorDailyRollupUpdateOne {
- _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 *ChannelMonitorDailyRollupUpdateOne) Select(field string, fields ...string) *ChannelMonitorDailyRollupUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated ChannelMonitorDailyRollup entity.
- func (_u *ChannelMonitorDailyRollupUpdateOne) Save(ctx context.Context) (*ChannelMonitorDailyRollup, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ChannelMonitorDailyRollupUpdateOne) SaveX(ctx context.Context) *ChannelMonitorDailyRollup {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *ChannelMonitorDailyRollupUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ChannelMonitorDailyRollupUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *ChannelMonitorDailyRollupUpdateOne) defaults() {
- if _, ok := _u.mutation.ComputedAt(); !ok {
- v := channelmonitordailyrollup.UpdateDefaultComputedAt()
- _u.mutation.SetComputedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ChannelMonitorDailyRollupUpdateOne) check() error {
- if v, ok := _u.mutation.Model(); ok {
- if err := channelmonitordailyrollup.ModelValidator(v); err != nil {
- return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorDailyRollup.model": %w`, err)}
- }
- }
- if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "ChannelMonitorDailyRollup.monitor"`)
- }
- return nil
- }
- func (_u *ChannelMonitorDailyRollupUpdateOne) sqlSave(ctx context.Context) (_node *ChannelMonitorDailyRollup, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(channelmonitordailyrollup.Table, channelmonitordailyrollup.Columns, sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChannelMonitorDailyRollup.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, channelmonitordailyrollup.FieldID)
- for _, f := range fields {
- if !channelmonitordailyrollup.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != channelmonitordailyrollup.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(channelmonitordailyrollup.FieldModel, field.TypeString, value)
- }
- if value, ok := _u.mutation.BucketDate(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldBucketDate, field.TypeTime, value)
- }
- if value, ok := _u.mutation.TotalChecks(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldTotalChecks, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedTotalChecks(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldTotalChecks, field.TypeInt, value)
- }
- if value, ok := _u.mutation.OkCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldOkCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedOkCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldOkCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.OperationalCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldOperationalCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedOperationalCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldOperationalCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.DegradedCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldDegradedCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedDegradedCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldDegradedCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.FailedCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldFailedCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedFailedCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldFailedCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.ErrorCount(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldErrorCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedErrorCount(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldErrorCount, field.TypeInt, value)
- }
- if value, ok := _u.mutation.SumLatencyMs(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldSumLatencyMs, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedSumLatencyMs(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldSumLatencyMs, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.CountLatency(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldCountLatency, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedCountLatency(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldCountLatency, field.TypeInt, value)
- }
- if value, ok := _u.mutation.SumPingLatencyMs(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldSumPingLatencyMs, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedSumPingLatencyMs(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldSumPingLatencyMs, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.CountPingLatency(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldCountPingLatency, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedCountPingLatency(); ok {
- _spec.AddField(channelmonitordailyrollup.FieldCountPingLatency, field.TypeInt, value)
- }
- if value, ok := _u.mutation.ComputedAt(); ok {
- _spec.SetField(channelmonitordailyrollup.FieldComputedAt, field.TypeTime, value)
- }
- if _u.mutation.MonitorCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: channelmonitordailyrollup.MonitorTable,
- Columns: []string{channelmonitordailyrollup.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: channelmonitordailyrollup.MonitorTable,
- Columns: []string{channelmonitordailyrollup.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 = &ChannelMonitorDailyRollup{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{channelmonitordailyrollup.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|