| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552 |
- // 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/dialect/sql/sqljson"
- "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/channelmonitorhistory"
- "github.com/Wei-Shaw/sub2api/ent/channelmonitorrequesttemplate"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- )
- // ChannelMonitorUpdate is the builder for updating ChannelMonitor entities.
- type ChannelMonitorUpdate struct {
- config
- hooks []Hook
- mutation *ChannelMonitorMutation
- }
- // Where appends a list predicates to the ChannelMonitorUpdate builder.
- func (_u *ChannelMonitorUpdate) Where(ps ...predicate.ChannelMonitor) *ChannelMonitorUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *ChannelMonitorUpdate) SetUpdatedAt(v time.Time) *ChannelMonitorUpdate {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetName sets the "name" field.
- func (_u *ChannelMonitorUpdate) SetName(v string) *ChannelMonitorUpdate {
- _u.mutation.SetName(v)
- return _u
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableName(v *string) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetName(*v)
- }
- return _u
- }
- // SetProvider sets the "provider" field.
- func (_u *ChannelMonitorUpdate) SetProvider(v channelmonitor.Provider) *ChannelMonitorUpdate {
- _u.mutation.SetProvider(v)
- return _u
- }
- // SetNillableProvider sets the "provider" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableProvider(v *channelmonitor.Provider) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetProvider(*v)
- }
- return _u
- }
- // SetCheckMode sets the "check_mode" field.
- func (_u *ChannelMonitorUpdate) SetCheckMode(v string) *ChannelMonitorUpdate {
- _u.mutation.SetCheckMode(v)
- return _u
- }
- // SetNillableCheckMode sets the "check_mode" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableCheckMode(v *string) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetCheckMode(*v)
- }
- return _u
- }
- // SetAccountID sets the "account_id" field.
- func (_u *ChannelMonitorUpdate) SetAccountID(v int64) *ChannelMonitorUpdate {
- _u.mutation.ResetAccountID()
- _u.mutation.SetAccountID(v)
- return _u
- }
- // SetNillableAccountID sets the "account_id" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableAccountID(v *int64) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetAccountID(*v)
- }
- return _u
- }
- // AddAccountID adds value to the "account_id" field.
- func (_u *ChannelMonitorUpdate) AddAccountID(v int64) *ChannelMonitorUpdate {
- _u.mutation.AddAccountID(v)
- return _u
- }
- // ClearAccountID clears the value of the "account_id" field.
- func (_u *ChannelMonitorUpdate) ClearAccountID() *ChannelMonitorUpdate {
- _u.mutation.ClearAccountID()
- return _u
- }
- // SetAPIMode sets the "api_mode" field.
- func (_u *ChannelMonitorUpdate) SetAPIMode(v string) *ChannelMonitorUpdate {
- _u.mutation.SetAPIMode(v)
- return _u
- }
- // SetNillableAPIMode sets the "api_mode" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableAPIMode(v *string) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetAPIMode(*v)
- }
- return _u
- }
- // SetEndpoint sets the "endpoint" field.
- func (_u *ChannelMonitorUpdate) SetEndpoint(v string) *ChannelMonitorUpdate {
- _u.mutation.SetEndpoint(v)
- return _u
- }
- // SetNillableEndpoint sets the "endpoint" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableEndpoint(v *string) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetEndpoint(*v)
- }
- return _u
- }
- // SetAPIKeyEncrypted sets the "api_key_encrypted" field.
- func (_u *ChannelMonitorUpdate) SetAPIKeyEncrypted(v string) *ChannelMonitorUpdate {
- _u.mutation.SetAPIKeyEncrypted(v)
- return _u
- }
- // SetNillableAPIKeyEncrypted sets the "api_key_encrypted" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableAPIKeyEncrypted(v *string) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetAPIKeyEncrypted(*v)
- }
- return _u
- }
- // SetPrimaryModel sets the "primary_model" field.
- func (_u *ChannelMonitorUpdate) SetPrimaryModel(v string) *ChannelMonitorUpdate {
- _u.mutation.SetPrimaryModel(v)
- return _u
- }
- // SetNillablePrimaryModel sets the "primary_model" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillablePrimaryModel(v *string) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetPrimaryModel(*v)
- }
- return _u
- }
- // SetExtraModels sets the "extra_models" field.
- func (_u *ChannelMonitorUpdate) SetExtraModels(v []string) *ChannelMonitorUpdate {
- _u.mutation.SetExtraModels(v)
- return _u
- }
- // AppendExtraModels appends value to the "extra_models" field.
- func (_u *ChannelMonitorUpdate) AppendExtraModels(v []string) *ChannelMonitorUpdate {
- _u.mutation.AppendExtraModels(v)
- return _u
- }
- // SetGroupName sets the "group_name" field.
- func (_u *ChannelMonitorUpdate) SetGroupName(v string) *ChannelMonitorUpdate {
- _u.mutation.SetGroupName(v)
- return _u
- }
- // SetNillableGroupName sets the "group_name" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableGroupName(v *string) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetGroupName(*v)
- }
- return _u
- }
- // ClearGroupName clears the value of the "group_name" field.
- func (_u *ChannelMonitorUpdate) ClearGroupName() *ChannelMonitorUpdate {
- _u.mutation.ClearGroupName()
- return _u
- }
- // SetEnabled sets the "enabled" field.
- func (_u *ChannelMonitorUpdate) SetEnabled(v bool) *ChannelMonitorUpdate {
- _u.mutation.SetEnabled(v)
- return _u
- }
- // SetNillableEnabled sets the "enabled" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableEnabled(v *bool) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetEnabled(*v)
- }
- return _u
- }
- // SetIntervalSeconds sets the "interval_seconds" field.
- func (_u *ChannelMonitorUpdate) SetIntervalSeconds(v int) *ChannelMonitorUpdate {
- _u.mutation.ResetIntervalSeconds()
- _u.mutation.SetIntervalSeconds(v)
- return _u
- }
- // SetNillableIntervalSeconds sets the "interval_seconds" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableIntervalSeconds(v *int) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetIntervalSeconds(*v)
- }
- return _u
- }
- // AddIntervalSeconds adds value to the "interval_seconds" field.
- func (_u *ChannelMonitorUpdate) AddIntervalSeconds(v int) *ChannelMonitorUpdate {
- _u.mutation.AddIntervalSeconds(v)
- return _u
- }
- // SetJitterSeconds sets the "jitter_seconds" field.
- func (_u *ChannelMonitorUpdate) SetJitterSeconds(v int) *ChannelMonitorUpdate {
- _u.mutation.ResetJitterSeconds()
- _u.mutation.SetJitterSeconds(v)
- return _u
- }
- // SetNillableJitterSeconds sets the "jitter_seconds" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableJitterSeconds(v *int) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetJitterSeconds(*v)
- }
- return _u
- }
- // AddJitterSeconds adds value to the "jitter_seconds" field.
- func (_u *ChannelMonitorUpdate) AddJitterSeconds(v int) *ChannelMonitorUpdate {
- _u.mutation.AddJitterSeconds(v)
- return _u
- }
- // SetLastCheckedAt sets the "last_checked_at" field.
- func (_u *ChannelMonitorUpdate) SetLastCheckedAt(v time.Time) *ChannelMonitorUpdate {
- _u.mutation.SetLastCheckedAt(v)
- return _u
- }
- // SetNillableLastCheckedAt sets the "last_checked_at" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableLastCheckedAt(v *time.Time) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetLastCheckedAt(*v)
- }
- return _u
- }
- // ClearLastCheckedAt clears the value of the "last_checked_at" field.
- func (_u *ChannelMonitorUpdate) ClearLastCheckedAt() *ChannelMonitorUpdate {
- _u.mutation.ClearLastCheckedAt()
- return _u
- }
- // SetCreatedBy sets the "created_by" field.
- func (_u *ChannelMonitorUpdate) SetCreatedBy(v int64) *ChannelMonitorUpdate {
- _u.mutation.ResetCreatedBy()
- _u.mutation.SetCreatedBy(v)
- return _u
- }
- // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableCreatedBy(v *int64) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetCreatedBy(*v)
- }
- return _u
- }
- // AddCreatedBy adds value to the "created_by" field.
- func (_u *ChannelMonitorUpdate) AddCreatedBy(v int64) *ChannelMonitorUpdate {
- _u.mutation.AddCreatedBy(v)
- return _u
- }
- // SetTemplateID sets the "template_id" field.
- func (_u *ChannelMonitorUpdate) SetTemplateID(v int64) *ChannelMonitorUpdate {
- _u.mutation.SetTemplateID(v)
- return _u
- }
- // SetNillableTemplateID sets the "template_id" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableTemplateID(v *int64) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetTemplateID(*v)
- }
- return _u
- }
- // ClearTemplateID clears the value of the "template_id" field.
- func (_u *ChannelMonitorUpdate) ClearTemplateID() *ChannelMonitorUpdate {
- _u.mutation.ClearTemplateID()
- return _u
- }
- // SetExtraHeaders sets the "extra_headers" field.
- func (_u *ChannelMonitorUpdate) SetExtraHeaders(v map[string]string) *ChannelMonitorUpdate {
- _u.mutation.SetExtraHeaders(v)
- return _u
- }
- // SetBodyOverrideMode sets the "body_override_mode" field.
- func (_u *ChannelMonitorUpdate) SetBodyOverrideMode(v string) *ChannelMonitorUpdate {
- _u.mutation.SetBodyOverrideMode(v)
- return _u
- }
- // SetNillableBodyOverrideMode sets the "body_override_mode" field if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableBodyOverrideMode(v *string) *ChannelMonitorUpdate {
- if v != nil {
- _u.SetBodyOverrideMode(*v)
- }
- return _u
- }
- // SetBodyOverride sets the "body_override" field.
- func (_u *ChannelMonitorUpdate) SetBodyOverride(v map[string]interface{}) *ChannelMonitorUpdate {
- _u.mutation.SetBodyOverride(v)
- return _u
- }
- // ClearBodyOverride clears the value of the "body_override" field.
- func (_u *ChannelMonitorUpdate) ClearBodyOverride() *ChannelMonitorUpdate {
- _u.mutation.ClearBodyOverride()
- return _u
- }
- // AddHistoryIDs adds the "history" edge to the ChannelMonitorHistory entity by IDs.
- func (_u *ChannelMonitorUpdate) AddHistoryIDs(ids ...int64) *ChannelMonitorUpdate {
- _u.mutation.AddHistoryIDs(ids...)
- return _u
- }
- // AddHistory adds the "history" edges to the ChannelMonitorHistory entity.
- func (_u *ChannelMonitorUpdate) AddHistory(v ...*ChannelMonitorHistory) *ChannelMonitorUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddHistoryIDs(ids...)
- }
- // AddDailyRollupIDs adds the "daily_rollups" edge to the ChannelMonitorDailyRollup entity by IDs.
- func (_u *ChannelMonitorUpdate) AddDailyRollupIDs(ids ...int64) *ChannelMonitorUpdate {
- _u.mutation.AddDailyRollupIDs(ids...)
- return _u
- }
- // AddDailyRollups adds the "daily_rollups" edges to the ChannelMonitorDailyRollup entity.
- func (_u *ChannelMonitorUpdate) AddDailyRollups(v ...*ChannelMonitorDailyRollup) *ChannelMonitorUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddDailyRollupIDs(ids...)
- }
- // SetRequestTemplateID sets the "request_template" edge to the ChannelMonitorRequestTemplate entity by ID.
- func (_u *ChannelMonitorUpdate) SetRequestTemplateID(id int64) *ChannelMonitorUpdate {
- _u.mutation.SetRequestTemplateID(id)
- return _u
- }
- // SetNillableRequestTemplateID sets the "request_template" edge to the ChannelMonitorRequestTemplate entity by ID if the given value is not nil.
- func (_u *ChannelMonitorUpdate) SetNillableRequestTemplateID(id *int64) *ChannelMonitorUpdate {
- if id != nil {
- _u = _u.SetRequestTemplateID(*id)
- }
- return _u
- }
- // SetRequestTemplate sets the "request_template" edge to the ChannelMonitorRequestTemplate entity.
- func (_u *ChannelMonitorUpdate) SetRequestTemplate(v *ChannelMonitorRequestTemplate) *ChannelMonitorUpdate {
- return _u.SetRequestTemplateID(v.ID)
- }
- // Mutation returns the ChannelMonitorMutation object of the builder.
- func (_u *ChannelMonitorUpdate) Mutation() *ChannelMonitorMutation {
- return _u.mutation
- }
- // ClearHistory clears all "history" edges to the ChannelMonitorHistory entity.
- func (_u *ChannelMonitorUpdate) ClearHistory() *ChannelMonitorUpdate {
- _u.mutation.ClearHistory()
- return _u
- }
- // RemoveHistoryIDs removes the "history" edge to ChannelMonitorHistory entities by IDs.
- func (_u *ChannelMonitorUpdate) RemoveHistoryIDs(ids ...int64) *ChannelMonitorUpdate {
- _u.mutation.RemoveHistoryIDs(ids...)
- return _u
- }
- // RemoveHistory removes "history" edges to ChannelMonitorHistory entities.
- func (_u *ChannelMonitorUpdate) RemoveHistory(v ...*ChannelMonitorHistory) *ChannelMonitorUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveHistoryIDs(ids...)
- }
- // ClearDailyRollups clears all "daily_rollups" edges to the ChannelMonitorDailyRollup entity.
- func (_u *ChannelMonitorUpdate) ClearDailyRollups() *ChannelMonitorUpdate {
- _u.mutation.ClearDailyRollups()
- return _u
- }
- // RemoveDailyRollupIDs removes the "daily_rollups" edge to ChannelMonitorDailyRollup entities by IDs.
- func (_u *ChannelMonitorUpdate) RemoveDailyRollupIDs(ids ...int64) *ChannelMonitorUpdate {
- _u.mutation.RemoveDailyRollupIDs(ids...)
- return _u
- }
- // RemoveDailyRollups removes "daily_rollups" edges to ChannelMonitorDailyRollup entities.
- func (_u *ChannelMonitorUpdate) RemoveDailyRollups(v ...*ChannelMonitorDailyRollup) *ChannelMonitorUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveDailyRollupIDs(ids...)
- }
- // ClearRequestTemplate clears the "request_template" edge to the ChannelMonitorRequestTemplate entity.
- func (_u *ChannelMonitorUpdate) ClearRequestTemplate() *ChannelMonitorUpdate {
- _u.mutation.ClearRequestTemplate()
- return _u
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *ChannelMonitorUpdate) 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 *ChannelMonitorUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *ChannelMonitorUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ChannelMonitorUpdate) 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 *ChannelMonitorUpdate) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := channelmonitor.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ChannelMonitorUpdate) check() error {
- if v, ok := _u.mutation.Name(); ok {
- if err := channelmonitor.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.name": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Provider(); ok {
- if err := channelmonitor.ProviderValidator(v); err != nil {
- return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.provider": %w`, err)}
- }
- }
- if v, ok := _u.mutation.CheckMode(); ok {
- if err := channelmonitor.CheckModeValidator(v); err != nil {
- return &ValidationError{Name: "check_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.check_mode": %w`, err)}
- }
- }
- if v, ok := _u.mutation.APIMode(); ok {
- if err := channelmonitor.APIModeValidator(v); err != nil {
- return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_mode": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Endpoint(); ok {
- if err := channelmonitor.EndpointValidator(v); err != nil {
- return &ValidationError{Name: "endpoint", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.endpoint": %w`, err)}
- }
- }
- if v, ok := _u.mutation.APIKeyEncrypted(); ok {
- if err := channelmonitor.APIKeyEncryptedValidator(v); err != nil {
- return &ValidationError{Name: "api_key_encrypted", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_key_encrypted": %w`, err)}
- }
- }
- if v, ok := _u.mutation.PrimaryModel(); ok {
- if err := channelmonitor.PrimaryModelValidator(v); err != nil {
- return &ValidationError{Name: "primary_model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.primary_model": %w`, err)}
- }
- }
- if v, ok := _u.mutation.GroupName(); ok {
- if err := channelmonitor.GroupNameValidator(v); err != nil {
- return &ValidationError{Name: "group_name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.group_name": %w`, err)}
- }
- }
- if v, ok := _u.mutation.IntervalSeconds(); ok {
- if err := channelmonitor.IntervalSecondsValidator(v); err != nil {
- return &ValidationError{Name: "interval_seconds", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.interval_seconds": %w`, err)}
- }
- }
- if v, ok := _u.mutation.JitterSeconds(); ok {
- if err := channelmonitor.JitterSecondsValidator(v); err != nil {
- return &ValidationError{Name: "jitter_seconds", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.jitter_seconds": %w`, err)}
- }
- }
- if v, ok := _u.mutation.BodyOverrideMode(); ok {
- if err := channelmonitor.BodyOverrideModeValidator(v); err != nil {
- return &ValidationError{Name: "body_override_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.body_override_mode": %w`, err)}
- }
- }
- return nil
- }
- func (_u *ChannelMonitorUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(channelmonitor.Table, channelmonitor.Columns, sqlgraph.NewFieldSpec(channelmonitor.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.UpdatedAt(); ok {
- _spec.SetField(channelmonitor.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.Name(); ok {
- _spec.SetField(channelmonitor.FieldName, field.TypeString, value)
- }
- if value, ok := _u.mutation.Provider(); ok {
- _spec.SetField(channelmonitor.FieldProvider, field.TypeEnum, value)
- }
- if value, ok := _u.mutation.CheckMode(); ok {
- _spec.SetField(channelmonitor.FieldCheckMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.AccountID(); ok {
- _spec.SetField(channelmonitor.FieldAccountID, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedAccountID(); ok {
- _spec.AddField(channelmonitor.FieldAccountID, field.TypeInt64, value)
- }
- if _u.mutation.AccountIDCleared() {
- _spec.ClearField(channelmonitor.FieldAccountID, field.TypeInt64)
- }
- if value, ok := _u.mutation.APIMode(); ok {
- _spec.SetField(channelmonitor.FieldAPIMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.Endpoint(); ok {
- _spec.SetField(channelmonitor.FieldEndpoint, field.TypeString, value)
- }
- if value, ok := _u.mutation.APIKeyEncrypted(); ok {
- _spec.SetField(channelmonitor.FieldAPIKeyEncrypted, field.TypeString, value)
- }
- if value, ok := _u.mutation.PrimaryModel(); ok {
- _spec.SetField(channelmonitor.FieldPrimaryModel, field.TypeString, value)
- }
- if value, ok := _u.mutation.ExtraModels(); ok {
- _spec.SetField(channelmonitor.FieldExtraModels, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.AppendedExtraModels(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, channelmonitor.FieldExtraModels, value)
- })
- }
- if value, ok := _u.mutation.GroupName(); ok {
- _spec.SetField(channelmonitor.FieldGroupName, field.TypeString, value)
- }
- if _u.mutation.GroupNameCleared() {
- _spec.ClearField(channelmonitor.FieldGroupName, field.TypeString)
- }
- if value, ok := _u.mutation.Enabled(); ok {
- _spec.SetField(channelmonitor.FieldEnabled, field.TypeBool, value)
- }
- if value, ok := _u.mutation.IntervalSeconds(); ok {
- _spec.SetField(channelmonitor.FieldIntervalSeconds, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedIntervalSeconds(); ok {
- _spec.AddField(channelmonitor.FieldIntervalSeconds, field.TypeInt, value)
- }
- if value, ok := _u.mutation.JitterSeconds(); ok {
- _spec.SetField(channelmonitor.FieldJitterSeconds, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedJitterSeconds(); ok {
- _spec.AddField(channelmonitor.FieldJitterSeconds, field.TypeInt, value)
- }
- if value, ok := _u.mutation.LastCheckedAt(); ok {
- _spec.SetField(channelmonitor.FieldLastCheckedAt, field.TypeTime, value)
- }
- if _u.mutation.LastCheckedAtCleared() {
- _spec.ClearField(channelmonitor.FieldLastCheckedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.CreatedBy(); ok {
- _spec.SetField(channelmonitor.FieldCreatedBy, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedCreatedBy(); ok {
- _spec.AddField(channelmonitor.FieldCreatedBy, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.ExtraHeaders(); ok {
- _spec.SetField(channelmonitor.FieldExtraHeaders, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.BodyOverrideMode(); ok {
- _spec.SetField(channelmonitor.FieldBodyOverrideMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.BodyOverride(); ok {
- _spec.SetField(channelmonitor.FieldBodyOverride, field.TypeJSON, value)
- }
- if _u.mutation.BodyOverrideCleared() {
- _spec.ClearField(channelmonitor.FieldBodyOverride, field.TypeJSON)
- }
- if _u.mutation.HistoryCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.HistoryTable,
- Columns: []string{channelmonitor.HistoryColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedHistoryIDs(); len(nodes) > 0 && !_u.mutation.HistoryCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.HistoryTable,
- Columns: []string{channelmonitor.HistoryColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.HistoryIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.HistoryTable,
- Columns: []string{channelmonitor.HistoryColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.DailyRollupsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.DailyRollupsTable,
- Columns: []string{channelmonitor.DailyRollupsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedDailyRollupsIDs(); len(nodes) > 0 && !_u.mutation.DailyRollupsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.DailyRollupsTable,
- Columns: []string{channelmonitor.DailyRollupsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.DailyRollupsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.DailyRollupsTable,
- Columns: []string{channelmonitor.DailyRollupsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.RequestTemplateCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: channelmonitor.RequestTemplateTable,
- Columns: []string{channelmonitor.RequestTemplateColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RequestTemplateIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: channelmonitor.RequestTemplateTable,
- Columns: []string{channelmonitor.RequestTemplateColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.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{channelmonitor.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // ChannelMonitorUpdateOne is the builder for updating a single ChannelMonitor entity.
- type ChannelMonitorUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *ChannelMonitorMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *ChannelMonitorUpdateOne) SetUpdatedAt(v time.Time) *ChannelMonitorUpdateOne {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetName sets the "name" field.
- func (_u *ChannelMonitorUpdateOne) SetName(v string) *ChannelMonitorUpdateOne {
- _u.mutation.SetName(v)
- return _u
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableName(v *string) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetName(*v)
- }
- return _u
- }
- // SetProvider sets the "provider" field.
- func (_u *ChannelMonitorUpdateOne) SetProvider(v channelmonitor.Provider) *ChannelMonitorUpdateOne {
- _u.mutation.SetProvider(v)
- return _u
- }
- // SetNillableProvider sets the "provider" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableProvider(v *channelmonitor.Provider) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetProvider(*v)
- }
- return _u
- }
- // SetCheckMode sets the "check_mode" field.
- func (_u *ChannelMonitorUpdateOne) SetCheckMode(v string) *ChannelMonitorUpdateOne {
- _u.mutation.SetCheckMode(v)
- return _u
- }
- // SetNillableCheckMode sets the "check_mode" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableCheckMode(v *string) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetCheckMode(*v)
- }
- return _u
- }
- // SetAccountID sets the "account_id" field.
- func (_u *ChannelMonitorUpdateOne) SetAccountID(v int64) *ChannelMonitorUpdateOne {
- _u.mutation.ResetAccountID()
- _u.mutation.SetAccountID(v)
- return _u
- }
- // SetNillableAccountID sets the "account_id" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableAccountID(v *int64) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetAccountID(*v)
- }
- return _u
- }
- // AddAccountID adds value to the "account_id" field.
- func (_u *ChannelMonitorUpdateOne) AddAccountID(v int64) *ChannelMonitorUpdateOne {
- _u.mutation.AddAccountID(v)
- return _u
- }
- // ClearAccountID clears the value of the "account_id" field.
- func (_u *ChannelMonitorUpdateOne) ClearAccountID() *ChannelMonitorUpdateOne {
- _u.mutation.ClearAccountID()
- return _u
- }
- // SetAPIMode sets the "api_mode" field.
- func (_u *ChannelMonitorUpdateOne) SetAPIMode(v string) *ChannelMonitorUpdateOne {
- _u.mutation.SetAPIMode(v)
- return _u
- }
- // SetNillableAPIMode sets the "api_mode" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableAPIMode(v *string) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetAPIMode(*v)
- }
- return _u
- }
- // SetEndpoint sets the "endpoint" field.
- func (_u *ChannelMonitorUpdateOne) SetEndpoint(v string) *ChannelMonitorUpdateOne {
- _u.mutation.SetEndpoint(v)
- return _u
- }
- // SetNillableEndpoint sets the "endpoint" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableEndpoint(v *string) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetEndpoint(*v)
- }
- return _u
- }
- // SetAPIKeyEncrypted sets the "api_key_encrypted" field.
- func (_u *ChannelMonitorUpdateOne) SetAPIKeyEncrypted(v string) *ChannelMonitorUpdateOne {
- _u.mutation.SetAPIKeyEncrypted(v)
- return _u
- }
- // SetNillableAPIKeyEncrypted sets the "api_key_encrypted" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableAPIKeyEncrypted(v *string) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetAPIKeyEncrypted(*v)
- }
- return _u
- }
- // SetPrimaryModel sets the "primary_model" field.
- func (_u *ChannelMonitorUpdateOne) SetPrimaryModel(v string) *ChannelMonitorUpdateOne {
- _u.mutation.SetPrimaryModel(v)
- return _u
- }
- // SetNillablePrimaryModel sets the "primary_model" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillablePrimaryModel(v *string) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetPrimaryModel(*v)
- }
- return _u
- }
- // SetExtraModels sets the "extra_models" field.
- func (_u *ChannelMonitorUpdateOne) SetExtraModels(v []string) *ChannelMonitorUpdateOne {
- _u.mutation.SetExtraModels(v)
- return _u
- }
- // AppendExtraModels appends value to the "extra_models" field.
- func (_u *ChannelMonitorUpdateOne) AppendExtraModels(v []string) *ChannelMonitorUpdateOne {
- _u.mutation.AppendExtraModels(v)
- return _u
- }
- // SetGroupName sets the "group_name" field.
- func (_u *ChannelMonitorUpdateOne) SetGroupName(v string) *ChannelMonitorUpdateOne {
- _u.mutation.SetGroupName(v)
- return _u
- }
- // SetNillableGroupName sets the "group_name" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableGroupName(v *string) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetGroupName(*v)
- }
- return _u
- }
- // ClearGroupName clears the value of the "group_name" field.
- func (_u *ChannelMonitorUpdateOne) ClearGroupName() *ChannelMonitorUpdateOne {
- _u.mutation.ClearGroupName()
- return _u
- }
- // SetEnabled sets the "enabled" field.
- func (_u *ChannelMonitorUpdateOne) SetEnabled(v bool) *ChannelMonitorUpdateOne {
- _u.mutation.SetEnabled(v)
- return _u
- }
- // SetNillableEnabled sets the "enabled" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableEnabled(v *bool) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetEnabled(*v)
- }
- return _u
- }
- // SetIntervalSeconds sets the "interval_seconds" field.
- func (_u *ChannelMonitorUpdateOne) SetIntervalSeconds(v int) *ChannelMonitorUpdateOne {
- _u.mutation.ResetIntervalSeconds()
- _u.mutation.SetIntervalSeconds(v)
- return _u
- }
- // SetNillableIntervalSeconds sets the "interval_seconds" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableIntervalSeconds(v *int) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetIntervalSeconds(*v)
- }
- return _u
- }
- // AddIntervalSeconds adds value to the "interval_seconds" field.
- func (_u *ChannelMonitorUpdateOne) AddIntervalSeconds(v int) *ChannelMonitorUpdateOne {
- _u.mutation.AddIntervalSeconds(v)
- return _u
- }
- // SetJitterSeconds sets the "jitter_seconds" field.
- func (_u *ChannelMonitorUpdateOne) SetJitterSeconds(v int) *ChannelMonitorUpdateOne {
- _u.mutation.ResetJitterSeconds()
- _u.mutation.SetJitterSeconds(v)
- return _u
- }
- // SetNillableJitterSeconds sets the "jitter_seconds" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableJitterSeconds(v *int) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetJitterSeconds(*v)
- }
- return _u
- }
- // AddJitterSeconds adds value to the "jitter_seconds" field.
- func (_u *ChannelMonitorUpdateOne) AddJitterSeconds(v int) *ChannelMonitorUpdateOne {
- _u.mutation.AddJitterSeconds(v)
- return _u
- }
- // SetLastCheckedAt sets the "last_checked_at" field.
- func (_u *ChannelMonitorUpdateOne) SetLastCheckedAt(v time.Time) *ChannelMonitorUpdateOne {
- _u.mutation.SetLastCheckedAt(v)
- return _u
- }
- // SetNillableLastCheckedAt sets the "last_checked_at" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableLastCheckedAt(v *time.Time) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetLastCheckedAt(*v)
- }
- return _u
- }
- // ClearLastCheckedAt clears the value of the "last_checked_at" field.
- func (_u *ChannelMonitorUpdateOne) ClearLastCheckedAt() *ChannelMonitorUpdateOne {
- _u.mutation.ClearLastCheckedAt()
- return _u
- }
- // SetCreatedBy sets the "created_by" field.
- func (_u *ChannelMonitorUpdateOne) SetCreatedBy(v int64) *ChannelMonitorUpdateOne {
- _u.mutation.ResetCreatedBy()
- _u.mutation.SetCreatedBy(v)
- return _u
- }
- // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableCreatedBy(v *int64) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetCreatedBy(*v)
- }
- return _u
- }
- // AddCreatedBy adds value to the "created_by" field.
- func (_u *ChannelMonitorUpdateOne) AddCreatedBy(v int64) *ChannelMonitorUpdateOne {
- _u.mutation.AddCreatedBy(v)
- return _u
- }
- // SetTemplateID sets the "template_id" field.
- func (_u *ChannelMonitorUpdateOne) SetTemplateID(v int64) *ChannelMonitorUpdateOne {
- _u.mutation.SetTemplateID(v)
- return _u
- }
- // SetNillableTemplateID sets the "template_id" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableTemplateID(v *int64) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetTemplateID(*v)
- }
- return _u
- }
- // ClearTemplateID clears the value of the "template_id" field.
- func (_u *ChannelMonitorUpdateOne) ClearTemplateID() *ChannelMonitorUpdateOne {
- _u.mutation.ClearTemplateID()
- return _u
- }
- // SetExtraHeaders sets the "extra_headers" field.
- func (_u *ChannelMonitorUpdateOne) SetExtraHeaders(v map[string]string) *ChannelMonitorUpdateOne {
- _u.mutation.SetExtraHeaders(v)
- return _u
- }
- // SetBodyOverrideMode sets the "body_override_mode" field.
- func (_u *ChannelMonitorUpdateOne) SetBodyOverrideMode(v string) *ChannelMonitorUpdateOne {
- _u.mutation.SetBodyOverrideMode(v)
- return _u
- }
- // SetNillableBodyOverrideMode sets the "body_override_mode" field if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableBodyOverrideMode(v *string) *ChannelMonitorUpdateOne {
- if v != nil {
- _u.SetBodyOverrideMode(*v)
- }
- return _u
- }
- // SetBodyOverride sets the "body_override" field.
- func (_u *ChannelMonitorUpdateOne) SetBodyOverride(v map[string]interface{}) *ChannelMonitorUpdateOne {
- _u.mutation.SetBodyOverride(v)
- return _u
- }
- // ClearBodyOverride clears the value of the "body_override" field.
- func (_u *ChannelMonitorUpdateOne) ClearBodyOverride() *ChannelMonitorUpdateOne {
- _u.mutation.ClearBodyOverride()
- return _u
- }
- // AddHistoryIDs adds the "history" edge to the ChannelMonitorHistory entity by IDs.
- func (_u *ChannelMonitorUpdateOne) AddHistoryIDs(ids ...int64) *ChannelMonitorUpdateOne {
- _u.mutation.AddHistoryIDs(ids...)
- return _u
- }
- // AddHistory adds the "history" edges to the ChannelMonitorHistory entity.
- func (_u *ChannelMonitorUpdateOne) AddHistory(v ...*ChannelMonitorHistory) *ChannelMonitorUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddHistoryIDs(ids...)
- }
- // AddDailyRollupIDs adds the "daily_rollups" edge to the ChannelMonitorDailyRollup entity by IDs.
- func (_u *ChannelMonitorUpdateOne) AddDailyRollupIDs(ids ...int64) *ChannelMonitorUpdateOne {
- _u.mutation.AddDailyRollupIDs(ids...)
- return _u
- }
- // AddDailyRollups adds the "daily_rollups" edges to the ChannelMonitorDailyRollup entity.
- func (_u *ChannelMonitorUpdateOne) AddDailyRollups(v ...*ChannelMonitorDailyRollup) *ChannelMonitorUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddDailyRollupIDs(ids...)
- }
- // SetRequestTemplateID sets the "request_template" edge to the ChannelMonitorRequestTemplate entity by ID.
- func (_u *ChannelMonitorUpdateOne) SetRequestTemplateID(id int64) *ChannelMonitorUpdateOne {
- _u.mutation.SetRequestTemplateID(id)
- return _u
- }
- // SetNillableRequestTemplateID sets the "request_template" edge to the ChannelMonitorRequestTemplate entity by ID if the given value is not nil.
- func (_u *ChannelMonitorUpdateOne) SetNillableRequestTemplateID(id *int64) *ChannelMonitorUpdateOne {
- if id != nil {
- _u = _u.SetRequestTemplateID(*id)
- }
- return _u
- }
- // SetRequestTemplate sets the "request_template" edge to the ChannelMonitorRequestTemplate entity.
- func (_u *ChannelMonitorUpdateOne) SetRequestTemplate(v *ChannelMonitorRequestTemplate) *ChannelMonitorUpdateOne {
- return _u.SetRequestTemplateID(v.ID)
- }
- // Mutation returns the ChannelMonitorMutation object of the builder.
- func (_u *ChannelMonitorUpdateOne) Mutation() *ChannelMonitorMutation {
- return _u.mutation
- }
- // ClearHistory clears all "history" edges to the ChannelMonitorHistory entity.
- func (_u *ChannelMonitorUpdateOne) ClearHistory() *ChannelMonitorUpdateOne {
- _u.mutation.ClearHistory()
- return _u
- }
- // RemoveHistoryIDs removes the "history" edge to ChannelMonitorHistory entities by IDs.
- func (_u *ChannelMonitorUpdateOne) RemoveHistoryIDs(ids ...int64) *ChannelMonitorUpdateOne {
- _u.mutation.RemoveHistoryIDs(ids...)
- return _u
- }
- // RemoveHistory removes "history" edges to ChannelMonitorHistory entities.
- func (_u *ChannelMonitorUpdateOne) RemoveHistory(v ...*ChannelMonitorHistory) *ChannelMonitorUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveHistoryIDs(ids...)
- }
- // ClearDailyRollups clears all "daily_rollups" edges to the ChannelMonitorDailyRollup entity.
- func (_u *ChannelMonitorUpdateOne) ClearDailyRollups() *ChannelMonitorUpdateOne {
- _u.mutation.ClearDailyRollups()
- return _u
- }
- // RemoveDailyRollupIDs removes the "daily_rollups" edge to ChannelMonitorDailyRollup entities by IDs.
- func (_u *ChannelMonitorUpdateOne) RemoveDailyRollupIDs(ids ...int64) *ChannelMonitorUpdateOne {
- _u.mutation.RemoveDailyRollupIDs(ids...)
- return _u
- }
- // RemoveDailyRollups removes "daily_rollups" edges to ChannelMonitorDailyRollup entities.
- func (_u *ChannelMonitorUpdateOne) RemoveDailyRollups(v ...*ChannelMonitorDailyRollup) *ChannelMonitorUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveDailyRollupIDs(ids...)
- }
- // ClearRequestTemplate clears the "request_template" edge to the ChannelMonitorRequestTemplate entity.
- func (_u *ChannelMonitorUpdateOne) ClearRequestTemplate() *ChannelMonitorUpdateOne {
- _u.mutation.ClearRequestTemplate()
- return _u
- }
- // Where appends a list predicates to the ChannelMonitorUpdate builder.
- func (_u *ChannelMonitorUpdateOne) Where(ps ...predicate.ChannelMonitor) *ChannelMonitorUpdateOne {
- _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 *ChannelMonitorUpdateOne) Select(field string, fields ...string) *ChannelMonitorUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated ChannelMonitor entity.
- func (_u *ChannelMonitorUpdateOne) Save(ctx context.Context) (*ChannelMonitor, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ChannelMonitorUpdateOne) SaveX(ctx context.Context) *ChannelMonitor {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *ChannelMonitorUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ChannelMonitorUpdateOne) 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 *ChannelMonitorUpdateOne) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := channelmonitor.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ChannelMonitorUpdateOne) check() error {
- if v, ok := _u.mutation.Name(); ok {
- if err := channelmonitor.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.name": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Provider(); ok {
- if err := channelmonitor.ProviderValidator(v); err != nil {
- return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.provider": %w`, err)}
- }
- }
- if v, ok := _u.mutation.CheckMode(); ok {
- if err := channelmonitor.CheckModeValidator(v); err != nil {
- return &ValidationError{Name: "check_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.check_mode": %w`, err)}
- }
- }
- if v, ok := _u.mutation.APIMode(); ok {
- if err := channelmonitor.APIModeValidator(v); err != nil {
- return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_mode": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Endpoint(); ok {
- if err := channelmonitor.EndpointValidator(v); err != nil {
- return &ValidationError{Name: "endpoint", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.endpoint": %w`, err)}
- }
- }
- if v, ok := _u.mutation.APIKeyEncrypted(); ok {
- if err := channelmonitor.APIKeyEncryptedValidator(v); err != nil {
- return &ValidationError{Name: "api_key_encrypted", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_key_encrypted": %w`, err)}
- }
- }
- if v, ok := _u.mutation.PrimaryModel(); ok {
- if err := channelmonitor.PrimaryModelValidator(v); err != nil {
- return &ValidationError{Name: "primary_model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.primary_model": %w`, err)}
- }
- }
- if v, ok := _u.mutation.GroupName(); ok {
- if err := channelmonitor.GroupNameValidator(v); err != nil {
- return &ValidationError{Name: "group_name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.group_name": %w`, err)}
- }
- }
- if v, ok := _u.mutation.IntervalSeconds(); ok {
- if err := channelmonitor.IntervalSecondsValidator(v); err != nil {
- return &ValidationError{Name: "interval_seconds", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.interval_seconds": %w`, err)}
- }
- }
- if v, ok := _u.mutation.JitterSeconds(); ok {
- if err := channelmonitor.JitterSecondsValidator(v); err != nil {
- return &ValidationError{Name: "jitter_seconds", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.jitter_seconds": %w`, err)}
- }
- }
- if v, ok := _u.mutation.BodyOverrideMode(); ok {
- if err := channelmonitor.BodyOverrideModeValidator(v); err != nil {
- return &ValidationError{Name: "body_override_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.body_override_mode": %w`, err)}
- }
- }
- return nil
- }
- func (_u *ChannelMonitorUpdateOne) sqlSave(ctx context.Context) (_node *ChannelMonitor, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(channelmonitor.Table, channelmonitor.Columns, sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChannelMonitor.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, channelmonitor.FieldID)
- for _, f := range fields {
- if !channelmonitor.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != channelmonitor.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.UpdatedAt(); ok {
- _spec.SetField(channelmonitor.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.Name(); ok {
- _spec.SetField(channelmonitor.FieldName, field.TypeString, value)
- }
- if value, ok := _u.mutation.Provider(); ok {
- _spec.SetField(channelmonitor.FieldProvider, field.TypeEnum, value)
- }
- if value, ok := _u.mutation.CheckMode(); ok {
- _spec.SetField(channelmonitor.FieldCheckMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.AccountID(); ok {
- _spec.SetField(channelmonitor.FieldAccountID, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedAccountID(); ok {
- _spec.AddField(channelmonitor.FieldAccountID, field.TypeInt64, value)
- }
- if _u.mutation.AccountIDCleared() {
- _spec.ClearField(channelmonitor.FieldAccountID, field.TypeInt64)
- }
- if value, ok := _u.mutation.APIMode(); ok {
- _spec.SetField(channelmonitor.FieldAPIMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.Endpoint(); ok {
- _spec.SetField(channelmonitor.FieldEndpoint, field.TypeString, value)
- }
- if value, ok := _u.mutation.APIKeyEncrypted(); ok {
- _spec.SetField(channelmonitor.FieldAPIKeyEncrypted, field.TypeString, value)
- }
- if value, ok := _u.mutation.PrimaryModel(); ok {
- _spec.SetField(channelmonitor.FieldPrimaryModel, field.TypeString, value)
- }
- if value, ok := _u.mutation.ExtraModels(); ok {
- _spec.SetField(channelmonitor.FieldExtraModels, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.AppendedExtraModels(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, channelmonitor.FieldExtraModels, value)
- })
- }
- if value, ok := _u.mutation.GroupName(); ok {
- _spec.SetField(channelmonitor.FieldGroupName, field.TypeString, value)
- }
- if _u.mutation.GroupNameCleared() {
- _spec.ClearField(channelmonitor.FieldGroupName, field.TypeString)
- }
- if value, ok := _u.mutation.Enabled(); ok {
- _spec.SetField(channelmonitor.FieldEnabled, field.TypeBool, value)
- }
- if value, ok := _u.mutation.IntervalSeconds(); ok {
- _spec.SetField(channelmonitor.FieldIntervalSeconds, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedIntervalSeconds(); ok {
- _spec.AddField(channelmonitor.FieldIntervalSeconds, field.TypeInt, value)
- }
- if value, ok := _u.mutation.JitterSeconds(); ok {
- _spec.SetField(channelmonitor.FieldJitterSeconds, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedJitterSeconds(); ok {
- _spec.AddField(channelmonitor.FieldJitterSeconds, field.TypeInt, value)
- }
- if value, ok := _u.mutation.LastCheckedAt(); ok {
- _spec.SetField(channelmonitor.FieldLastCheckedAt, field.TypeTime, value)
- }
- if _u.mutation.LastCheckedAtCleared() {
- _spec.ClearField(channelmonitor.FieldLastCheckedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.CreatedBy(); ok {
- _spec.SetField(channelmonitor.FieldCreatedBy, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedCreatedBy(); ok {
- _spec.AddField(channelmonitor.FieldCreatedBy, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.ExtraHeaders(); ok {
- _spec.SetField(channelmonitor.FieldExtraHeaders, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.BodyOverrideMode(); ok {
- _spec.SetField(channelmonitor.FieldBodyOverrideMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.BodyOverride(); ok {
- _spec.SetField(channelmonitor.FieldBodyOverride, field.TypeJSON, value)
- }
- if _u.mutation.BodyOverrideCleared() {
- _spec.ClearField(channelmonitor.FieldBodyOverride, field.TypeJSON)
- }
- if _u.mutation.HistoryCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.HistoryTable,
- Columns: []string{channelmonitor.HistoryColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedHistoryIDs(); len(nodes) > 0 && !_u.mutation.HistoryCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.HistoryTable,
- Columns: []string{channelmonitor.HistoryColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.HistoryIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.HistoryTable,
- Columns: []string{channelmonitor.HistoryColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.DailyRollupsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.DailyRollupsTable,
- Columns: []string{channelmonitor.DailyRollupsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedDailyRollupsIDs(); len(nodes) > 0 && !_u.mutation.DailyRollupsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.DailyRollupsTable,
- Columns: []string{channelmonitor.DailyRollupsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.DailyRollupsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: channelmonitor.DailyRollupsTable,
- Columns: []string{channelmonitor.DailyRollupsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.RequestTemplateCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: channelmonitor.RequestTemplateTable,
- Columns: []string{channelmonitor.RequestTemplateColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RequestTemplateIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: channelmonitor.RequestTemplateTable,
- Columns: []string{channelmonitor.RequestTemplateColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &ChannelMonitor{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{channelmonitor.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|