channelmonitorhistory_update.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/channelmonitor"
  12. "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory"
  13. "github.com/Wei-Shaw/sub2api/ent/predicate"
  14. "github.com/Wei-Shaw/sub2api/internal/domain"
  15. )
  16. // ChannelMonitorHistoryUpdate is the builder for updating ChannelMonitorHistory entities.
  17. type ChannelMonitorHistoryUpdate struct {
  18. config
  19. hooks []Hook
  20. mutation *ChannelMonitorHistoryMutation
  21. }
  22. // Where appends a list predicates to the ChannelMonitorHistoryUpdate builder.
  23. func (_u *ChannelMonitorHistoryUpdate) Where(ps ...predicate.ChannelMonitorHistory) *ChannelMonitorHistoryUpdate {
  24. _u.mutation.Where(ps...)
  25. return _u
  26. }
  27. // SetMonitorID sets the "monitor_id" field.
  28. func (_u *ChannelMonitorHistoryUpdate) SetMonitorID(v int64) *ChannelMonitorHistoryUpdate {
  29. _u.mutation.SetMonitorID(v)
  30. return _u
  31. }
  32. // SetNillableMonitorID sets the "monitor_id" field if the given value is not nil.
  33. func (_u *ChannelMonitorHistoryUpdate) SetNillableMonitorID(v *int64) *ChannelMonitorHistoryUpdate {
  34. if v != nil {
  35. _u.SetMonitorID(*v)
  36. }
  37. return _u
  38. }
  39. // SetModel sets the "model" field.
  40. func (_u *ChannelMonitorHistoryUpdate) SetModel(v string) *ChannelMonitorHistoryUpdate {
  41. _u.mutation.SetModel(v)
  42. return _u
  43. }
  44. // SetNillableModel sets the "model" field if the given value is not nil.
  45. func (_u *ChannelMonitorHistoryUpdate) SetNillableModel(v *string) *ChannelMonitorHistoryUpdate {
  46. if v != nil {
  47. _u.SetModel(*v)
  48. }
  49. return _u
  50. }
  51. // SetStatus sets the "status" field.
  52. func (_u *ChannelMonitorHistoryUpdate) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpdate {
  53. _u.mutation.SetStatus(v)
  54. return _u
  55. }
  56. // SetNillableStatus sets the "status" field if the given value is not nil.
  57. func (_u *ChannelMonitorHistoryUpdate) SetNillableStatus(v *channelmonitorhistory.Status) *ChannelMonitorHistoryUpdate {
  58. if v != nil {
  59. _u.SetStatus(*v)
  60. }
  61. return _u
  62. }
  63. // SetLatencyMs sets the "latency_ms" field.
  64. func (_u *ChannelMonitorHistoryUpdate) SetLatencyMs(v int) *ChannelMonitorHistoryUpdate {
  65. _u.mutation.ResetLatencyMs()
  66. _u.mutation.SetLatencyMs(v)
  67. return _u
  68. }
  69. // SetNillableLatencyMs sets the "latency_ms" field if the given value is not nil.
  70. func (_u *ChannelMonitorHistoryUpdate) SetNillableLatencyMs(v *int) *ChannelMonitorHistoryUpdate {
  71. if v != nil {
  72. _u.SetLatencyMs(*v)
  73. }
  74. return _u
  75. }
  76. // AddLatencyMs adds value to the "latency_ms" field.
  77. func (_u *ChannelMonitorHistoryUpdate) AddLatencyMs(v int) *ChannelMonitorHistoryUpdate {
  78. _u.mutation.AddLatencyMs(v)
  79. return _u
  80. }
  81. // ClearLatencyMs clears the value of the "latency_ms" field.
  82. func (_u *ChannelMonitorHistoryUpdate) ClearLatencyMs() *ChannelMonitorHistoryUpdate {
  83. _u.mutation.ClearLatencyMs()
  84. return _u
  85. }
  86. // SetPingLatencyMs sets the "ping_latency_ms" field.
  87. func (_u *ChannelMonitorHistoryUpdate) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpdate {
  88. _u.mutation.ResetPingLatencyMs()
  89. _u.mutation.SetPingLatencyMs(v)
  90. return _u
  91. }
  92. // SetNillablePingLatencyMs sets the "ping_latency_ms" field if the given value is not nil.
  93. func (_u *ChannelMonitorHistoryUpdate) SetNillablePingLatencyMs(v *int) *ChannelMonitorHistoryUpdate {
  94. if v != nil {
  95. _u.SetPingLatencyMs(*v)
  96. }
  97. return _u
  98. }
  99. // AddPingLatencyMs adds value to the "ping_latency_ms" field.
  100. func (_u *ChannelMonitorHistoryUpdate) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpdate {
  101. _u.mutation.AddPingLatencyMs(v)
  102. return _u
  103. }
  104. // ClearPingLatencyMs clears the value of the "ping_latency_ms" field.
  105. func (_u *ChannelMonitorHistoryUpdate) ClearPingLatencyMs() *ChannelMonitorHistoryUpdate {
  106. _u.mutation.ClearPingLatencyMs()
  107. return _u
  108. }
  109. // SetMessage sets the "message" field.
  110. func (_u *ChannelMonitorHistoryUpdate) SetMessage(v string) *ChannelMonitorHistoryUpdate {
  111. _u.mutation.SetMessage(v)
  112. return _u
  113. }
  114. // SetNillableMessage sets the "message" field if the given value is not nil.
  115. func (_u *ChannelMonitorHistoryUpdate) SetNillableMessage(v *string) *ChannelMonitorHistoryUpdate {
  116. if v != nil {
  117. _u.SetMessage(*v)
  118. }
  119. return _u
  120. }
  121. // ClearMessage clears the value of the "message" field.
  122. func (_u *ChannelMonitorHistoryUpdate) ClearMessage() *ChannelMonitorHistoryUpdate {
  123. _u.mutation.ClearMessage()
  124. return _u
  125. }
  126. // SetQuota sets the "quota" field.
  127. func (_u *ChannelMonitorHistoryUpdate) SetQuota(v *domain.MonitorQuotaSnapshot) *ChannelMonitorHistoryUpdate {
  128. _u.mutation.SetQuota(v)
  129. return _u
  130. }
  131. // ClearQuota clears the value of the "quota" field.
  132. func (_u *ChannelMonitorHistoryUpdate) ClearQuota() *ChannelMonitorHistoryUpdate {
  133. _u.mutation.ClearQuota()
  134. return _u
  135. }
  136. // SetCheckedAt sets the "checked_at" field.
  137. func (_u *ChannelMonitorHistoryUpdate) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpdate {
  138. _u.mutation.SetCheckedAt(v)
  139. return _u
  140. }
  141. // SetNillableCheckedAt sets the "checked_at" field if the given value is not nil.
  142. func (_u *ChannelMonitorHistoryUpdate) SetNillableCheckedAt(v *time.Time) *ChannelMonitorHistoryUpdate {
  143. if v != nil {
  144. _u.SetCheckedAt(*v)
  145. }
  146. return _u
  147. }
  148. // SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
  149. func (_u *ChannelMonitorHistoryUpdate) SetMonitor(v *ChannelMonitor) *ChannelMonitorHistoryUpdate {
  150. return _u.SetMonitorID(v.ID)
  151. }
  152. // Mutation returns the ChannelMonitorHistoryMutation object of the builder.
  153. func (_u *ChannelMonitorHistoryUpdate) Mutation() *ChannelMonitorHistoryMutation {
  154. return _u.mutation
  155. }
  156. // ClearMonitor clears the "monitor" edge to the ChannelMonitor entity.
  157. func (_u *ChannelMonitorHistoryUpdate) ClearMonitor() *ChannelMonitorHistoryUpdate {
  158. _u.mutation.ClearMonitor()
  159. return _u
  160. }
  161. // Save executes the query and returns the number of nodes affected by the update operation.
  162. func (_u *ChannelMonitorHistoryUpdate) Save(ctx context.Context) (int, error) {
  163. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  164. }
  165. // SaveX is like Save, but panics if an error occurs.
  166. func (_u *ChannelMonitorHistoryUpdate) SaveX(ctx context.Context) int {
  167. affected, err := _u.Save(ctx)
  168. if err != nil {
  169. panic(err)
  170. }
  171. return affected
  172. }
  173. // Exec executes the query.
  174. func (_u *ChannelMonitorHistoryUpdate) Exec(ctx context.Context) error {
  175. _, err := _u.Save(ctx)
  176. return err
  177. }
  178. // ExecX is like Exec, but panics if an error occurs.
  179. func (_u *ChannelMonitorHistoryUpdate) ExecX(ctx context.Context) {
  180. if err := _u.Exec(ctx); err != nil {
  181. panic(err)
  182. }
  183. }
  184. // check runs all checks and user-defined validators on the builder.
  185. func (_u *ChannelMonitorHistoryUpdate) check() error {
  186. if v, ok := _u.mutation.Model(); ok {
  187. if err := channelmonitorhistory.ModelValidator(v); err != nil {
  188. return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.model": %w`, err)}
  189. }
  190. }
  191. if v, ok := _u.mutation.Status(); ok {
  192. if err := channelmonitorhistory.StatusValidator(v); err != nil {
  193. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.status": %w`, err)}
  194. }
  195. }
  196. if v, ok := _u.mutation.Message(); ok {
  197. if err := channelmonitorhistory.MessageValidator(v); err != nil {
  198. return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.message": %w`, err)}
  199. }
  200. }
  201. if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 {
  202. return errors.New(`ent: clearing a required unique edge "ChannelMonitorHistory.monitor"`)
  203. }
  204. return nil
  205. }
  206. func (_u *ChannelMonitorHistoryUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  207. if err := _u.check(); err != nil {
  208. return _node, err
  209. }
  210. _spec := sqlgraph.NewUpdateSpec(channelmonitorhistory.Table, channelmonitorhistory.Columns, sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64))
  211. if ps := _u.mutation.predicates; len(ps) > 0 {
  212. _spec.Predicate = func(selector *sql.Selector) {
  213. for i := range ps {
  214. ps[i](selector)
  215. }
  216. }
  217. }
  218. if value, ok := _u.mutation.Model(); ok {
  219. _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value)
  220. }
  221. if value, ok := _u.mutation.Status(); ok {
  222. _spec.SetField(channelmonitorhistory.FieldStatus, field.TypeEnum, value)
  223. }
  224. if value, ok := _u.mutation.LatencyMs(); ok {
  225. _spec.SetField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
  226. }
  227. if value, ok := _u.mutation.AddedLatencyMs(); ok {
  228. _spec.AddField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
  229. }
  230. if _u.mutation.LatencyMsCleared() {
  231. _spec.ClearField(channelmonitorhistory.FieldLatencyMs, field.TypeInt)
  232. }
  233. if value, ok := _u.mutation.PingLatencyMs(); ok {
  234. _spec.SetField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
  235. }
  236. if value, ok := _u.mutation.AddedPingLatencyMs(); ok {
  237. _spec.AddField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
  238. }
  239. if _u.mutation.PingLatencyMsCleared() {
  240. _spec.ClearField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt)
  241. }
  242. if value, ok := _u.mutation.Message(); ok {
  243. _spec.SetField(channelmonitorhistory.FieldMessage, field.TypeString, value)
  244. }
  245. if _u.mutation.MessageCleared() {
  246. _spec.ClearField(channelmonitorhistory.FieldMessage, field.TypeString)
  247. }
  248. if value, ok := _u.mutation.Quota(); ok {
  249. _spec.SetField(channelmonitorhistory.FieldQuota, field.TypeJSON, value)
  250. }
  251. if _u.mutation.QuotaCleared() {
  252. _spec.ClearField(channelmonitorhistory.FieldQuota, field.TypeJSON)
  253. }
  254. if value, ok := _u.mutation.CheckedAt(); ok {
  255. _spec.SetField(channelmonitorhistory.FieldCheckedAt, field.TypeTime, value)
  256. }
  257. if _u.mutation.MonitorCleared() {
  258. edge := &sqlgraph.EdgeSpec{
  259. Rel: sqlgraph.M2O,
  260. Inverse: true,
  261. Table: channelmonitorhistory.MonitorTable,
  262. Columns: []string{channelmonitorhistory.MonitorColumn},
  263. Bidi: false,
  264. Target: &sqlgraph.EdgeTarget{
  265. IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
  266. },
  267. }
  268. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  269. }
  270. if nodes := _u.mutation.MonitorIDs(); len(nodes) > 0 {
  271. edge := &sqlgraph.EdgeSpec{
  272. Rel: sqlgraph.M2O,
  273. Inverse: true,
  274. Table: channelmonitorhistory.MonitorTable,
  275. Columns: []string{channelmonitorhistory.MonitorColumn},
  276. Bidi: false,
  277. Target: &sqlgraph.EdgeTarget{
  278. IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
  279. },
  280. }
  281. for _, k := range nodes {
  282. edge.Target.Nodes = append(edge.Target.Nodes, k)
  283. }
  284. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  285. }
  286. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  287. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  288. err = &NotFoundError{channelmonitorhistory.Label}
  289. } else if sqlgraph.IsConstraintError(err) {
  290. err = &ConstraintError{msg: err.Error(), wrap: err}
  291. }
  292. return 0, err
  293. }
  294. _u.mutation.done = true
  295. return _node, nil
  296. }
  297. // ChannelMonitorHistoryUpdateOne is the builder for updating a single ChannelMonitorHistory entity.
  298. type ChannelMonitorHistoryUpdateOne struct {
  299. config
  300. fields []string
  301. hooks []Hook
  302. mutation *ChannelMonitorHistoryMutation
  303. }
  304. // SetMonitorID sets the "monitor_id" field.
  305. func (_u *ChannelMonitorHistoryUpdateOne) SetMonitorID(v int64) *ChannelMonitorHistoryUpdateOne {
  306. _u.mutation.SetMonitorID(v)
  307. return _u
  308. }
  309. // SetNillableMonitorID sets the "monitor_id" field if the given value is not nil.
  310. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableMonitorID(v *int64) *ChannelMonitorHistoryUpdateOne {
  311. if v != nil {
  312. _u.SetMonitorID(*v)
  313. }
  314. return _u
  315. }
  316. // SetModel sets the "model" field.
  317. func (_u *ChannelMonitorHistoryUpdateOne) SetModel(v string) *ChannelMonitorHistoryUpdateOne {
  318. _u.mutation.SetModel(v)
  319. return _u
  320. }
  321. // SetNillableModel sets the "model" field if the given value is not nil.
  322. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableModel(v *string) *ChannelMonitorHistoryUpdateOne {
  323. if v != nil {
  324. _u.SetModel(*v)
  325. }
  326. return _u
  327. }
  328. // SetStatus sets the "status" field.
  329. func (_u *ChannelMonitorHistoryUpdateOne) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpdateOne {
  330. _u.mutation.SetStatus(v)
  331. return _u
  332. }
  333. // SetNillableStatus sets the "status" field if the given value is not nil.
  334. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableStatus(v *channelmonitorhistory.Status) *ChannelMonitorHistoryUpdateOne {
  335. if v != nil {
  336. _u.SetStatus(*v)
  337. }
  338. return _u
  339. }
  340. // SetLatencyMs sets the "latency_ms" field.
  341. func (_u *ChannelMonitorHistoryUpdateOne) SetLatencyMs(v int) *ChannelMonitorHistoryUpdateOne {
  342. _u.mutation.ResetLatencyMs()
  343. _u.mutation.SetLatencyMs(v)
  344. return _u
  345. }
  346. // SetNillableLatencyMs sets the "latency_ms" field if the given value is not nil.
  347. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableLatencyMs(v *int) *ChannelMonitorHistoryUpdateOne {
  348. if v != nil {
  349. _u.SetLatencyMs(*v)
  350. }
  351. return _u
  352. }
  353. // AddLatencyMs adds value to the "latency_ms" field.
  354. func (_u *ChannelMonitorHistoryUpdateOne) AddLatencyMs(v int) *ChannelMonitorHistoryUpdateOne {
  355. _u.mutation.AddLatencyMs(v)
  356. return _u
  357. }
  358. // ClearLatencyMs clears the value of the "latency_ms" field.
  359. func (_u *ChannelMonitorHistoryUpdateOne) ClearLatencyMs() *ChannelMonitorHistoryUpdateOne {
  360. _u.mutation.ClearLatencyMs()
  361. return _u
  362. }
  363. // SetPingLatencyMs sets the "ping_latency_ms" field.
  364. func (_u *ChannelMonitorHistoryUpdateOne) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpdateOne {
  365. _u.mutation.ResetPingLatencyMs()
  366. _u.mutation.SetPingLatencyMs(v)
  367. return _u
  368. }
  369. // SetNillablePingLatencyMs sets the "ping_latency_ms" field if the given value is not nil.
  370. func (_u *ChannelMonitorHistoryUpdateOne) SetNillablePingLatencyMs(v *int) *ChannelMonitorHistoryUpdateOne {
  371. if v != nil {
  372. _u.SetPingLatencyMs(*v)
  373. }
  374. return _u
  375. }
  376. // AddPingLatencyMs adds value to the "ping_latency_ms" field.
  377. func (_u *ChannelMonitorHistoryUpdateOne) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpdateOne {
  378. _u.mutation.AddPingLatencyMs(v)
  379. return _u
  380. }
  381. // ClearPingLatencyMs clears the value of the "ping_latency_ms" field.
  382. func (_u *ChannelMonitorHistoryUpdateOne) ClearPingLatencyMs() *ChannelMonitorHistoryUpdateOne {
  383. _u.mutation.ClearPingLatencyMs()
  384. return _u
  385. }
  386. // SetMessage sets the "message" field.
  387. func (_u *ChannelMonitorHistoryUpdateOne) SetMessage(v string) *ChannelMonitorHistoryUpdateOne {
  388. _u.mutation.SetMessage(v)
  389. return _u
  390. }
  391. // SetNillableMessage sets the "message" field if the given value is not nil.
  392. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableMessage(v *string) *ChannelMonitorHistoryUpdateOne {
  393. if v != nil {
  394. _u.SetMessage(*v)
  395. }
  396. return _u
  397. }
  398. // ClearMessage clears the value of the "message" field.
  399. func (_u *ChannelMonitorHistoryUpdateOne) ClearMessage() *ChannelMonitorHistoryUpdateOne {
  400. _u.mutation.ClearMessage()
  401. return _u
  402. }
  403. // SetQuota sets the "quota" field.
  404. func (_u *ChannelMonitorHistoryUpdateOne) SetQuota(v *domain.MonitorQuotaSnapshot) *ChannelMonitorHistoryUpdateOne {
  405. _u.mutation.SetQuota(v)
  406. return _u
  407. }
  408. // ClearQuota clears the value of the "quota" field.
  409. func (_u *ChannelMonitorHistoryUpdateOne) ClearQuota() *ChannelMonitorHistoryUpdateOne {
  410. _u.mutation.ClearQuota()
  411. return _u
  412. }
  413. // SetCheckedAt sets the "checked_at" field.
  414. func (_u *ChannelMonitorHistoryUpdateOne) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpdateOne {
  415. _u.mutation.SetCheckedAt(v)
  416. return _u
  417. }
  418. // SetNillableCheckedAt sets the "checked_at" field if the given value is not nil.
  419. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableCheckedAt(v *time.Time) *ChannelMonitorHistoryUpdateOne {
  420. if v != nil {
  421. _u.SetCheckedAt(*v)
  422. }
  423. return _u
  424. }
  425. // SetMonitor sets the "monitor" edge to the ChannelMonitor entity.
  426. func (_u *ChannelMonitorHistoryUpdateOne) SetMonitor(v *ChannelMonitor) *ChannelMonitorHistoryUpdateOne {
  427. return _u.SetMonitorID(v.ID)
  428. }
  429. // Mutation returns the ChannelMonitorHistoryMutation object of the builder.
  430. func (_u *ChannelMonitorHistoryUpdateOne) Mutation() *ChannelMonitorHistoryMutation {
  431. return _u.mutation
  432. }
  433. // ClearMonitor clears the "monitor" edge to the ChannelMonitor entity.
  434. func (_u *ChannelMonitorHistoryUpdateOne) ClearMonitor() *ChannelMonitorHistoryUpdateOne {
  435. _u.mutation.ClearMonitor()
  436. return _u
  437. }
  438. // Where appends a list predicates to the ChannelMonitorHistoryUpdate builder.
  439. func (_u *ChannelMonitorHistoryUpdateOne) Where(ps ...predicate.ChannelMonitorHistory) *ChannelMonitorHistoryUpdateOne {
  440. _u.mutation.Where(ps...)
  441. return _u
  442. }
  443. // Select allows selecting one or more fields (columns) of the returned entity.
  444. // The default is selecting all fields defined in the entity schema.
  445. func (_u *ChannelMonitorHistoryUpdateOne) Select(field string, fields ...string) *ChannelMonitorHistoryUpdateOne {
  446. _u.fields = append([]string{field}, fields...)
  447. return _u
  448. }
  449. // Save executes the query and returns the updated ChannelMonitorHistory entity.
  450. func (_u *ChannelMonitorHistoryUpdateOne) Save(ctx context.Context) (*ChannelMonitorHistory, error) {
  451. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  452. }
  453. // SaveX is like Save, but panics if an error occurs.
  454. func (_u *ChannelMonitorHistoryUpdateOne) SaveX(ctx context.Context) *ChannelMonitorHistory {
  455. node, err := _u.Save(ctx)
  456. if err != nil {
  457. panic(err)
  458. }
  459. return node
  460. }
  461. // Exec executes the query on the entity.
  462. func (_u *ChannelMonitorHistoryUpdateOne) Exec(ctx context.Context) error {
  463. _, err := _u.Save(ctx)
  464. return err
  465. }
  466. // ExecX is like Exec, but panics if an error occurs.
  467. func (_u *ChannelMonitorHistoryUpdateOne) ExecX(ctx context.Context) {
  468. if err := _u.Exec(ctx); err != nil {
  469. panic(err)
  470. }
  471. }
  472. // check runs all checks and user-defined validators on the builder.
  473. func (_u *ChannelMonitorHistoryUpdateOne) check() error {
  474. if v, ok := _u.mutation.Model(); ok {
  475. if err := channelmonitorhistory.ModelValidator(v); err != nil {
  476. return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.model": %w`, err)}
  477. }
  478. }
  479. if v, ok := _u.mutation.Status(); ok {
  480. if err := channelmonitorhistory.StatusValidator(v); err != nil {
  481. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.status": %w`, err)}
  482. }
  483. }
  484. if v, ok := _u.mutation.Message(); ok {
  485. if err := channelmonitorhistory.MessageValidator(v); err != nil {
  486. return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.message": %w`, err)}
  487. }
  488. }
  489. if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 {
  490. return errors.New(`ent: clearing a required unique edge "ChannelMonitorHistory.monitor"`)
  491. }
  492. return nil
  493. }
  494. func (_u *ChannelMonitorHistoryUpdateOne) sqlSave(ctx context.Context) (_node *ChannelMonitorHistory, err error) {
  495. if err := _u.check(); err != nil {
  496. return _node, err
  497. }
  498. _spec := sqlgraph.NewUpdateSpec(channelmonitorhistory.Table, channelmonitorhistory.Columns, sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64))
  499. id, ok := _u.mutation.ID()
  500. if !ok {
  501. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChannelMonitorHistory.id" for update`)}
  502. }
  503. _spec.Node.ID.Value = id
  504. if fields := _u.fields; len(fields) > 0 {
  505. _spec.Node.Columns = make([]string, 0, len(fields))
  506. _spec.Node.Columns = append(_spec.Node.Columns, channelmonitorhistory.FieldID)
  507. for _, f := range fields {
  508. if !channelmonitorhistory.ValidColumn(f) {
  509. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  510. }
  511. if f != channelmonitorhistory.FieldID {
  512. _spec.Node.Columns = append(_spec.Node.Columns, f)
  513. }
  514. }
  515. }
  516. if ps := _u.mutation.predicates; len(ps) > 0 {
  517. _spec.Predicate = func(selector *sql.Selector) {
  518. for i := range ps {
  519. ps[i](selector)
  520. }
  521. }
  522. }
  523. if value, ok := _u.mutation.Model(); ok {
  524. _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value)
  525. }
  526. if value, ok := _u.mutation.Status(); ok {
  527. _spec.SetField(channelmonitorhistory.FieldStatus, field.TypeEnum, value)
  528. }
  529. if value, ok := _u.mutation.LatencyMs(); ok {
  530. _spec.SetField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
  531. }
  532. if value, ok := _u.mutation.AddedLatencyMs(); ok {
  533. _spec.AddField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value)
  534. }
  535. if _u.mutation.LatencyMsCleared() {
  536. _spec.ClearField(channelmonitorhistory.FieldLatencyMs, field.TypeInt)
  537. }
  538. if value, ok := _u.mutation.PingLatencyMs(); ok {
  539. _spec.SetField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
  540. }
  541. if value, ok := _u.mutation.AddedPingLatencyMs(); ok {
  542. _spec.AddField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value)
  543. }
  544. if _u.mutation.PingLatencyMsCleared() {
  545. _spec.ClearField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt)
  546. }
  547. if value, ok := _u.mutation.Message(); ok {
  548. _spec.SetField(channelmonitorhistory.FieldMessage, field.TypeString, value)
  549. }
  550. if _u.mutation.MessageCleared() {
  551. _spec.ClearField(channelmonitorhistory.FieldMessage, field.TypeString)
  552. }
  553. if value, ok := _u.mutation.Quota(); ok {
  554. _spec.SetField(channelmonitorhistory.FieldQuota, field.TypeJSON, value)
  555. }
  556. if _u.mutation.QuotaCleared() {
  557. _spec.ClearField(channelmonitorhistory.FieldQuota, field.TypeJSON)
  558. }
  559. if value, ok := _u.mutation.CheckedAt(); ok {
  560. _spec.SetField(channelmonitorhistory.FieldCheckedAt, field.TypeTime, value)
  561. }
  562. if _u.mutation.MonitorCleared() {
  563. edge := &sqlgraph.EdgeSpec{
  564. Rel: sqlgraph.M2O,
  565. Inverse: true,
  566. Table: channelmonitorhistory.MonitorTable,
  567. Columns: []string{channelmonitorhistory.MonitorColumn},
  568. Bidi: false,
  569. Target: &sqlgraph.EdgeTarget{
  570. IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
  571. },
  572. }
  573. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  574. }
  575. if nodes := _u.mutation.MonitorIDs(); len(nodes) > 0 {
  576. edge := &sqlgraph.EdgeSpec{
  577. Rel: sqlgraph.M2O,
  578. Inverse: true,
  579. Table: channelmonitorhistory.MonitorTable,
  580. Columns: []string{channelmonitorhistory.MonitorColumn},
  581. Bidi: false,
  582. Target: &sqlgraph.EdgeTarget{
  583. IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
  584. },
  585. }
  586. for _, k := range nodes {
  587. edge.Target.Nodes = append(edge.Target.Nodes, k)
  588. }
  589. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  590. }
  591. _node = &ChannelMonitorHistory{config: _u.config}
  592. _spec.Assign = _node.assignValues
  593. _spec.ScanValues = _node.scanValues
  594. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  595. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  596. err = &NotFoundError{channelmonitorhistory.Label}
  597. } else if sqlgraph.IsConstraintError(err) {
  598. err = &ConstraintError{msg: err.Error(), wrap: err}
  599. }
  600. return nil, err
  601. }
  602. _u.mutation.done = true
  603. return _node, nil
  604. }