channelmonitor_update.go 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/dialect/sql/sqljson"
  11. "entgo.io/ent/schema/field"
  12. "github.com/Wei-Shaw/sub2api/ent/channelmonitor"
  13. "github.com/Wei-Shaw/sub2api/ent/channelmonitordailyrollup"
  14. "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory"
  15. "github.com/Wei-Shaw/sub2api/ent/channelmonitorrequesttemplate"
  16. "github.com/Wei-Shaw/sub2api/ent/predicate"
  17. )
  18. // ChannelMonitorUpdate is the builder for updating ChannelMonitor entities.
  19. type ChannelMonitorUpdate struct {
  20. config
  21. hooks []Hook
  22. mutation *ChannelMonitorMutation
  23. }
  24. // Where appends a list predicates to the ChannelMonitorUpdate builder.
  25. func (_u *ChannelMonitorUpdate) Where(ps ...predicate.ChannelMonitor) *ChannelMonitorUpdate {
  26. _u.mutation.Where(ps...)
  27. return _u
  28. }
  29. // SetUpdatedAt sets the "updated_at" field.
  30. func (_u *ChannelMonitorUpdate) SetUpdatedAt(v time.Time) *ChannelMonitorUpdate {
  31. _u.mutation.SetUpdatedAt(v)
  32. return _u
  33. }
  34. // SetName sets the "name" field.
  35. func (_u *ChannelMonitorUpdate) SetName(v string) *ChannelMonitorUpdate {
  36. _u.mutation.SetName(v)
  37. return _u
  38. }
  39. // SetNillableName sets the "name" field if the given value is not nil.
  40. func (_u *ChannelMonitorUpdate) SetNillableName(v *string) *ChannelMonitorUpdate {
  41. if v != nil {
  42. _u.SetName(*v)
  43. }
  44. return _u
  45. }
  46. // SetProvider sets the "provider" field.
  47. func (_u *ChannelMonitorUpdate) SetProvider(v channelmonitor.Provider) *ChannelMonitorUpdate {
  48. _u.mutation.SetProvider(v)
  49. return _u
  50. }
  51. // SetNillableProvider sets the "provider" field if the given value is not nil.
  52. func (_u *ChannelMonitorUpdate) SetNillableProvider(v *channelmonitor.Provider) *ChannelMonitorUpdate {
  53. if v != nil {
  54. _u.SetProvider(*v)
  55. }
  56. return _u
  57. }
  58. // SetCheckMode sets the "check_mode" field.
  59. func (_u *ChannelMonitorUpdate) SetCheckMode(v string) *ChannelMonitorUpdate {
  60. _u.mutation.SetCheckMode(v)
  61. return _u
  62. }
  63. // SetNillableCheckMode sets the "check_mode" field if the given value is not nil.
  64. func (_u *ChannelMonitorUpdate) SetNillableCheckMode(v *string) *ChannelMonitorUpdate {
  65. if v != nil {
  66. _u.SetCheckMode(*v)
  67. }
  68. return _u
  69. }
  70. // SetAccountID sets the "account_id" field.
  71. func (_u *ChannelMonitorUpdate) SetAccountID(v int64) *ChannelMonitorUpdate {
  72. _u.mutation.ResetAccountID()
  73. _u.mutation.SetAccountID(v)
  74. return _u
  75. }
  76. // SetNillableAccountID sets the "account_id" field if the given value is not nil.
  77. func (_u *ChannelMonitorUpdate) SetNillableAccountID(v *int64) *ChannelMonitorUpdate {
  78. if v != nil {
  79. _u.SetAccountID(*v)
  80. }
  81. return _u
  82. }
  83. // AddAccountID adds value to the "account_id" field.
  84. func (_u *ChannelMonitorUpdate) AddAccountID(v int64) *ChannelMonitorUpdate {
  85. _u.mutation.AddAccountID(v)
  86. return _u
  87. }
  88. // ClearAccountID clears the value of the "account_id" field.
  89. func (_u *ChannelMonitorUpdate) ClearAccountID() *ChannelMonitorUpdate {
  90. _u.mutation.ClearAccountID()
  91. return _u
  92. }
  93. // SetAPIMode sets the "api_mode" field.
  94. func (_u *ChannelMonitorUpdate) SetAPIMode(v string) *ChannelMonitorUpdate {
  95. _u.mutation.SetAPIMode(v)
  96. return _u
  97. }
  98. // SetNillableAPIMode sets the "api_mode" field if the given value is not nil.
  99. func (_u *ChannelMonitorUpdate) SetNillableAPIMode(v *string) *ChannelMonitorUpdate {
  100. if v != nil {
  101. _u.SetAPIMode(*v)
  102. }
  103. return _u
  104. }
  105. // SetEndpoint sets the "endpoint" field.
  106. func (_u *ChannelMonitorUpdate) SetEndpoint(v string) *ChannelMonitorUpdate {
  107. _u.mutation.SetEndpoint(v)
  108. return _u
  109. }
  110. // SetNillableEndpoint sets the "endpoint" field if the given value is not nil.
  111. func (_u *ChannelMonitorUpdate) SetNillableEndpoint(v *string) *ChannelMonitorUpdate {
  112. if v != nil {
  113. _u.SetEndpoint(*v)
  114. }
  115. return _u
  116. }
  117. // SetAPIKeyEncrypted sets the "api_key_encrypted" field.
  118. func (_u *ChannelMonitorUpdate) SetAPIKeyEncrypted(v string) *ChannelMonitorUpdate {
  119. _u.mutation.SetAPIKeyEncrypted(v)
  120. return _u
  121. }
  122. // SetNillableAPIKeyEncrypted sets the "api_key_encrypted" field if the given value is not nil.
  123. func (_u *ChannelMonitorUpdate) SetNillableAPIKeyEncrypted(v *string) *ChannelMonitorUpdate {
  124. if v != nil {
  125. _u.SetAPIKeyEncrypted(*v)
  126. }
  127. return _u
  128. }
  129. // SetPrimaryModel sets the "primary_model" field.
  130. func (_u *ChannelMonitorUpdate) SetPrimaryModel(v string) *ChannelMonitorUpdate {
  131. _u.mutation.SetPrimaryModel(v)
  132. return _u
  133. }
  134. // SetNillablePrimaryModel sets the "primary_model" field if the given value is not nil.
  135. func (_u *ChannelMonitorUpdate) SetNillablePrimaryModel(v *string) *ChannelMonitorUpdate {
  136. if v != nil {
  137. _u.SetPrimaryModel(*v)
  138. }
  139. return _u
  140. }
  141. // SetExtraModels sets the "extra_models" field.
  142. func (_u *ChannelMonitorUpdate) SetExtraModels(v []string) *ChannelMonitorUpdate {
  143. _u.mutation.SetExtraModels(v)
  144. return _u
  145. }
  146. // AppendExtraModels appends value to the "extra_models" field.
  147. func (_u *ChannelMonitorUpdate) AppendExtraModels(v []string) *ChannelMonitorUpdate {
  148. _u.mutation.AppendExtraModels(v)
  149. return _u
  150. }
  151. // SetGroupName sets the "group_name" field.
  152. func (_u *ChannelMonitorUpdate) SetGroupName(v string) *ChannelMonitorUpdate {
  153. _u.mutation.SetGroupName(v)
  154. return _u
  155. }
  156. // SetNillableGroupName sets the "group_name" field if the given value is not nil.
  157. func (_u *ChannelMonitorUpdate) SetNillableGroupName(v *string) *ChannelMonitorUpdate {
  158. if v != nil {
  159. _u.SetGroupName(*v)
  160. }
  161. return _u
  162. }
  163. // ClearGroupName clears the value of the "group_name" field.
  164. func (_u *ChannelMonitorUpdate) ClearGroupName() *ChannelMonitorUpdate {
  165. _u.mutation.ClearGroupName()
  166. return _u
  167. }
  168. // SetEnabled sets the "enabled" field.
  169. func (_u *ChannelMonitorUpdate) SetEnabled(v bool) *ChannelMonitorUpdate {
  170. _u.mutation.SetEnabled(v)
  171. return _u
  172. }
  173. // SetNillableEnabled sets the "enabled" field if the given value is not nil.
  174. func (_u *ChannelMonitorUpdate) SetNillableEnabled(v *bool) *ChannelMonitorUpdate {
  175. if v != nil {
  176. _u.SetEnabled(*v)
  177. }
  178. return _u
  179. }
  180. // SetIntervalSeconds sets the "interval_seconds" field.
  181. func (_u *ChannelMonitorUpdate) SetIntervalSeconds(v int) *ChannelMonitorUpdate {
  182. _u.mutation.ResetIntervalSeconds()
  183. _u.mutation.SetIntervalSeconds(v)
  184. return _u
  185. }
  186. // SetNillableIntervalSeconds sets the "interval_seconds" field if the given value is not nil.
  187. func (_u *ChannelMonitorUpdate) SetNillableIntervalSeconds(v *int) *ChannelMonitorUpdate {
  188. if v != nil {
  189. _u.SetIntervalSeconds(*v)
  190. }
  191. return _u
  192. }
  193. // AddIntervalSeconds adds value to the "interval_seconds" field.
  194. func (_u *ChannelMonitorUpdate) AddIntervalSeconds(v int) *ChannelMonitorUpdate {
  195. _u.mutation.AddIntervalSeconds(v)
  196. return _u
  197. }
  198. // SetJitterSeconds sets the "jitter_seconds" field.
  199. func (_u *ChannelMonitorUpdate) SetJitterSeconds(v int) *ChannelMonitorUpdate {
  200. _u.mutation.ResetJitterSeconds()
  201. _u.mutation.SetJitterSeconds(v)
  202. return _u
  203. }
  204. // SetNillableJitterSeconds sets the "jitter_seconds" field if the given value is not nil.
  205. func (_u *ChannelMonitorUpdate) SetNillableJitterSeconds(v *int) *ChannelMonitorUpdate {
  206. if v != nil {
  207. _u.SetJitterSeconds(*v)
  208. }
  209. return _u
  210. }
  211. // AddJitterSeconds adds value to the "jitter_seconds" field.
  212. func (_u *ChannelMonitorUpdate) AddJitterSeconds(v int) *ChannelMonitorUpdate {
  213. _u.mutation.AddJitterSeconds(v)
  214. return _u
  215. }
  216. // SetLastCheckedAt sets the "last_checked_at" field.
  217. func (_u *ChannelMonitorUpdate) SetLastCheckedAt(v time.Time) *ChannelMonitorUpdate {
  218. _u.mutation.SetLastCheckedAt(v)
  219. return _u
  220. }
  221. // SetNillableLastCheckedAt sets the "last_checked_at" field if the given value is not nil.
  222. func (_u *ChannelMonitorUpdate) SetNillableLastCheckedAt(v *time.Time) *ChannelMonitorUpdate {
  223. if v != nil {
  224. _u.SetLastCheckedAt(*v)
  225. }
  226. return _u
  227. }
  228. // ClearLastCheckedAt clears the value of the "last_checked_at" field.
  229. func (_u *ChannelMonitorUpdate) ClearLastCheckedAt() *ChannelMonitorUpdate {
  230. _u.mutation.ClearLastCheckedAt()
  231. return _u
  232. }
  233. // SetCreatedBy sets the "created_by" field.
  234. func (_u *ChannelMonitorUpdate) SetCreatedBy(v int64) *ChannelMonitorUpdate {
  235. _u.mutation.ResetCreatedBy()
  236. _u.mutation.SetCreatedBy(v)
  237. return _u
  238. }
  239. // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
  240. func (_u *ChannelMonitorUpdate) SetNillableCreatedBy(v *int64) *ChannelMonitorUpdate {
  241. if v != nil {
  242. _u.SetCreatedBy(*v)
  243. }
  244. return _u
  245. }
  246. // AddCreatedBy adds value to the "created_by" field.
  247. func (_u *ChannelMonitorUpdate) AddCreatedBy(v int64) *ChannelMonitorUpdate {
  248. _u.mutation.AddCreatedBy(v)
  249. return _u
  250. }
  251. // SetTemplateID sets the "template_id" field.
  252. func (_u *ChannelMonitorUpdate) SetTemplateID(v int64) *ChannelMonitorUpdate {
  253. _u.mutation.SetTemplateID(v)
  254. return _u
  255. }
  256. // SetNillableTemplateID sets the "template_id" field if the given value is not nil.
  257. func (_u *ChannelMonitorUpdate) SetNillableTemplateID(v *int64) *ChannelMonitorUpdate {
  258. if v != nil {
  259. _u.SetTemplateID(*v)
  260. }
  261. return _u
  262. }
  263. // ClearTemplateID clears the value of the "template_id" field.
  264. func (_u *ChannelMonitorUpdate) ClearTemplateID() *ChannelMonitorUpdate {
  265. _u.mutation.ClearTemplateID()
  266. return _u
  267. }
  268. // SetExtraHeaders sets the "extra_headers" field.
  269. func (_u *ChannelMonitorUpdate) SetExtraHeaders(v map[string]string) *ChannelMonitorUpdate {
  270. _u.mutation.SetExtraHeaders(v)
  271. return _u
  272. }
  273. // SetBodyOverrideMode sets the "body_override_mode" field.
  274. func (_u *ChannelMonitorUpdate) SetBodyOverrideMode(v string) *ChannelMonitorUpdate {
  275. _u.mutation.SetBodyOverrideMode(v)
  276. return _u
  277. }
  278. // SetNillableBodyOverrideMode sets the "body_override_mode" field if the given value is not nil.
  279. func (_u *ChannelMonitorUpdate) SetNillableBodyOverrideMode(v *string) *ChannelMonitorUpdate {
  280. if v != nil {
  281. _u.SetBodyOverrideMode(*v)
  282. }
  283. return _u
  284. }
  285. // SetBodyOverride sets the "body_override" field.
  286. func (_u *ChannelMonitorUpdate) SetBodyOverride(v map[string]interface{}) *ChannelMonitorUpdate {
  287. _u.mutation.SetBodyOverride(v)
  288. return _u
  289. }
  290. // ClearBodyOverride clears the value of the "body_override" field.
  291. func (_u *ChannelMonitorUpdate) ClearBodyOverride() *ChannelMonitorUpdate {
  292. _u.mutation.ClearBodyOverride()
  293. return _u
  294. }
  295. // AddHistoryIDs adds the "history" edge to the ChannelMonitorHistory entity by IDs.
  296. func (_u *ChannelMonitorUpdate) AddHistoryIDs(ids ...int64) *ChannelMonitorUpdate {
  297. _u.mutation.AddHistoryIDs(ids...)
  298. return _u
  299. }
  300. // AddHistory adds the "history" edges to the ChannelMonitorHistory entity.
  301. func (_u *ChannelMonitorUpdate) AddHistory(v ...*ChannelMonitorHistory) *ChannelMonitorUpdate {
  302. ids := make([]int64, len(v))
  303. for i := range v {
  304. ids[i] = v[i].ID
  305. }
  306. return _u.AddHistoryIDs(ids...)
  307. }
  308. // AddDailyRollupIDs adds the "daily_rollups" edge to the ChannelMonitorDailyRollup entity by IDs.
  309. func (_u *ChannelMonitorUpdate) AddDailyRollupIDs(ids ...int64) *ChannelMonitorUpdate {
  310. _u.mutation.AddDailyRollupIDs(ids...)
  311. return _u
  312. }
  313. // AddDailyRollups adds the "daily_rollups" edges to the ChannelMonitorDailyRollup entity.
  314. func (_u *ChannelMonitorUpdate) AddDailyRollups(v ...*ChannelMonitorDailyRollup) *ChannelMonitorUpdate {
  315. ids := make([]int64, len(v))
  316. for i := range v {
  317. ids[i] = v[i].ID
  318. }
  319. return _u.AddDailyRollupIDs(ids...)
  320. }
  321. // SetRequestTemplateID sets the "request_template" edge to the ChannelMonitorRequestTemplate entity by ID.
  322. func (_u *ChannelMonitorUpdate) SetRequestTemplateID(id int64) *ChannelMonitorUpdate {
  323. _u.mutation.SetRequestTemplateID(id)
  324. return _u
  325. }
  326. // SetNillableRequestTemplateID sets the "request_template" edge to the ChannelMonitorRequestTemplate entity by ID if the given value is not nil.
  327. func (_u *ChannelMonitorUpdate) SetNillableRequestTemplateID(id *int64) *ChannelMonitorUpdate {
  328. if id != nil {
  329. _u = _u.SetRequestTemplateID(*id)
  330. }
  331. return _u
  332. }
  333. // SetRequestTemplate sets the "request_template" edge to the ChannelMonitorRequestTemplate entity.
  334. func (_u *ChannelMonitorUpdate) SetRequestTemplate(v *ChannelMonitorRequestTemplate) *ChannelMonitorUpdate {
  335. return _u.SetRequestTemplateID(v.ID)
  336. }
  337. // Mutation returns the ChannelMonitorMutation object of the builder.
  338. func (_u *ChannelMonitorUpdate) Mutation() *ChannelMonitorMutation {
  339. return _u.mutation
  340. }
  341. // ClearHistory clears all "history" edges to the ChannelMonitorHistory entity.
  342. func (_u *ChannelMonitorUpdate) ClearHistory() *ChannelMonitorUpdate {
  343. _u.mutation.ClearHistory()
  344. return _u
  345. }
  346. // RemoveHistoryIDs removes the "history" edge to ChannelMonitorHistory entities by IDs.
  347. func (_u *ChannelMonitorUpdate) RemoveHistoryIDs(ids ...int64) *ChannelMonitorUpdate {
  348. _u.mutation.RemoveHistoryIDs(ids...)
  349. return _u
  350. }
  351. // RemoveHistory removes "history" edges to ChannelMonitorHistory entities.
  352. func (_u *ChannelMonitorUpdate) RemoveHistory(v ...*ChannelMonitorHistory) *ChannelMonitorUpdate {
  353. ids := make([]int64, len(v))
  354. for i := range v {
  355. ids[i] = v[i].ID
  356. }
  357. return _u.RemoveHistoryIDs(ids...)
  358. }
  359. // ClearDailyRollups clears all "daily_rollups" edges to the ChannelMonitorDailyRollup entity.
  360. func (_u *ChannelMonitorUpdate) ClearDailyRollups() *ChannelMonitorUpdate {
  361. _u.mutation.ClearDailyRollups()
  362. return _u
  363. }
  364. // RemoveDailyRollupIDs removes the "daily_rollups" edge to ChannelMonitorDailyRollup entities by IDs.
  365. func (_u *ChannelMonitorUpdate) RemoveDailyRollupIDs(ids ...int64) *ChannelMonitorUpdate {
  366. _u.mutation.RemoveDailyRollupIDs(ids...)
  367. return _u
  368. }
  369. // RemoveDailyRollups removes "daily_rollups" edges to ChannelMonitorDailyRollup entities.
  370. func (_u *ChannelMonitorUpdate) RemoveDailyRollups(v ...*ChannelMonitorDailyRollup) *ChannelMonitorUpdate {
  371. ids := make([]int64, len(v))
  372. for i := range v {
  373. ids[i] = v[i].ID
  374. }
  375. return _u.RemoveDailyRollupIDs(ids...)
  376. }
  377. // ClearRequestTemplate clears the "request_template" edge to the ChannelMonitorRequestTemplate entity.
  378. func (_u *ChannelMonitorUpdate) ClearRequestTemplate() *ChannelMonitorUpdate {
  379. _u.mutation.ClearRequestTemplate()
  380. return _u
  381. }
  382. // Save executes the query and returns the number of nodes affected by the update operation.
  383. func (_u *ChannelMonitorUpdate) Save(ctx context.Context) (int, error) {
  384. _u.defaults()
  385. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  386. }
  387. // SaveX is like Save, but panics if an error occurs.
  388. func (_u *ChannelMonitorUpdate) SaveX(ctx context.Context) int {
  389. affected, err := _u.Save(ctx)
  390. if err != nil {
  391. panic(err)
  392. }
  393. return affected
  394. }
  395. // Exec executes the query.
  396. func (_u *ChannelMonitorUpdate) Exec(ctx context.Context) error {
  397. _, err := _u.Save(ctx)
  398. return err
  399. }
  400. // ExecX is like Exec, but panics if an error occurs.
  401. func (_u *ChannelMonitorUpdate) ExecX(ctx context.Context) {
  402. if err := _u.Exec(ctx); err != nil {
  403. panic(err)
  404. }
  405. }
  406. // defaults sets the default values of the builder before save.
  407. func (_u *ChannelMonitorUpdate) defaults() {
  408. if _, ok := _u.mutation.UpdatedAt(); !ok {
  409. v := channelmonitor.UpdateDefaultUpdatedAt()
  410. _u.mutation.SetUpdatedAt(v)
  411. }
  412. }
  413. // check runs all checks and user-defined validators on the builder.
  414. func (_u *ChannelMonitorUpdate) check() error {
  415. if v, ok := _u.mutation.Name(); ok {
  416. if err := channelmonitor.NameValidator(v); err != nil {
  417. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.name": %w`, err)}
  418. }
  419. }
  420. if v, ok := _u.mutation.Provider(); ok {
  421. if err := channelmonitor.ProviderValidator(v); err != nil {
  422. return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.provider": %w`, err)}
  423. }
  424. }
  425. if v, ok := _u.mutation.CheckMode(); ok {
  426. if err := channelmonitor.CheckModeValidator(v); err != nil {
  427. return &ValidationError{Name: "check_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.check_mode": %w`, err)}
  428. }
  429. }
  430. if v, ok := _u.mutation.APIMode(); ok {
  431. if err := channelmonitor.APIModeValidator(v); err != nil {
  432. return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_mode": %w`, err)}
  433. }
  434. }
  435. if v, ok := _u.mutation.Endpoint(); ok {
  436. if err := channelmonitor.EndpointValidator(v); err != nil {
  437. return &ValidationError{Name: "endpoint", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.endpoint": %w`, err)}
  438. }
  439. }
  440. if v, ok := _u.mutation.APIKeyEncrypted(); ok {
  441. if err := channelmonitor.APIKeyEncryptedValidator(v); err != nil {
  442. return &ValidationError{Name: "api_key_encrypted", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_key_encrypted": %w`, err)}
  443. }
  444. }
  445. if v, ok := _u.mutation.PrimaryModel(); ok {
  446. if err := channelmonitor.PrimaryModelValidator(v); err != nil {
  447. return &ValidationError{Name: "primary_model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.primary_model": %w`, err)}
  448. }
  449. }
  450. if v, ok := _u.mutation.GroupName(); ok {
  451. if err := channelmonitor.GroupNameValidator(v); err != nil {
  452. return &ValidationError{Name: "group_name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.group_name": %w`, err)}
  453. }
  454. }
  455. if v, ok := _u.mutation.IntervalSeconds(); ok {
  456. if err := channelmonitor.IntervalSecondsValidator(v); err != nil {
  457. return &ValidationError{Name: "interval_seconds", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.interval_seconds": %w`, err)}
  458. }
  459. }
  460. if v, ok := _u.mutation.JitterSeconds(); ok {
  461. if err := channelmonitor.JitterSecondsValidator(v); err != nil {
  462. return &ValidationError{Name: "jitter_seconds", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.jitter_seconds": %w`, err)}
  463. }
  464. }
  465. if v, ok := _u.mutation.BodyOverrideMode(); ok {
  466. if err := channelmonitor.BodyOverrideModeValidator(v); err != nil {
  467. return &ValidationError{Name: "body_override_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.body_override_mode": %w`, err)}
  468. }
  469. }
  470. return nil
  471. }
  472. func (_u *ChannelMonitorUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  473. if err := _u.check(); err != nil {
  474. return _node, err
  475. }
  476. _spec := sqlgraph.NewUpdateSpec(channelmonitor.Table, channelmonitor.Columns, sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64))
  477. if ps := _u.mutation.predicates; len(ps) > 0 {
  478. _spec.Predicate = func(selector *sql.Selector) {
  479. for i := range ps {
  480. ps[i](selector)
  481. }
  482. }
  483. }
  484. if value, ok := _u.mutation.UpdatedAt(); ok {
  485. _spec.SetField(channelmonitor.FieldUpdatedAt, field.TypeTime, value)
  486. }
  487. if value, ok := _u.mutation.Name(); ok {
  488. _spec.SetField(channelmonitor.FieldName, field.TypeString, value)
  489. }
  490. if value, ok := _u.mutation.Provider(); ok {
  491. _spec.SetField(channelmonitor.FieldProvider, field.TypeEnum, value)
  492. }
  493. if value, ok := _u.mutation.CheckMode(); ok {
  494. _spec.SetField(channelmonitor.FieldCheckMode, field.TypeString, value)
  495. }
  496. if value, ok := _u.mutation.AccountID(); ok {
  497. _spec.SetField(channelmonitor.FieldAccountID, field.TypeInt64, value)
  498. }
  499. if value, ok := _u.mutation.AddedAccountID(); ok {
  500. _spec.AddField(channelmonitor.FieldAccountID, field.TypeInt64, value)
  501. }
  502. if _u.mutation.AccountIDCleared() {
  503. _spec.ClearField(channelmonitor.FieldAccountID, field.TypeInt64)
  504. }
  505. if value, ok := _u.mutation.APIMode(); ok {
  506. _spec.SetField(channelmonitor.FieldAPIMode, field.TypeString, value)
  507. }
  508. if value, ok := _u.mutation.Endpoint(); ok {
  509. _spec.SetField(channelmonitor.FieldEndpoint, field.TypeString, value)
  510. }
  511. if value, ok := _u.mutation.APIKeyEncrypted(); ok {
  512. _spec.SetField(channelmonitor.FieldAPIKeyEncrypted, field.TypeString, value)
  513. }
  514. if value, ok := _u.mutation.PrimaryModel(); ok {
  515. _spec.SetField(channelmonitor.FieldPrimaryModel, field.TypeString, value)
  516. }
  517. if value, ok := _u.mutation.ExtraModels(); ok {
  518. _spec.SetField(channelmonitor.FieldExtraModels, field.TypeJSON, value)
  519. }
  520. if value, ok := _u.mutation.AppendedExtraModels(); ok {
  521. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  522. sqljson.Append(u, channelmonitor.FieldExtraModels, value)
  523. })
  524. }
  525. if value, ok := _u.mutation.GroupName(); ok {
  526. _spec.SetField(channelmonitor.FieldGroupName, field.TypeString, value)
  527. }
  528. if _u.mutation.GroupNameCleared() {
  529. _spec.ClearField(channelmonitor.FieldGroupName, field.TypeString)
  530. }
  531. if value, ok := _u.mutation.Enabled(); ok {
  532. _spec.SetField(channelmonitor.FieldEnabled, field.TypeBool, value)
  533. }
  534. if value, ok := _u.mutation.IntervalSeconds(); ok {
  535. _spec.SetField(channelmonitor.FieldIntervalSeconds, field.TypeInt, value)
  536. }
  537. if value, ok := _u.mutation.AddedIntervalSeconds(); ok {
  538. _spec.AddField(channelmonitor.FieldIntervalSeconds, field.TypeInt, value)
  539. }
  540. if value, ok := _u.mutation.JitterSeconds(); ok {
  541. _spec.SetField(channelmonitor.FieldJitterSeconds, field.TypeInt, value)
  542. }
  543. if value, ok := _u.mutation.AddedJitterSeconds(); ok {
  544. _spec.AddField(channelmonitor.FieldJitterSeconds, field.TypeInt, value)
  545. }
  546. if value, ok := _u.mutation.LastCheckedAt(); ok {
  547. _spec.SetField(channelmonitor.FieldLastCheckedAt, field.TypeTime, value)
  548. }
  549. if _u.mutation.LastCheckedAtCleared() {
  550. _spec.ClearField(channelmonitor.FieldLastCheckedAt, field.TypeTime)
  551. }
  552. if value, ok := _u.mutation.CreatedBy(); ok {
  553. _spec.SetField(channelmonitor.FieldCreatedBy, field.TypeInt64, value)
  554. }
  555. if value, ok := _u.mutation.AddedCreatedBy(); ok {
  556. _spec.AddField(channelmonitor.FieldCreatedBy, field.TypeInt64, value)
  557. }
  558. if value, ok := _u.mutation.ExtraHeaders(); ok {
  559. _spec.SetField(channelmonitor.FieldExtraHeaders, field.TypeJSON, value)
  560. }
  561. if value, ok := _u.mutation.BodyOverrideMode(); ok {
  562. _spec.SetField(channelmonitor.FieldBodyOverrideMode, field.TypeString, value)
  563. }
  564. if value, ok := _u.mutation.BodyOverride(); ok {
  565. _spec.SetField(channelmonitor.FieldBodyOverride, field.TypeJSON, value)
  566. }
  567. if _u.mutation.BodyOverrideCleared() {
  568. _spec.ClearField(channelmonitor.FieldBodyOverride, field.TypeJSON)
  569. }
  570. if _u.mutation.HistoryCleared() {
  571. edge := &sqlgraph.EdgeSpec{
  572. Rel: sqlgraph.O2M,
  573. Inverse: false,
  574. Table: channelmonitor.HistoryTable,
  575. Columns: []string{channelmonitor.HistoryColumn},
  576. Bidi: false,
  577. Target: &sqlgraph.EdgeTarget{
  578. IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
  579. },
  580. }
  581. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  582. }
  583. if nodes := _u.mutation.RemovedHistoryIDs(); len(nodes) > 0 && !_u.mutation.HistoryCleared() {
  584. edge := &sqlgraph.EdgeSpec{
  585. Rel: sqlgraph.O2M,
  586. Inverse: false,
  587. Table: channelmonitor.HistoryTable,
  588. Columns: []string{channelmonitor.HistoryColumn},
  589. Bidi: false,
  590. Target: &sqlgraph.EdgeTarget{
  591. IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
  592. },
  593. }
  594. for _, k := range nodes {
  595. edge.Target.Nodes = append(edge.Target.Nodes, k)
  596. }
  597. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  598. }
  599. if nodes := _u.mutation.HistoryIDs(); len(nodes) > 0 {
  600. edge := &sqlgraph.EdgeSpec{
  601. Rel: sqlgraph.O2M,
  602. Inverse: false,
  603. Table: channelmonitor.HistoryTable,
  604. Columns: []string{channelmonitor.HistoryColumn},
  605. Bidi: false,
  606. Target: &sqlgraph.EdgeTarget{
  607. IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
  608. },
  609. }
  610. for _, k := range nodes {
  611. edge.Target.Nodes = append(edge.Target.Nodes, k)
  612. }
  613. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  614. }
  615. if _u.mutation.DailyRollupsCleared() {
  616. edge := &sqlgraph.EdgeSpec{
  617. Rel: sqlgraph.O2M,
  618. Inverse: false,
  619. Table: channelmonitor.DailyRollupsTable,
  620. Columns: []string{channelmonitor.DailyRollupsColumn},
  621. Bidi: false,
  622. Target: &sqlgraph.EdgeTarget{
  623. IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
  624. },
  625. }
  626. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  627. }
  628. if nodes := _u.mutation.RemovedDailyRollupsIDs(); len(nodes) > 0 && !_u.mutation.DailyRollupsCleared() {
  629. edge := &sqlgraph.EdgeSpec{
  630. Rel: sqlgraph.O2M,
  631. Inverse: false,
  632. Table: channelmonitor.DailyRollupsTable,
  633. Columns: []string{channelmonitor.DailyRollupsColumn},
  634. Bidi: false,
  635. Target: &sqlgraph.EdgeTarget{
  636. IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
  637. },
  638. }
  639. for _, k := range nodes {
  640. edge.Target.Nodes = append(edge.Target.Nodes, k)
  641. }
  642. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  643. }
  644. if nodes := _u.mutation.DailyRollupsIDs(); len(nodes) > 0 {
  645. edge := &sqlgraph.EdgeSpec{
  646. Rel: sqlgraph.O2M,
  647. Inverse: false,
  648. Table: channelmonitor.DailyRollupsTable,
  649. Columns: []string{channelmonitor.DailyRollupsColumn},
  650. Bidi: false,
  651. Target: &sqlgraph.EdgeTarget{
  652. IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
  653. },
  654. }
  655. for _, k := range nodes {
  656. edge.Target.Nodes = append(edge.Target.Nodes, k)
  657. }
  658. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  659. }
  660. if _u.mutation.RequestTemplateCleared() {
  661. edge := &sqlgraph.EdgeSpec{
  662. Rel: sqlgraph.M2O,
  663. Inverse: false,
  664. Table: channelmonitor.RequestTemplateTable,
  665. Columns: []string{channelmonitor.RequestTemplateColumn},
  666. Bidi: false,
  667. Target: &sqlgraph.EdgeTarget{
  668. IDSpec: sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64),
  669. },
  670. }
  671. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  672. }
  673. if nodes := _u.mutation.RequestTemplateIDs(); len(nodes) > 0 {
  674. edge := &sqlgraph.EdgeSpec{
  675. Rel: sqlgraph.M2O,
  676. Inverse: false,
  677. Table: channelmonitor.RequestTemplateTable,
  678. Columns: []string{channelmonitor.RequestTemplateColumn},
  679. Bidi: false,
  680. Target: &sqlgraph.EdgeTarget{
  681. IDSpec: sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64),
  682. },
  683. }
  684. for _, k := range nodes {
  685. edge.Target.Nodes = append(edge.Target.Nodes, k)
  686. }
  687. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  688. }
  689. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  690. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  691. err = &NotFoundError{channelmonitor.Label}
  692. } else if sqlgraph.IsConstraintError(err) {
  693. err = &ConstraintError{msg: err.Error(), wrap: err}
  694. }
  695. return 0, err
  696. }
  697. _u.mutation.done = true
  698. return _node, nil
  699. }
  700. // ChannelMonitorUpdateOne is the builder for updating a single ChannelMonitor entity.
  701. type ChannelMonitorUpdateOne struct {
  702. config
  703. fields []string
  704. hooks []Hook
  705. mutation *ChannelMonitorMutation
  706. }
  707. // SetUpdatedAt sets the "updated_at" field.
  708. func (_u *ChannelMonitorUpdateOne) SetUpdatedAt(v time.Time) *ChannelMonitorUpdateOne {
  709. _u.mutation.SetUpdatedAt(v)
  710. return _u
  711. }
  712. // SetName sets the "name" field.
  713. func (_u *ChannelMonitorUpdateOne) SetName(v string) *ChannelMonitorUpdateOne {
  714. _u.mutation.SetName(v)
  715. return _u
  716. }
  717. // SetNillableName sets the "name" field if the given value is not nil.
  718. func (_u *ChannelMonitorUpdateOne) SetNillableName(v *string) *ChannelMonitorUpdateOne {
  719. if v != nil {
  720. _u.SetName(*v)
  721. }
  722. return _u
  723. }
  724. // SetProvider sets the "provider" field.
  725. func (_u *ChannelMonitorUpdateOne) SetProvider(v channelmonitor.Provider) *ChannelMonitorUpdateOne {
  726. _u.mutation.SetProvider(v)
  727. return _u
  728. }
  729. // SetNillableProvider sets the "provider" field if the given value is not nil.
  730. func (_u *ChannelMonitorUpdateOne) SetNillableProvider(v *channelmonitor.Provider) *ChannelMonitorUpdateOne {
  731. if v != nil {
  732. _u.SetProvider(*v)
  733. }
  734. return _u
  735. }
  736. // SetCheckMode sets the "check_mode" field.
  737. func (_u *ChannelMonitorUpdateOne) SetCheckMode(v string) *ChannelMonitorUpdateOne {
  738. _u.mutation.SetCheckMode(v)
  739. return _u
  740. }
  741. // SetNillableCheckMode sets the "check_mode" field if the given value is not nil.
  742. func (_u *ChannelMonitorUpdateOne) SetNillableCheckMode(v *string) *ChannelMonitorUpdateOne {
  743. if v != nil {
  744. _u.SetCheckMode(*v)
  745. }
  746. return _u
  747. }
  748. // SetAccountID sets the "account_id" field.
  749. func (_u *ChannelMonitorUpdateOne) SetAccountID(v int64) *ChannelMonitorUpdateOne {
  750. _u.mutation.ResetAccountID()
  751. _u.mutation.SetAccountID(v)
  752. return _u
  753. }
  754. // SetNillableAccountID sets the "account_id" field if the given value is not nil.
  755. func (_u *ChannelMonitorUpdateOne) SetNillableAccountID(v *int64) *ChannelMonitorUpdateOne {
  756. if v != nil {
  757. _u.SetAccountID(*v)
  758. }
  759. return _u
  760. }
  761. // AddAccountID adds value to the "account_id" field.
  762. func (_u *ChannelMonitorUpdateOne) AddAccountID(v int64) *ChannelMonitorUpdateOne {
  763. _u.mutation.AddAccountID(v)
  764. return _u
  765. }
  766. // ClearAccountID clears the value of the "account_id" field.
  767. func (_u *ChannelMonitorUpdateOne) ClearAccountID() *ChannelMonitorUpdateOne {
  768. _u.mutation.ClearAccountID()
  769. return _u
  770. }
  771. // SetAPIMode sets the "api_mode" field.
  772. func (_u *ChannelMonitorUpdateOne) SetAPIMode(v string) *ChannelMonitorUpdateOne {
  773. _u.mutation.SetAPIMode(v)
  774. return _u
  775. }
  776. // SetNillableAPIMode sets the "api_mode" field if the given value is not nil.
  777. func (_u *ChannelMonitorUpdateOne) SetNillableAPIMode(v *string) *ChannelMonitorUpdateOne {
  778. if v != nil {
  779. _u.SetAPIMode(*v)
  780. }
  781. return _u
  782. }
  783. // SetEndpoint sets the "endpoint" field.
  784. func (_u *ChannelMonitorUpdateOne) SetEndpoint(v string) *ChannelMonitorUpdateOne {
  785. _u.mutation.SetEndpoint(v)
  786. return _u
  787. }
  788. // SetNillableEndpoint sets the "endpoint" field if the given value is not nil.
  789. func (_u *ChannelMonitorUpdateOne) SetNillableEndpoint(v *string) *ChannelMonitorUpdateOne {
  790. if v != nil {
  791. _u.SetEndpoint(*v)
  792. }
  793. return _u
  794. }
  795. // SetAPIKeyEncrypted sets the "api_key_encrypted" field.
  796. func (_u *ChannelMonitorUpdateOne) SetAPIKeyEncrypted(v string) *ChannelMonitorUpdateOne {
  797. _u.mutation.SetAPIKeyEncrypted(v)
  798. return _u
  799. }
  800. // SetNillableAPIKeyEncrypted sets the "api_key_encrypted" field if the given value is not nil.
  801. func (_u *ChannelMonitorUpdateOne) SetNillableAPIKeyEncrypted(v *string) *ChannelMonitorUpdateOne {
  802. if v != nil {
  803. _u.SetAPIKeyEncrypted(*v)
  804. }
  805. return _u
  806. }
  807. // SetPrimaryModel sets the "primary_model" field.
  808. func (_u *ChannelMonitorUpdateOne) SetPrimaryModel(v string) *ChannelMonitorUpdateOne {
  809. _u.mutation.SetPrimaryModel(v)
  810. return _u
  811. }
  812. // SetNillablePrimaryModel sets the "primary_model" field if the given value is not nil.
  813. func (_u *ChannelMonitorUpdateOne) SetNillablePrimaryModel(v *string) *ChannelMonitorUpdateOne {
  814. if v != nil {
  815. _u.SetPrimaryModel(*v)
  816. }
  817. return _u
  818. }
  819. // SetExtraModels sets the "extra_models" field.
  820. func (_u *ChannelMonitorUpdateOne) SetExtraModels(v []string) *ChannelMonitorUpdateOne {
  821. _u.mutation.SetExtraModels(v)
  822. return _u
  823. }
  824. // AppendExtraModels appends value to the "extra_models" field.
  825. func (_u *ChannelMonitorUpdateOne) AppendExtraModels(v []string) *ChannelMonitorUpdateOne {
  826. _u.mutation.AppendExtraModels(v)
  827. return _u
  828. }
  829. // SetGroupName sets the "group_name" field.
  830. func (_u *ChannelMonitorUpdateOne) SetGroupName(v string) *ChannelMonitorUpdateOne {
  831. _u.mutation.SetGroupName(v)
  832. return _u
  833. }
  834. // SetNillableGroupName sets the "group_name" field if the given value is not nil.
  835. func (_u *ChannelMonitorUpdateOne) SetNillableGroupName(v *string) *ChannelMonitorUpdateOne {
  836. if v != nil {
  837. _u.SetGroupName(*v)
  838. }
  839. return _u
  840. }
  841. // ClearGroupName clears the value of the "group_name" field.
  842. func (_u *ChannelMonitorUpdateOne) ClearGroupName() *ChannelMonitorUpdateOne {
  843. _u.mutation.ClearGroupName()
  844. return _u
  845. }
  846. // SetEnabled sets the "enabled" field.
  847. func (_u *ChannelMonitorUpdateOne) SetEnabled(v bool) *ChannelMonitorUpdateOne {
  848. _u.mutation.SetEnabled(v)
  849. return _u
  850. }
  851. // SetNillableEnabled sets the "enabled" field if the given value is not nil.
  852. func (_u *ChannelMonitorUpdateOne) SetNillableEnabled(v *bool) *ChannelMonitorUpdateOne {
  853. if v != nil {
  854. _u.SetEnabled(*v)
  855. }
  856. return _u
  857. }
  858. // SetIntervalSeconds sets the "interval_seconds" field.
  859. func (_u *ChannelMonitorUpdateOne) SetIntervalSeconds(v int) *ChannelMonitorUpdateOne {
  860. _u.mutation.ResetIntervalSeconds()
  861. _u.mutation.SetIntervalSeconds(v)
  862. return _u
  863. }
  864. // SetNillableIntervalSeconds sets the "interval_seconds" field if the given value is not nil.
  865. func (_u *ChannelMonitorUpdateOne) SetNillableIntervalSeconds(v *int) *ChannelMonitorUpdateOne {
  866. if v != nil {
  867. _u.SetIntervalSeconds(*v)
  868. }
  869. return _u
  870. }
  871. // AddIntervalSeconds adds value to the "interval_seconds" field.
  872. func (_u *ChannelMonitorUpdateOne) AddIntervalSeconds(v int) *ChannelMonitorUpdateOne {
  873. _u.mutation.AddIntervalSeconds(v)
  874. return _u
  875. }
  876. // SetJitterSeconds sets the "jitter_seconds" field.
  877. func (_u *ChannelMonitorUpdateOne) SetJitterSeconds(v int) *ChannelMonitorUpdateOne {
  878. _u.mutation.ResetJitterSeconds()
  879. _u.mutation.SetJitterSeconds(v)
  880. return _u
  881. }
  882. // SetNillableJitterSeconds sets the "jitter_seconds" field if the given value is not nil.
  883. func (_u *ChannelMonitorUpdateOne) SetNillableJitterSeconds(v *int) *ChannelMonitorUpdateOne {
  884. if v != nil {
  885. _u.SetJitterSeconds(*v)
  886. }
  887. return _u
  888. }
  889. // AddJitterSeconds adds value to the "jitter_seconds" field.
  890. func (_u *ChannelMonitorUpdateOne) AddJitterSeconds(v int) *ChannelMonitorUpdateOne {
  891. _u.mutation.AddJitterSeconds(v)
  892. return _u
  893. }
  894. // SetLastCheckedAt sets the "last_checked_at" field.
  895. func (_u *ChannelMonitorUpdateOne) SetLastCheckedAt(v time.Time) *ChannelMonitorUpdateOne {
  896. _u.mutation.SetLastCheckedAt(v)
  897. return _u
  898. }
  899. // SetNillableLastCheckedAt sets the "last_checked_at" field if the given value is not nil.
  900. func (_u *ChannelMonitorUpdateOne) SetNillableLastCheckedAt(v *time.Time) *ChannelMonitorUpdateOne {
  901. if v != nil {
  902. _u.SetLastCheckedAt(*v)
  903. }
  904. return _u
  905. }
  906. // ClearLastCheckedAt clears the value of the "last_checked_at" field.
  907. func (_u *ChannelMonitorUpdateOne) ClearLastCheckedAt() *ChannelMonitorUpdateOne {
  908. _u.mutation.ClearLastCheckedAt()
  909. return _u
  910. }
  911. // SetCreatedBy sets the "created_by" field.
  912. func (_u *ChannelMonitorUpdateOne) SetCreatedBy(v int64) *ChannelMonitorUpdateOne {
  913. _u.mutation.ResetCreatedBy()
  914. _u.mutation.SetCreatedBy(v)
  915. return _u
  916. }
  917. // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
  918. func (_u *ChannelMonitorUpdateOne) SetNillableCreatedBy(v *int64) *ChannelMonitorUpdateOne {
  919. if v != nil {
  920. _u.SetCreatedBy(*v)
  921. }
  922. return _u
  923. }
  924. // AddCreatedBy adds value to the "created_by" field.
  925. func (_u *ChannelMonitorUpdateOne) AddCreatedBy(v int64) *ChannelMonitorUpdateOne {
  926. _u.mutation.AddCreatedBy(v)
  927. return _u
  928. }
  929. // SetTemplateID sets the "template_id" field.
  930. func (_u *ChannelMonitorUpdateOne) SetTemplateID(v int64) *ChannelMonitorUpdateOne {
  931. _u.mutation.SetTemplateID(v)
  932. return _u
  933. }
  934. // SetNillableTemplateID sets the "template_id" field if the given value is not nil.
  935. func (_u *ChannelMonitorUpdateOne) SetNillableTemplateID(v *int64) *ChannelMonitorUpdateOne {
  936. if v != nil {
  937. _u.SetTemplateID(*v)
  938. }
  939. return _u
  940. }
  941. // ClearTemplateID clears the value of the "template_id" field.
  942. func (_u *ChannelMonitorUpdateOne) ClearTemplateID() *ChannelMonitorUpdateOne {
  943. _u.mutation.ClearTemplateID()
  944. return _u
  945. }
  946. // SetExtraHeaders sets the "extra_headers" field.
  947. func (_u *ChannelMonitorUpdateOne) SetExtraHeaders(v map[string]string) *ChannelMonitorUpdateOne {
  948. _u.mutation.SetExtraHeaders(v)
  949. return _u
  950. }
  951. // SetBodyOverrideMode sets the "body_override_mode" field.
  952. func (_u *ChannelMonitorUpdateOne) SetBodyOverrideMode(v string) *ChannelMonitorUpdateOne {
  953. _u.mutation.SetBodyOverrideMode(v)
  954. return _u
  955. }
  956. // SetNillableBodyOverrideMode sets the "body_override_mode" field if the given value is not nil.
  957. func (_u *ChannelMonitorUpdateOne) SetNillableBodyOverrideMode(v *string) *ChannelMonitorUpdateOne {
  958. if v != nil {
  959. _u.SetBodyOverrideMode(*v)
  960. }
  961. return _u
  962. }
  963. // SetBodyOverride sets the "body_override" field.
  964. func (_u *ChannelMonitorUpdateOne) SetBodyOverride(v map[string]interface{}) *ChannelMonitorUpdateOne {
  965. _u.mutation.SetBodyOverride(v)
  966. return _u
  967. }
  968. // ClearBodyOverride clears the value of the "body_override" field.
  969. func (_u *ChannelMonitorUpdateOne) ClearBodyOverride() *ChannelMonitorUpdateOne {
  970. _u.mutation.ClearBodyOverride()
  971. return _u
  972. }
  973. // AddHistoryIDs adds the "history" edge to the ChannelMonitorHistory entity by IDs.
  974. func (_u *ChannelMonitorUpdateOne) AddHistoryIDs(ids ...int64) *ChannelMonitorUpdateOne {
  975. _u.mutation.AddHistoryIDs(ids...)
  976. return _u
  977. }
  978. // AddHistory adds the "history" edges to the ChannelMonitorHistory entity.
  979. func (_u *ChannelMonitorUpdateOne) AddHistory(v ...*ChannelMonitorHistory) *ChannelMonitorUpdateOne {
  980. ids := make([]int64, len(v))
  981. for i := range v {
  982. ids[i] = v[i].ID
  983. }
  984. return _u.AddHistoryIDs(ids...)
  985. }
  986. // AddDailyRollupIDs adds the "daily_rollups" edge to the ChannelMonitorDailyRollup entity by IDs.
  987. func (_u *ChannelMonitorUpdateOne) AddDailyRollupIDs(ids ...int64) *ChannelMonitorUpdateOne {
  988. _u.mutation.AddDailyRollupIDs(ids...)
  989. return _u
  990. }
  991. // AddDailyRollups adds the "daily_rollups" edges to the ChannelMonitorDailyRollup entity.
  992. func (_u *ChannelMonitorUpdateOne) AddDailyRollups(v ...*ChannelMonitorDailyRollup) *ChannelMonitorUpdateOne {
  993. ids := make([]int64, len(v))
  994. for i := range v {
  995. ids[i] = v[i].ID
  996. }
  997. return _u.AddDailyRollupIDs(ids...)
  998. }
  999. // SetRequestTemplateID sets the "request_template" edge to the ChannelMonitorRequestTemplate entity by ID.
  1000. func (_u *ChannelMonitorUpdateOne) SetRequestTemplateID(id int64) *ChannelMonitorUpdateOne {
  1001. _u.mutation.SetRequestTemplateID(id)
  1002. return _u
  1003. }
  1004. // SetNillableRequestTemplateID sets the "request_template" edge to the ChannelMonitorRequestTemplate entity by ID if the given value is not nil.
  1005. func (_u *ChannelMonitorUpdateOne) SetNillableRequestTemplateID(id *int64) *ChannelMonitorUpdateOne {
  1006. if id != nil {
  1007. _u = _u.SetRequestTemplateID(*id)
  1008. }
  1009. return _u
  1010. }
  1011. // SetRequestTemplate sets the "request_template" edge to the ChannelMonitorRequestTemplate entity.
  1012. func (_u *ChannelMonitorUpdateOne) SetRequestTemplate(v *ChannelMonitorRequestTemplate) *ChannelMonitorUpdateOne {
  1013. return _u.SetRequestTemplateID(v.ID)
  1014. }
  1015. // Mutation returns the ChannelMonitorMutation object of the builder.
  1016. func (_u *ChannelMonitorUpdateOne) Mutation() *ChannelMonitorMutation {
  1017. return _u.mutation
  1018. }
  1019. // ClearHistory clears all "history" edges to the ChannelMonitorHistory entity.
  1020. func (_u *ChannelMonitorUpdateOne) ClearHistory() *ChannelMonitorUpdateOne {
  1021. _u.mutation.ClearHistory()
  1022. return _u
  1023. }
  1024. // RemoveHistoryIDs removes the "history" edge to ChannelMonitorHistory entities by IDs.
  1025. func (_u *ChannelMonitorUpdateOne) RemoveHistoryIDs(ids ...int64) *ChannelMonitorUpdateOne {
  1026. _u.mutation.RemoveHistoryIDs(ids...)
  1027. return _u
  1028. }
  1029. // RemoveHistory removes "history" edges to ChannelMonitorHistory entities.
  1030. func (_u *ChannelMonitorUpdateOne) RemoveHistory(v ...*ChannelMonitorHistory) *ChannelMonitorUpdateOne {
  1031. ids := make([]int64, len(v))
  1032. for i := range v {
  1033. ids[i] = v[i].ID
  1034. }
  1035. return _u.RemoveHistoryIDs(ids...)
  1036. }
  1037. // ClearDailyRollups clears all "daily_rollups" edges to the ChannelMonitorDailyRollup entity.
  1038. func (_u *ChannelMonitorUpdateOne) ClearDailyRollups() *ChannelMonitorUpdateOne {
  1039. _u.mutation.ClearDailyRollups()
  1040. return _u
  1041. }
  1042. // RemoveDailyRollupIDs removes the "daily_rollups" edge to ChannelMonitorDailyRollup entities by IDs.
  1043. func (_u *ChannelMonitorUpdateOne) RemoveDailyRollupIDs(ids ...int64) *ChannelMonitorUpdateOne {
  1044. _u.mutation.RemoveDailyRollupIDs(ids...)
  1045. return _u
  1046. }
  1047. // RemoveDailyRollups removes "daily_rollups" edges to ChannelMonitorDailyRollup entities.
  1048. func (_u *ChannelMonitorUpdateOne) RemoveDailyRollups(v ...*ChannelMonitorDailyRollup) *ChannelMonitorUpdateOne {
  1049. ids := make([]int64, len(v))
  1050. for i := range v {
  1051. ids[i] = v[i].ID
  1052. }
  1053. return _u.RemoveDailyRollupIDs(ids...)
  1054. }
  1055. // ClearRequestTemplate clears the "request_template" edge to the ChannelMonitorRequestTemplate entity.
  1056. func (_u *ChannelMonitorUpdateOne) ClearRequestTemplate() *ChannelMonitorUpdateOne {
  1057. _u.mutation.ClearRequestTemplate()
  1058. return _u
  1059. }
  1060. // Where appends a list predicates to the ChannelMonitorUpdate builder.
  1061. func (_u *ChannelMonitorUpdateOne) Where(ps ...predicate.ChannelMonitor) *ChannelMonitorUpdateOne {
  1062. _u.mutation.Where(ps...)
  1063. return _u
  1064. }
  1065. // Select allows selecting one or more fields (columns) of the returned entity.
  1066. // The default is selecting all fields defined in the entity schema.
  1067. func (_u *ChannelMonitorUpdateOne) Select(field string, fields ...string) *ChannelMonitorUpdateOne {
  1068. _u.fields = append([]string{field}, fields...)
  1069. return _u
  1070. }
  1071. // Save executes the query and returns the updated ChannelMonitor entity.
  1072. func (_u *ChannelMonitorUpdateOne) Save(ctx context.Context) (*ChannelMonitor, error) {
  1073. _u.defaults()
  1074. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  1075. }
  1076. // SaveX is like Save, but panics if an error occurs.
  1077. func (_u *ChannelMonitorUpdateOne) SaveX(ctx context.Context) *ChannelMonitor {
  1078. node, err := _u.Save(ctx)
  1079. if err != nil {
  1080. panic(err)
  1081. }
  1082. return node
  1083. }
  1084. // Exec executes the query on the entity.
  1085. func (_u *ChannelMonitorUpdateOne) Exec(ctx context.Context) error {
  1086. _, err := _u.Save(ctx)
  1087. return err
  1088. }
  1089. // ExecX is like Exec, but panics if an error occurs.
  1090. func (_u *ChannelMonitorUpdateOne) ExecX(ctx context.Context) {
  1091. if err := _u.Exec(ctx); err != nil {
  1092. panic(err)
  1093. }
  1094. }
  1095. // defaults sets the default values of the builder before save.
  1096. func (_u *ChannelMonitorUpdateOne) defaults() {
  1097. if _, ok := _u.mutation.UpdatedAt(); !ok {
  1098. v := channelmonitor.UpdateDefaultUpdatedAt()
  1099. _u.mutation.SetUpdatedAt(v)
  1100. }
  1101. }
  1102. // check runs all checks and user-defined validators on the builder.
  1103. func (_u *ChannelMonitorUpdateOne) check() error {
  1104. if v, ok := _u.mutation.Name(); ok {
  1105. if err := channelmonitor.NameValidator(v); err != nil {
  1106. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.name": %w`, err)}
  1107. }
  1108. }
  1109. if v, ok := _u.mutation.Provider(); ok {
  1110. if err := channelmonitor.ProviderValidator(v); err != nil {
  1111. return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.provider": %w`, err)}
  1112. }
  1113. }
  1114. if v, ok := _u.mutation.CheckMode(); ok {
  1115. if err := channelmonitor.CheckModeValidator(v); err != nil {
  1116. return &ValidationError{Name: "check_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.check_mode": %w`, err)}
  1117. }
  1118. }
  1119. if v, ok := _u.mutation.APIMode(); ok {
  1120. if err := channelmonitor.APIModeValidator(v); err != nil {
  1121. return &ValidationError{Name: "api_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_mode": %w`, err)}
  1122. }
  1123. }
  1124. if v, ok := _u.mutation.Endpoint(); ok {
  1125. if err := channelmonitor.EndpointValidator(v); err != nil {
  1126. return &ValidationError{Name: "endpoint", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.endpoint": %w`, err)}
  1127. }
  1128. }
  1129. if v, ok := _u.mutation.APIKeyEncrypted(); ok {
  1130. if err := channelmonitor.APIKeyEncryptedValidator(v); err != nil {
  1131. return &ValidationError{Name: "api_key_encrypted", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.api_key_encrypted": %w`, err)}
  1132. }
  1133. }
  1134. if v, ok := _u.mutation.PrimaryModel(); ok {
  1135. if err := channelmonitor.PrimaryModelValidator(v); err != nil {
  1136. return &ValidationError{Name: "primary_model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.primary_model": %w`, err)}
  1137. }
  1138. }
  1139. if v, ok := _u.mutation.GroupName(); ok {
  1140. if err := channelmonitor.GroupNameValidator(v); err != nil {
  1141. return &ValidationError{Name: "group_name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.group_name": %w`, err)}
  1142. }
  1143. }
  1144. if v, ok := _u.mutation.IntervalSeconds(); ok {
  1145. if err := channelmonitor.IntervalSecondsValidator(v); err != nil {
  1146. return &ValidationError{Name: "interval_seconds", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.interval_seconds": %w`, err)}
  1147. }
  1148. }
  1149. if v, ok := _u.mutation.JitterSeconds(); ok {
  1150. if err := channelmonitor.JitterSecondsValidator(v); err != nil {
  1151. return &ValidationError{Name: "jitter_seconds", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.jitter_seconds": %w`, err)}
  1152. }
  1153. }
  1154. if v, ok := _u.mutation.BodyOverrideMode(); ok {
  1155. if err := channelmonitor.BodyOverrideModeValidator(v); err != nil {
  1156. return &ValidationError{Name: "body_override_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitor.body_override_mode": %w`, err)}
  1157. }
  1158. }
  1159. return nil
  1160. }
  1161. func (_u *ChannelMonitorUpdateOne) sqlSave(ctx context.Context) (_node *ChannelMonitor, err error) {
  1162. if err := _u.check(); err != nil {
  1163. return _node, err
  1164. }
  1165. _spec := sqlgraph.NewUpdateSpec(channelmonitor.Table, channelmonitor.Columns, sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64))
  1166. id, ok := _u.mutation.ID()
  1167. if !ok {
  1168. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChannelMonitor.id" for update`)}
  1169. }
  1170. _spec.Node.ID.Value = id
  1171. if fields := _u.fields; len(fields) > 0 {
  1172. _spec.Node.Columns = make([]string, 0, len(fields))
  1173. _spec.Node.Columns = append(_spec.Node.Columns, channelmonitor.FieldID)
  1174. for _, f := range fields {
  1175. if !channelmonitor.ValidColumn(f) {
  1176. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1177. }
  1178. if f != channelmonitor.FieldID {
  1179. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1180. }
  1181. }
  1182. }
  1183. if ps := _u.mutation.predicates; len(ps) > 0 {
  1184. _spec.Predicate = func(selector *sql.Selector) {
  1185. for i := range ps {
  1186. ps[i](selector)
  1187. }
  1188. }
  1189. }
  1190. if value, ok := _u.mutation.UpdatedAt(); ok {
  1191. _spec.SetField(channelmonitor.FieldUpdatedAt, field.TypeTime, value)
  1192. }
  1193. if value, ok := _u.mutation.Name(); ok {
  1194. _spec.SetField(channelmonitor.FieldName, field.TypeString, value)
  1195. }
  1196. if value, ok := _u.mutation.Provider(); ok {
  1197. _spec.SetField(channelmonitor.FieldProvider, field.TypeEnum, value)
  1198. }
  1199. if value, ok := _u.mutation.CheckMode(); ok {
  1200. _spec.SetField(channelmonitor.FieldCheckMode, field.TypeString, value)
  1201. }
  1202. if value, ok := _u.mutation.AccountID(); ok {
  1203. _spec.SetField(channelmonitor.FieldAccountID, field.TypeInt64, value)
  1204. }
  1205. if value, ok := _u.mutation.AddedAccountID(); ok {
  1206. _spec.AddField(channelmonitor.FieldAccountID, field.TypeInt64, value)
  1207. }
  1208. if _u.mutation.AccountIDCleared() {
  1209. _spec.ClearField(channelmonitor.FieldAccountID, field.TypeInt64)
  1210. }
  1211. if value, ok := _u.mutation.APIMode(); ok {
  1212. _spec.SetField(channelmonitor.FieldAPIMode, field.TypeString, value)
  1213. }
  1214. if value, ok := _u.mutation.Endpoint(); ok {
  1215. _spec.SetField(channelmonitor.FieldEndpoint, field.TypeString, value)
  1216. }
  1217. if value, ok := _u.mutation.APIKeyEncrypted(); ok {
  1218. _spec.SetField(channelmonitor.FieldAPIKeyEncrypted, field.TypeString, value)
  1219. }
  1220. if value, ok := _u.mutation.PrimaryModel(); ok {
  1221. _spec.SetField(channelmonitor.FieldPrimaryModel, field.TypeString, value)
  1222. }
  1223. if value, ok := _u.mutation.ExtraModels(); ok {
  1224. _spec.SetField(channelmonitor.FieldExtraModels, field.TypeJSON, value)
  1225. }
  1226. if value, ok := _u.mutation.AppendedExtraModels(); ok {
  1227. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  1228. sqljson.Append(u, channelmonitor.FieldExtraModels, value)
  1229. })
  1230. }
  1231. if value, ok := _u.mutation.GroupName(); ok {
  1232. _spec.SetField(channelmonitor.FieldGroupName, field.TypeString, value)
  1233. }
  1234. if _u.mutation.GroupNameCleared() {
  1235. _spec.ClearField(channelmonitor.FieldGroupName, field.TypeString)
  1236. }
  1237. if value, ok := _u.mutation.Enabled(); ok {
  1238. _spec.SetField(channelmonitor.FieldEnabled, field.TypeBool, value)
  1239. }
  1240. if value, ok := _u.mutation.IntervalSeconds(); ok {
  1241. _spec.SetField(channelmonitor.FieldIntervalSeconds, field.TypeInt, value)
  1242. }
  1243. if value, ok := _u.mutation.AddedIntervalSeconds(); ok {
  1244. _spec.AddField(channelmonitor.FieldIntervalSeconds, field.TypeInt, value)
  1245. }
  1246. if value, ok := _u.mutation.JitterSeconds(); ok {
  1247. _spec.SetField(channelmonitor.FieldJitterSeconds, field.TypeInt, value)
  1248. }
  1249. if value, ok := _u.mutation.AddedJitterSeconds(); ok {
  1250. _spec.AddField(channelmonitor.FieldJitterSeconds, field.TypeInt, value)
  1251. }
  1252. if value, ok := _u.mutation.LastCheckedAt(); ok {
  1253. _spec.SetField(channelmonitor.FieldLastCheckedAt, field.TypeTime, value)
  1254. }
  1255. if _u.mutation.LastCheckedAtCleared() {
  1256. _spec.ClearField(channelmonitor.FieldLastCheckedAt, field.TypeTime)
  1257. }
  1258. if value, ok := _u.mutation.CreatedBy(); ok {
  1259. _spec.SetField(channelmonitor.FieldCreatedBy, field.TypeInt64, value)
  1260. }
  1261. if value, ok := _u.mutation.AddedCreatedBy(); ok {
  1262. _spec.AddField(channelmonitor.FieldCreatedBy, field.TypeInt64, value)
  1263. }
  1264. if value, ok := _u.mutation.ExtraHeaders(); ok {
  1265. _spec.SetField(channelmonitor.FieldExtraHeaders, field.TypeJSON, value)
  1266. }
  1267. if value, ok := _u.mutation.BodyOverrideMode(); ok {
  1268. _spec.SetField(channelmonitor.FieldBodyOverrideMode, field.TypeString, value)
  1269. }
  1270. if value, ok := _u.mutation.BodyOverride(); ok {
  1271. _spec.SetField(channelmonitor.FieldBodyOverride, field.TypeJSON, value)
  1272. }
  1273. if _u.mutation.BodyOverrideCleared() {
  1274. _spec.ClearField(channelmonitor.FieldBodyOverride, field.TypeJSON)
  1275. }
  1276. if _u.mutation.HistoryCleared() {
  1277. edge := &sqlgraph.EdgeSpec{
  1278. Rel: sqlgraph.O2M,
  1279. Inverse: false,
  1280. Table: channelmonitor.HistoryTable,
  1281. Columns: []string{channelmonitor.HistoryColumn},
  1282. Bidi: false,
  1283. Target: &sqlgraph.EdgeTarget{
  1284. IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
  1285. },
  1286. }
  1287. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1288. }
  1289. if nodes := _u.mutation.RemovedHistoryIDs(); len(nodes) > 0 && !_u.mutation.HistoryCleared() {
  1290. edge := &sqlgraph.EdgeSpec{
  1291. Rel: sqlgraph.O2M,
  1292. Inverse: false,
  1293. Table: channelmonitor.HistoryTable,
  1294. Columns: []string{channelmonitor.HistoryColumn},
  1295. Bidi: false,
  1296. Target: &sqlgraph.EdgeTarget{
  1297. IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
  1298. },
  1299. }
  1300. for _, k := range nodes {
  1301. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1302. }
  1303. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1304. }
  1305. if nodes := _u.mutation.HistoryIDs(); len(nodes) > 0 {
  1306. edge := &sqlgraph.EdgeSpec{
  1307. Rel: sqlgraph.O2M,
  1308. Inverse: false,
  1309. Table: channelmonitor.HistoryTable,
  1310. Columns: []string{channelmonitor.HistoryColumn},
  1311. Bidi: false,
  1312. Target: &sqlgraph.EdgeTarget{
  1313. IDSpec: sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64),
  1314. },
  1315. }
  1316. for _, k := range nodes {
  1317. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1318. }
  1319. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1320. }
  1321. if _u.mutation.DailyRollupsCleared() {
  1322. edge := &sqlgraph.EdgeSpec{
  1323. Rel: sqlgraph.O2M,
  1324. Inverse: false,
  1325. Table: channelmonitor.DailyRollupsTable,
  1326. Columns: []string{channelmonitor.DailyRollupsColumn},
  1327. Bidi: false,
  1328. Target: &sqlgraph.EdgeTarget{
  1329. IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
  1330. },
  1331. }
  1332. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1333. }
  1334. if nodes := _u.mutation.RemovedDailyRollupsIDs(); len(nodes) > 0 && !_u.mutation.DailyRollupsCleared() {
  1335. edge := &sqlgraph.EdgeSpec{
  1336. Rel: sqlgraph.O2M,
  1337. Inverse: false,
  1338. Table: channelmonitor.DailyRollupsTable,
  1339. Columns: []string{channelmonitor.DailyRollupsColumn},
  1340. Bidi: false,
  1341. Target: &sqlgraph.EdgeTarget{
  1342. IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
  1343. },
  1344. }
  1345. for _, k := range nodes {
  1346. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1347. }
  1348. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1349. }
  1350. if nodes := _u.mutation.DailyRollupsIDs(); len(nodes) > 0 {
  1351. edge := &sqlgraph.EdgeSpec{
  1352. Rel: sqlgraph.O2M,
  1353. Inverse: false,
  1354. Table: channelmonitor.DailyRollupsTable,
  1355. Columns: []string{channelmonitor.DailyRollupsColumn},
  1356. Bidi: false,
  1357. Target: &sqlgraph.EdgeTarget{
  1358. IDSpec: sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64),
  1359. },
  1360. }
  1361. for _, k := range nodes {
  1362. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1363. }
  1364. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1365. }
  1366. if _u.mutation.RequestTemplateCleared() {
  1367. edge := &sqlgraph.EdgeSpec{
  1368. Rel: sqlgraph.M2O,
  1369. Inverse: false,
  1370. Table: channelmonitor.RequestTemplateTable,
  1371. Columns: []string{channelmonitor.RequestTemplateColumn},
  1372. Bidi: false,
  1373. Target: &sqlgraph.EdgeTarget{
  1374. IDSpec: sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64),
  1375. },
  1376. }
  1377. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1378. }
  1379. if nodes := _u.mutation.RequestTemplateIDs(); len(nodes) > 0 {
  1380. edge := &sqlgraph.EdgeSpec{
  1381. Rel: sqlgraph.M2O,
  1382. Inverse: false,
  1383. Table: channelmonitor.RequestTemplateTable,
  1384. Columns: []string{channelmonitor.RequestTemplateColumn},
  1385. Bidi: false,
  1386. Target: &sqlgraph.EdgeTarget{
  1387. IDSpec: sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64),
  1388. },
  1389. }
  1390. for _, k := range nodes {
  1391. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1392. }
  1393. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1394. }
  1395. _node = &ChannelMonitor{config: _u.config}
  1396. _spec.Assign = _node.assignValues
  1397. _spec.ScanValues = _node.scanValues
  1398. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  1399. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1400. err = &NotFoundError{channelmonitor.Label}
  1401. } else if sqlgraph.IsConstraintError(err) {
  1402. err = &ConstraintError{msg: err.Error(), wrap: err}
  1403. }
  1404. return nil, err
  1405. }
  1406. _u.mutation.done = true
  1407. return _node, nil
  1408. }