channelmonitorhistory.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. "github.com/Wei-Shaw/sub2api/ent/channelmonitor"
  11. "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory"
  12. "github.com/Wei-Shaw/sub2api/internal/domain"
  13. )
  14. // ChannelMonitorHistory is the model entity for the ChannelMonitorHistory schema.
  15. type ChannelMonitorHistory struct {
  16. config `json:"-"`
  17. // ID of the ent.
  18. ID int64 `json:"id,omitempty"`
  19. // MonitorID holds the value of the "monitor_id" field.
  20. MonitorID int64 `json:"monitor_id,omitempty"`
  21. // Model holds the value of the "model" field.
  22. Model string `json:"model,omitempty"`
  23. // Status holds the value of the "status" field.
  24. Status channelmonitorhistory.Status `json:"status,omitempty"`
  25. // LatencyMs holds the value of the "latency_ms" field.
  26. LatencyMs *int `json:"latency_ms,omitempty"`
  27. // PingLatencyMs holds the value of the "ping_latency_ms" field.
  28. PingLatencyMs *int `json:"ping_latency_ms,omitempty"`
  29. // Message holds the value of the "message" field.
  30. Message string `json:"message,omitempty"`
  31. // Quota holds the value of the "quota" field.
  32. Quota *domain.MonitorQuotaSnapshot `json:"quota,omitempty"`
  33. // CheckedAt holds the value of the "checked_at" field.
  34. CheckedAt time.Time `json:"checked_at,omitempty"`
  35. // Edges holds the relations/edges for other nodes in the graph.
  36. // The values are being populated by the ChannelMonitorHistoryQuery when eager-loading is set.
  37. Edges ChannelMonitorHistoryEdges `json:"edges"`
  38. selectValues sql.SelectValues
  39. }
  40. // ChannelMonitorHistoryEdges holds the relations/edges for other nodes in the graph.
  41. type ChannelMonitorHistoryEdges struct {
  42. // Monitor holds the value of the monitor edge.
  43. Monitor *ChannelMonitor `json:"monitor,omitempty"`
  44. // loadedTypes holds the information for reporting if a
  45. // type was loaded (or requested) in eager-loading or not.
  46. loadedTypes [1]bool
  47. }
  48. // MonitorOrErr returns the Monitor value or an error if the edge
  49. // was not loaded in eager-loading, or loaded but was not found.
  50. func (e ChannelMonitorHistoryEdges) MonitorOrErr() (*ChannelMonitor, error) {
  51. if e.Monitor != nil {
  52. return e.Monitor, nil
  53. } else if e.loadedTypes[0] {
  54. return nil, &NotFoundError{label: channelmonitor.Label}
  55. }
  56. return nil, &NotLoadedError{edge: "monitor"}
  57. }
  58. // scanValues returns the types for scanning values from sql.Rows.
  59. func (*ChannelMonitorHistory) scanValues(columns []string) ([]any, error) {
  60. values := make([]any, len(columns))
  61. for i := range columns {
  62. switch columns[i] {
  63. case channelmonitorhistory.FieldQuota:
  64. values[i] = new([]byte)
  65. case channelmonitorhistory.FieldID, channelmonitorhistory.FieldMonitorID, channelmonitorhistory.FieldLatencyMs, channelmonitorhistory.FieldPingLatencyMs:
  66. values[i] = new(sql.NullInt64)
  67. case channelmonitorhistory.FieldModel, channelmonitorhistory.FieldStatus, channelmonitorhistory.FieldMessage:
  68. values[i] = new(sql.NullString)
  69. case channelmonitorhistory.FieldCheckedAt:
  70. values[i] = new(sql.NullTime)
  71. default:
  72. values[i] = new(sql.UnknownType)
  73. }
  74. }
  75. return values, nil
  76. }
  77. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  78. // to the ChannelMonitorHistory fields.
  79. func (_m *ChannelMonitorHistory) assignValues(columns []string, values []any) error {
  80. if m, n := len(values), len(columns); m < n {
  81. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  82. }
  83. for i := range columns {
  84. switch columns[i] {
  85. case channelmonitorhistory.FieldID:
  86. value, ok := values[i].(*sql.NullInt64)
  87. if !ok {
  88. return fmt.Errorf("unexpected type %T for field id", value)
  89. }
  90. _m.ID = int64(value.Int64)
  91. case channelmonitorhistory.FieldMonitorID:
  92. if value, ok := values[i].(*sql.NullInt64); !ok {
  93. return fmt.Errorf("unexpected type %T for field monitor_id", values[i])
  94. } else if value.Valid {
  95. _m.MonitorID = value.Int64
  96. }
  97. case channelmonitorhistory.FieldModel:
  98. if value, ok := values[i].(*sql.NullString); !ok {
  99. return fmt.Errorf("unexpected type %T for field model", values[i])
  100. } else if value.Valid {
  101. _m.Model = value.String
  102. }
  103. case channelmonitorhistory.FieldStatus:
  104. if value, ok := values[i].(*sql.NullString); !ok {
  105. return fmt.Errorf("unexpected type %T for field status", values[i])
  106. } else if value.Valid {
  107. _m.Status = channelmonitorhistory.Status(value.String)
  108. }
  109. case channelmonitorhistory.FieldLatencyMs:
  110. if value, ok := values[i].(*sql.NullInt64); !ok {
  111. return fmt.Errorf("unexpected type %T for field latency_ms", values[i])
  112. } else if value.Valid {
  113. _m.LatencyMs = new(int)
  114. *_m.LatencyMs = int(value.Int64)
  115. }
  116. case channelmonitorhistory.FieldPingLatencyMs:
  117. if value, ok := values[i].(*sql.NullInt64); !ok {
  118. return fmt.Errorf("unexpected type %T for field ping_latency_ms", values[i])
  119. } else if value.Valid {
  120. _m.PingLatencyMs = new(int)
  121. *_m.PingLatencyMs = int(value.Int64)
  122. }
  123. case channelmonitorhistory.FieldMessage:
  124. if value, ok := values[i].(*sql.NullString); !ok {
  125. return fmt.Errorf("unexpected type %T for field message", values[i])
  126. } else if value.Valid {
  127. _m.Message = value.String
  128. }
  129. case channelmonitorhistory.FieldQuota:
  130. if value, ok := values[i].(*[]byte); !ok {
  131. return fmt.Errorf("unexpected type %T for field quota", values[i])
  132. } else if value != nil && len(*value) > 0 {
  133. if err := json.Unmarshal(*value, &_m.Quota); err != nil {
  134. return fmt.Errorf("unmarshal field quota: %w", err)
  135. }
  136. }
  137. case channelmonitorhistory.FieldCheckedAt:
  138. if value, ok := values[i].(*sql.NullTime); !ok {
  139. return fmt.Errorf("unexpected type %T for field checked_at", values[i])
  140. } else if value.Valid {
  141. _m.CheckedAt = value.Time
  142. }
  143. default:
  144. _m.selectValues.Set(columns[i], values[i])
  145. }
  146. }
  147. return nil
  148. }
  149. // Value returns the ent.Value that was dynamically selected and assigned to the ChannelMonitorHistory.
  150. // This includes values selected through modifiers, order, etc.
  151. func (_m *ChannelMonitorHistory) Value(name string) (ent.Value, error) {
  152. return _m.selectValues.Get(name)
  153. }
  154. // QueryMonitor queries the "monitor" edge of the ChannelMonitorHistory entity.
  155. func (_m *ChannelMonitorHistory) QueryMonitor() *ChannelMonitorQuery {
  156. return NewChannelMonitorHistoryClient(_m.config).QueryMonitor(_m)
  157. }
  158. // Update returns a builder for updating this ChannelMonitorHistory.
  159. // Note that you need to call ChannelMonitorHistory.Unwrap() before calling this method if this ChannelMonitorHistory
  160. // was returned from a transaction, and the transaction was committed or rolled back.
  161. func (_m *ChannelMonitorHistory) Update() *ChannelMonitorHistoryUpdateOne {
  162. return NewChannelMonitorHistoryClient(_m.config).UpdateOne(_m)
  163. }
  164. // Unwrap unwraps the ChannelMonitorHistory entity that was returned from a transaction after it was closed,
  165. // so that all future queries will be executed through the driver which created the transaction.
  166. func (_m *ChannelMonitorHistory) Unwrap() *ChannelMonitorHistory {
  167. _tx, ok := _m.config.driver.(*txDriver)
  168. if !ok {
  169. panic("ent: ChannelMonitorHistory is not a transactional entity")
  170. }
  171. _m.config.driver = _tx.drv
  172. return _m
  173. }
  174. // String implements the fmt.Stringer.
  175. func (_m *ChannelMonitorHistory) String() string {
  176. var builder strings.Builder
  177. builder.WriteString("ChannelMonitorHistory(")
  178. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  179. builder.WriteString("monitor_id=")
  180. builder.WriteString(fmt.Sprintf("%v", _m.MonitorID))
  181. builder.WriteString(", ")
  182. builder.WriteString("model=")
  183. builder.WriteString(_m.Model)
  184. builder.WriteString(", ")
  185. builder.WriteString("status=")
  186. builder.WriteString(fmt.Sprintf("%v", _m.Status))
  187. builder.WriteString(", ")
  188. if v := _m.LatencyMs; v != nil {
  189. builder.WriteString("latency_ms=")
  190. builder.WriteString(fmt.Sprintf("%v", *v))
  191. }
  192. builder.WriteString(", ")
  193. if v := _m.PingLatencyMs; v != nil {
  194. builder.WriteString("ping_latency_ms=")
  195. builder.WriteString(fmt.Sprintf("%v", *v))
  196. }
  197. builder.WriteString(", ")
  198. builder.WriteString("message=")
  199. builder.WriteString(_m.Message)
  200. builder.WriteString(", ")
  201. builder.WriteString("quota=")
  202. builder.WriteString(fmt.Sprintf("%v", _m.Quota))
  203. builder.WriteString(", ")
  204. builder.WriteString("checked_at=")
  205. builder.WriteString(_m.CheckedAt.Format(time.ANSIC))
  206. builder.WriteByte(')')
  207. return builder.String()
  208. }
  209. // ChannelMonitorHistories is a parsable slice of ChannelMonitorHistory.
  210. type ChannelMonitorHistories []*ChannelMonitorHistory