| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018 |
- // 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/internal/domain"
- )
- // ChannelMonitorHistoryCreate is the builder for creating a ChannelMonitorHistory entity.
- type ChannelMonitorHistoryCreate struct {
- config
- mutation *ChannelMonitorHistoryMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetMonitorID sets the "monitor_id" field.
- func (_c *ChannelMonitorHistoryCreate) SetMonitorID(v int64) *ChannelMonitorHistoryCreate {
- _c.mutation.SetMonitorID(v)
- return _c
- }
- // SetModel sets the "model" field.
- func (_c *ChannelMonitorHistoryCreate) SetModel(v string) *ChannelMonitorHistoryCreate {
- _c.mutation.SetModel(v)
- return _c
- }
- // SetStatus sets the "status" field.
- func (_c *ChannelMonitorHistoryCreate) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryCreate {
- _c.mutation.SetStatus(v)
- return _c
- }
- // SetLatencyMs sets the "latency_ms" field.
- func (_c *ChannelMonitorHistoryCreate) SetLatencyMs(v int) *ChannelMonitorHistoryCreate {
- _c.mutation.SetLatencyMs(v)
- return _c
- }
- // SetNillableLatencyMs sets the "latency_ms" field if the given value is not nil.
- func (_c *ChannelMonitorHistoryCreate) SetNillableLatencyMs(v *int) *ChannelMonitorHistoryCreate {
- if v != nil {
- _c.SetLatencyMs(*v)
- }
- return _c
- }
- // SetPingLatencyMs sets the "ping_latency_ms" field.
- func (_c *ChannelMonitorHistoryCreate) SetPingLatencyMs(v int) *ChannelMonitorHistoryCreate {
- _c.mutation.SetPingLatencyMs(v)
- return _c
- }
- // SetNillablePingLatencyMs sets the "ping_latency_ms" field if the given value is not nil.
- func (_c *ChannelMonitorHistoryCreate) SetNillablePingLatencyMs(v *int) *ChannelMonitorHistoryCreate {
- if v != nil {
- _c.SetPingLatencyMs(*v)
- }
- return _c
- }
- // SetMessage sets the "message" field.
- func (_c *ChannelMonitorHistoryCreate) SetMessage(v string) *ChannelMonitorHistoryCreate {
- _c.mutation.SetMessage(v)
- return _c
- }
- // SetNillableMessage sets the "message" field if the given value is not nil.
- func (_c *ChannelMonitorHistoryCreate) SetNillableMessage(v *string) *ChannelMonitorHistoryCreate {
- if v != nil {
- _c.SetMessage(*v)
- }
- return _c
- }
- // SetQuota sets the "quota" field.
- func (_c *ChannelMonitorHistoryCreate) SetQuota(v *domain.MonitorQuotaSnapshot) *ChannelMonitorHistoryCreate {
- _c.mutation.SetQuota(v)
- return _c
- }
- // SetCheckedAt sets the "checked_at" field.
- func (_c *ChannelMonitorHistoryCreate) SetCheckedAt(v time.Time) *ChannelMonitorHistoryCreate {
- _c.mutation.SetCheckedAt(v)
- return _c
- }
- // SetNillableCheckedAt sets the "checked_at" field if the given value is not nil.
- func (_c *ChannelMonitorHistoryCreate) SetNillableCheckedAt(v *time.Time) *ChannelMonitorHistoryCreate {
- if v != nil {
- _c.SetCheckedAt(*v)
- }
- return _c
- }
- // SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
- func (_c *ChannelMonitorHistoryCreate) SetMonitor(v *ChannelMonitor) *ChannelMonitorHistoryCreate {
- return _c.SetMonitorID(v.ID)
- }
- // Mutation returns the ChannelMonitorHistoryMutation object of the builder.
- func (_c *ChannelMonitorHistoryCreate) Mutation() *ChannelMonitorHistoryMutation {
- return _c.mutation
- }
- // Save creates the ChannelMonitorHistory in the database.
- func (_c *ChannelMonitorHistoryCreate) Save(ctx context.Context) (*ChannelMonitorHistory, error) {
- _c.defaults()
- return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (_c *ChannelMonitorHistoryCreate) SaveX(ctx context.Context) *ChannelMonitorHistory {
- v, err := _c.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (_c *ChannelMonitorHistoryCreate) Exec(ctx context.Context) error {
- _, err := _c.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_c *ChannelMonitorHistoryCreate) ExecX(ctx context.Context) {
- if err := _c.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_c *ChannelMonitorHistoryCreate) defaults() {
- if _, ok := _c.mutation.Message(); !ok {
- v := channelmonitorhistory.DefaultMessage
- _c.mutation.SetMessage(v)
- }
- if _, ok := _c.mutation.CheckedAt(); !ok {
- v := channelmonitorhistory.DefaultCheckedAt()
- _c.mutation.SetCheckedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_c *ChannelMonitorHistoryCreate) check() error {
- if _, ok := _c.mutation.MonitorID(); !ok {
- return &ValidationError{Name: "monitor_id", err: errors.New(`ent: missing required field "ChannelMonitorHistory.monitor_id"`)}
- }
- if _, ok := _c.mutation.Model(); !ok {
- return &ValidationError{Name: "model", err: errors.New(`ent: missing required field "ChannelMonitorHistory.model"`)}
- }
- if v, ok := _c.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 _, ok := _c.mutation.Status(); !ok {
- return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "ChannelMonitorHistory.status"`)}
- }
- if v, ok := _c.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 := _c.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 _, ok := _c.mutation.CheckedAt(); !ok {
- return &ValidationError{Name: "checked_at", err: errors.New(`ent: missing required field "ChannelMonitorHistory.checked_at"`)}
- }
- if len(_c.mutation.MonitorIDs()) == 0 {
- return &ValidationError{Name: "monitor", err: errors.New(`ent: missing required edge "ChannelMonitorHistory.monitor"`)}
- }
- return nil
- }
- func (_c *ChannelMonitorHistoryCreate) sqlSave(ctx context.Context) (*ChannelMonitorHistory, error) {
- if err := _c.check(); err != nil {
- return nil, err
- }
- _node, _spec := _c.createSpec()
- if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- id := _spec.ID.Value.(int64)
- _node.ID = int64(id)
- _c.mutation.id = &_node.ID
- _c.mutation.done = true
- return _node, nil
- }
- func (_c *ChannelMonitorHistoryCreate) createSpec() (*ChannelMonitorHistory, *sqlgraph.CreateSpec) {
- var (
- _node = &ChannelMonitorHistory{config: _c.config}
- _spec = sqlgraph.NewCreateSpec(channelmonitorhistory.Table, sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64))
- )
- _spec.OnConflict = _c.conflict
- if value, ok := _c.mutation.Model(); ok {
- _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value)
- _node.Model = value
- }
- if value, ok := _c.mutation.Status(); ok {
- _spec.SetField(channelmonitorhistory.FieldStatus, field.TypeEnum, value)
- _node.Status = value
- }
- if value, ok := _c.mutation.LatencyMs(); ok {
- _spec.SetField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
- _node.LatencyMs = &value
- }
- if value, ok := _c.mutation.PingLatencyMs(); ok {
- _spec.SetField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
- _node.PingLatencyMs = &value
- }
- if value, ok := _c.mutation.Message(); ok {
- _spec.SetField(channelmonitorhistory.FieldMessage, field.TypeString, value)
- _node.Message = value
- }
- if value, ok := _c.mutation.Quota(); ok {
- _spec.SetField(channelmonitorhistory.FieldQuota, field.TypeJSON, value)
- _node.Quota = value
- }
- if value, ok := _c.mutation.CheckedAt(); ok {
- _spec.SetField(channelmonitorhistory.FieldCheckedAt, field.TypeTime, value)
- _node.CheckedAt = value
- }
- if nodes := _c.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)
- }
- _node.MonitorID = nodes[0]
- _spec.Edges = append(_spec.Edges, edge)
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.ChannelMonitorHistory.Create().
- // SetMonitorID(v).
- // OnConflict(
- // // Update the row with the new values
- // // the was proposed for insertion.
- // sql.ResolveWithNewValues(),
- // ).
- // // Override some of the fields with custom
- // // update values.
- // Update(func(u *ent.ChannelMonitorHistoryUpsert) {
- // SetMonitorID(v+v).
- // }).
- // Exec(ctx)
- func (_c *ChannelMonitorHistoryCreate) OnConflict(opts ...sql.ConflictOption) *ChannelMonitorHistoryUpsertOne {
- _c.conflict = opts
- return &ChannelMonitorHistoryUpsertOne{
- create: _c,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.ChannelMonitorHistory.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (_c *ChannelMonitorHistoryCreate) OnConflictColumns(columns ...string) *ChannelMonitorHistoryUpsertOne {
- _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
- return &ChannelMonitorHistoryUpsertOne{
- create: _c,
- }
- }
- type (
- // ChannelMonitorHistoryUpsertOne is the builder for "upsert"-ing
- // one ChannelMonitorHistory node.
- ChannelMonitorHistoryUpsertOne struct {
- create *ChannelMonitorHistoryCreate
- }
- // ChannelMonitorHistoryUpsert is the "OnConflict" setter.
- ChannelMonitorHistoryUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetMonitorID sets the "monitor_id" field.
- func (u *ChannelMonitorHistoryUpsert) SetMonitorID(v int64) *ChannelMonitorHistoryUpsert {
- u.Set(channelmonitorhistory.FieldMonitorID, v)
- return u
- }
- // UpdateMonitorID sets the "monitor_id" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsert) UpdateMonitorID() *ChannelMonitorHistoryUpsert {
- u.SetExcluded(channelmonitorhistory.FieldMonitorID)
- return u
- }
- // SetModel sets the "model" field.
- func (u *ChannelMonitorHistoryUpsert) SetModel(v string) *ChannelMonitorHistoryUpsert {
- u.Set(channelmonitorhistory.FieldModel, v)
- return u
- }
- // UpdateModel sets the "model" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsert) UpdateModel() *ChannelMonitorHistoryUpsert {
- u.SetExcluded(channelmonitorhistory.FieldModel)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *ChannelMonitorHistoryUpsert) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpsert {
- u.Set(channelmonitorhistory.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsert) UpdateStatus() *ChannelMonitorHistoryUpsert {
- u.SetExcluded(channelmonitorhistory.FieldStatus)
- return u
- }
- // SetLatencyMs sets the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsert) SetLatencyMs(v int) *ChannelMonitorHistoryUpsert {
- u.Set(channelmonitorhistory.FieldLatencyMs, v)
- return u
- }
- // UpdateLatencyMs sets the "latency_ms" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsert) UpdateLatencyMs() *ChannelMonitorHistoryUpsert {
- u.SetExcluded(channelmonitorhistory.FieldLatencyMs)
- return u
- }
- // AddLatencyMs adds v to the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsert) AddLatencyMs(v int) *ChannelMonitorHistoryUpsert {
- u.Add(channelmonitorhistory.FieldLatencyMs, v)
- return u
- }
- // ClearLatencyMs clears the value of the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsert) ClearLatencyMs() *ChannelMonitorHistoryUpsert {
- u.SetNull(channelmonitorhistory.FieldLatencyMs)
- return u
- }
- // SetPingLatencyMs sets the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsert) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpsert {
- u.Set(channelmonitorhistory.FieldPingLatencyMs, v)
- return u
- }
- // UpdatePingLatencyMs sets the "ping_latency_ms" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsert) UpdatePingLatencyMs() *ChannelMonitorHistoryUpsert {
- u.SetExcluded(channelmonitorhistory.FieldPingLatencyMs)
- return u
- }
- // AddPingLatencyMs adds v to the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsert) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpsert {
- u.Add(channelmonitorhistory.FieldPingLatencyMs, v)
- return u
- }
- // ClearPingLatencyMs clears the value of the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsert) ClearPingLatencyMs() *ChannelMonitorHistoryUpsert {
- u.SetNull(channelmonitorhistory.FieldPingLatencyMs)
- return u
- }
- // SetMessage sets the "message" field.
- func (u *ChannelMonitorHistoryUpsert) SetMessage(v string) *ChannelMonitorHistoryUpsert {
- u.Set(channelmonitorhistory.FieldMessage, v)
- return u
- }
- // UpdateMessage sets the "message" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsert) UpdateMessage() *ChannelMonitorHistoryUpsert {
- u.SetExcluded(channelmonitorhistory.FieldMessage)
- return u
- }
- // ClearMessage clears the value of the "message" field.
- func (u *ChannelMonitorHistoryUpsert) ClearMessage() *ChannelMonitorHistoryUpsert {
- u.SetNull(channelmonitorhistory.FieldMessage)
- return u
- }
- // SetQuota sets the "quota" field.
- func (u *ChannelMonitorHistoryUpsert) SetQuota(v *domain.MonitorQuotaSnapshot) *ChannelMonitorHistoryUpsert {
- u.Set(channelmonitorhistory.FieldQuota, v)
- return u
- }
- // UpdateQuota sets the "quota" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsert) UpdateQuota() *ChannelMonitorHistoryUpsert {
- u.SetExcluded(channelmonitorhistory.FieldQuota)
- return u
- }
- // ClearQuota clears the value of the "quota" field.
- func (u *ChannelMonitorHistoryUpsert) ClearQuota() *ChannelMonitorHistoryUpsert {
- u.SetNull(channelmonitorhistory.FieldQuota)
- return u
- }
- // SetCheckedAt sets the "checked_at" field.
- func (u *ChannelMonitorHistoryUpsert) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpsert {
- u.Set(channelmonitorhistory.FieldCheckedAt, v)
- return u
- }
- // UpdateCheckedAt sets the "checked_at" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsert) UpdateCheckedAt() *ChannelMonitorHistoryUpsert {
- u.SetExcluded(channelmonitorhistory.FieldCheckedAt)
- return u
- }
- // UpdateNewValues updates the mutable fields using the new values that were set on create.
- // Using this option is equivalent to using:
- //
- // client.ChannelMonitorHistory.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // ).
- // Exec(ctx)
- func (u *ChannelMonitorHistoryUpsertOne) UpdateNewValues() *ChannelMonitorHistoryUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.ChannelMonitorHistory.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *ChannelMonitorHistoryUpsertOne) Ignore() *ChannelMonitorHistoryUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
- return u
- }
- // DoNothing configures the conflict_action to `DO NOTHING`.
- // Supported only by SQLite and PostgreSQL.
- func (u *ChannelMonitorHistoryUpsertOne) DoNothing() *ChannelMonitorHistoryUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the ChannelMonitorHistoryCreate.OnConflict
- // documentation for more info.
- func (u *ChannelMonitorHistoryUpsertOne) Update(set func(*ChannelMonitorHistoryUpsert)) *ChannelMonitorHistoryUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&ChannelMonitorHistoryUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetMonitorID sets the "monitor_id" field.
- func (u *ChannelMonitorHistoryUpsertOne) SetMonitorID(v int64) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetMonitorID(v)
- })
- }
- // UpdateMonitorID sets the "monitor_id" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertOne) UpdateMonitorID() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateMonitorID()
- })
- }
- // SetModel sets the "model" field.
- func (u *ChannelMonitorHistoryUpsertOne) SetModel(v string) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetModel(v)
- })
- }
- // UpdateModel sets the "model" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertOne) UpdateModel() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateModel()
- })
- }
- // SetStatus sets the "status" field.
- func (u *ChannelMonitorHistoryUpsertOne) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertOne) UpdateStatus() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateStatus()
- })
- }
- // SetLatencyMs sets the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertOne) SetLatencyMs(v int) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetLatencyMs(v)
- })
- }
- // AddLatencyMs adds v to the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertOne) AddLatencyMs(v int) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.AddLatencyMs(v)
- })
- }
- // UpdateLatencyMs sets the "latency_ms" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertOne) UpdateLatencyMs() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateLatencyMs()
- })
- }
- // ClearLatencyMs clears the value of the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertOne) ClearLatencyMs() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.ClearLatencyMs()
- })
- }
- // SetPingLatencyMs sets the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertOne) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetPingLatencyMs(v)
- })
- }
- // AddPingLatencyMs adds v to the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertOne) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.AddPingLatencyMs(v)
- })
- }
- // UpdatePingLatencyMs sets the "ping_latency_ms" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertOne) UpdatePingLatencyMs() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdatePingLatencyMs()
- })
- }
- // ClearPingLatencyMs clears the value of the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertOne) ClearPingLatencyMs() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.ClearPingLatencyMs()
- })
- }
- // SetMessage sets the "message" field.
- func (u *ChannelMonitorHistoryUpsertOne) SetMessage(v string) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetMessage(v)
- })
- }
- // UpdateMessage sets the "message" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertOne) UpdateMessage() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateMessage()
- })
- }
- // ClearMessage clears the value of the "message" field.
- func (u *ChannelMonitorHistoryUpsertOne) ClearMessage() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.ClearMessage()
- })
- }
- // SetQuota sets the "quota" field.
- func (u *ChannelMonitorHistoryUpsertOne) SetQuota(v *domain.MonitorQuotaSnapshot) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetQuota(v)
- })
- }
- // UpdateQuota sets the "quota" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertOne) UpdateQuota() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateQuota()
- })
- }
- // ClearQuota clears the value of the "quota" field.
- func (u *ChannelMonitorHistoryUpsertOne) ClearQuota() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.ClearQuota()
- })
- }
- // SetCheckedAt sets the "checked_at" field.
- func (u *ChannelMonitorHistoryUpsertOne) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetCheckedAt(v)
- })
- }
- // UpdateCheckedAt sets the "checked_at" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertOne) UpdateCheckedAt() *ChannelMonitorHistoryUpsertOne {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateCheckedAt()
- })
- }
- // Exec executes the query.
- func (u *ChannelMonitorHistoryUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for ChannelMonitorHistoryCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *ChannelMonitorHistoryUpsertOne) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // Exec executes the UPSERT query and returns the inserted/updated ID.
- func (u *ChannelMonitorHistoryUpsertOne) ID(ctx context.Context) (id int64, err error) {
- node, err := u.create.Save(ctx)
- if err != nil {
- return id, err
- }
- return node.ID, nil
- }
- // IDX is like ID, but panics if an error occurs.
- func (u *ChannelMonitorHistoryUpsertOne) IDX(ctx context.Context) int64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // ChannelMonitorHistoryCreateBulk is the builder for creating many ChannelMonitorHistory entities in bulk.
- type ChannelMonitorHistoryCreateBulk struct {
- config
- err error
- builders []*ChannelMonitorHistoryCreate
- conflict []sql.ConflictOption
- }
- // Save creates the ChannelMonitorHistory entities in the database.
- func (_c *ChannelMonitorHistoryCreateBulk) Save(ctx context.Context) ([]*ChannelMonitorHistory, error) {
- if _c.err != nil {
- return nil, _c.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
- nodes := make([]*ChannelMonitorHistory, len(_c.builders))
- mutators := make([]Mutator, len(_c.builders))
- for i := range _c.builders {
- func(i int, root context.Context) {
- builder := _c.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*ChannelMonitorHistoryMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- if err := builder.check(); err != nil {
- return nil, err
- }
- builder.mutation = mutation
- var err error
- nodes[i], specs[i] = builder.createSpec()
- if i < len(mutators)-1 {
- _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = _c.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- }
- }
- if err != nil {
- return nil, err
- }
- mutation.id = &nodes[i].ID
- if specs[i].ID.Value != nil {
- id := specs[i].ID.Value.(int64)
- nodes[i].ID = int64(id)
- }
- mutation.done = true
- return nodes[i], nil
- })
- for i := len(builder.hooks) - 1; i >= 0; i-- {
- mut = builder.hooks[i](mut)
- }
- mutators[i] = mut
- }(i, ctx)
- }
- if len(mutators) > 0 {
- if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_c *ChannelMonitorHistoryCreateBulk) SaveX(ctx context.Context) []*ChannelMonitorHistory {
- v, err := _c.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (_c *ChannelMonitorHistoryCreateBulk) Exec(ctx context.Context) error {
- _, err := _c.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_c *ChannelMonitorHistoryCreateBulk) ExecX(ctx context.Context) {
- if err := _c.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.ChannelMonitorHistory.CreateBulk(builders...).
- // OnConflict(
- // // Update the row with the new values
- // // the was proposed for insertion.
- // sql.ResolveWithNewValues(),
- // ).
- // // Override some of the fields with custom
- // // update values.
- // Update(func(u *ent.ChannelMonitorHistoryUpsert) {
- // SetMonitorID(v+v).
- // }).
- // Exec(ctx)
- func (_c *ChannelMonitorHistoryCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChannelMonitorHistoryUpsertBulk {
- _c.conflict = opts
- return &ChannelMonitorHistoryUpsertBulk{
- create: _c,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.ChannelMonitorHistory.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (_c *ChannelMonitorHistoryCreateBulk) OnConflictColumns(columns ...string) *ChannelMonitorHistoryUpsertBulk {
- _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
- return &ChannelMonitorHistoryUpsertBulk{
- create: _c,
- }
- }
- // ChannelMonitorHistoryUpsertBulk is the builder for "upsert"-ing
- // a bulk of ChannelMonitorHistory nodes.
- type ChannelMonitorHistoryUpsertBulk struct {
- create *ChannelMonitorHistoryCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.ChannelMonitorHistory.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // ).
- // Exec(ctx)
- func (u *ChannelMonitorHistoryUpsertBulk) UpdateNewValues() *ChannelMonitorHistoryUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.ChannelMonitorHistory.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *ChannelMonitorHistoryUpsertBulk) Ignore() *ChannelMonitorHistoryUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
- return u
- }
- // DoNothing configures the conflict_action to `DO NOTHING`.
- // Supported only by SQLite and PostgreSQL.
- func (u *ChannelMonitorHistoryUpsertBulk) DoNothing() *ChannelMonitorHistoryUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the ChannelMonitorHistoryCreateBulk.OnConflict
- // documentation for more info.
- func (u *ChannelMonitorHistoryUpsertBulk) Update(set func(*ChannelMonitorHistoryUpsert)) *ChannelMonitorHistoryUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&ChannelMonitorHistoryUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetMonitorID sets the "monitor_id" field.
- func (u *ChannelMonitorHistoryUpsertBulk) SetMonitorID(v int64) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetMonitorID(v)
- })
- }
- // UpdateMonitorID sets the "monitor_id" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertBulk) UpdateMonitorID() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateMonitorID()
- })
- }
- // SetModel sets the "model" field.
- func (u *ChannelMonitorHistoryUpsertBulk) SetModel(v string) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetModel(v)
- })
- }
- // UpdateModel sets the "model" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertBulk) UpdateModel() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateModel()
- })
- }
- // SetStatus sets the "status" field.
- func (u *ChannelMonitorHistoryUpsertBulk) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertBulk) UpdateStatus() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateStatus()
- })
- }
- // SetLatencyMs sets the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertBulk) SetLatencyMs(v int) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetLatencyMs(v)
- })
- }
- // AddLatencyMs adds v to the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertBulk) AddLatencyMs(v int) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.AddLatencyMs(v)
- })
- }
- // UpdateLatencyMs sets the "latency_ms" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertBulk) UpdateLatencyMs() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateLatencyMs()
- })
- }
- // ClearLatencyMs clears the value of the "latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertBulk) ClearLatencyMs() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.ClearLatencyMs()
- })
- }
- // SetPingLatencyMs sets the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertBulk) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetPingLatencyMs(v)
- })
- }
- // AddPingLatencyMs adds v to the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertBulk) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.AddPingLatencyMs(v)
- })
- }
- // UpdatePingLatencyMs sets the "ping_latency_ms" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertBulk) UpdatePingLatencyMs() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdatePingLatencyMs()
- })
- }
- // ClearPingLatencyMs clears the value of the "ping_latency_ms" field.
- func (u *ChannelMonitorHistoryUpsertBulk) ClearPingLatencyMs() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.ClearPingLatencyMs()
- })
- }
- // SetMessage sets the "message" field.
- func (u *ChannelMonitorHistoryUpsertBulk) SetMessage(v string) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetMessage(v)
- })
- }
- // UpdateMessage sets the "message" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertBulk) UpdateMessage() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateMessage()
- })
- }
- // ClearMessage clears the value of the "message" field.
- func (u *ChannelMonitorHistoryUpsertBulk) ClearMessage() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.ClearMessage()
- })
- }
- // SetQuota sets the "quota" field.
- func (u *ChannelMonitorHistoryUpsertBulk) SetQuota(v *domain.MonitorQuotaSnapshot) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetQuota(v)
- })
- }
- // UpdateQuota sets the "quota" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertBulk) UpdateQuota() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateQuota()
- })
- }
- // ClearQuota clears the value of the "quota" field.
- func (u *ChannelMonitorHistoryUpsertBulk) ClearQuota() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.ClearQuota()
- })
- }
- // SetCheckedAt sets the "checked_at" field.
- func (u *ChannelMonitorHistoryUpsertBulk) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.SetCheckedAt(v)
- })
- }
- // UpdateCheckedAt sets the "checked_at" field to the value that was provided on create.
- func (u *ChannelMonitorHistoryUpsertBulk) UpdateCheckedAt() *ChannelMonitorHistoryUpsertBulk {
- return u.Update(func(s *ChannelMonitorHistoryUpsert) {
- s.UpdateCheckedAt()
- })
- }
- // Exec executes the query.
- func (u *ChannelMonitorHistoryUpsertBulk) Exec(ctx context.Context) error {
- if u.create.err != nil {
- return u.create.err
- }
- for i, b := range u.create.builders {
- if len(b.conflict) != 0 {
- return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ChannelMonitorHistoryCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for ChannelMonitorHistoryCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *ChannelMonitorHistoryUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|