proxy.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "entgo.io/ent"
  8. "entgo.io/ent/dialect/sql"
  9. "github.com/Wei-Shaw/sub2api/ent/proxy"
  10. )
  11. // Proxy is the model entity for the Proxy schema.
  12. type Proxy struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID int64 `json:"id,omitempty"`
  16. // CreatedAt holds the value of the "created_at" field.
  17. CreatedAt time.Time `json:"created_at,omitempty"`
  18. // UpdatedAt holds the value of the "updated_at" field.
  19. UpdatedAt time.Time `json:"updated_at,omitempty"`
  20. // DeletedAt holds the value of the "deleted_at" field.
  21. DeletedAt *time.Time `json:"deleted_at,omitempty"`
  22. // Name holds the value of the "name" field.
  23. Name string `json:"name,omitempty"`
  24. // Protocol holds the value of the "protocol" field.
  25. Protocol string `json:"protocol,omitempty"`
  26. // Host holds the value of the "host" field.
  27. Host string `json:"host,omitempty"`
  28. // Port holds the value of the "port" field.
  29. Port int `json:"port,omitempty"`
  30. // Username holds the value of the "username" field.
  31. Username *string `json:"username,omitempty"`
  32. // Password holds the value of the "password" field.
  33. Password *string `json:"password,omitempty"`
  34. // Status holds the value of the "status" field.
  35. Status string `json:"status,omitempty"`
  36. // Proxy expiration time (NULL means never expires).
  37. ExpiresAt *time.Time `json:"expires_at,omitempty"`
  38. // Fallback target on expiry: none | proxy | direct.
  39. FallbackMode string `json:"fallback_mode,omitempty"`
  40. // Backup proxy id when fallback_mode=proxy (self-reference).
  41. BackupProxyID *int64 `json:"backup_proxy_id,omitempty"`
  42. // Days before expiry to flag as expiring-soon (per proxy).
  43. ExpiryWarnDays int `json:"expiry_warn_days,omitempty"`
  44. // Edges holds the relations/edges for other nodes in the graph.
  45. // The values are being populated by the ProxyQuery when eager-loading is set.
  46. Edges ProxyEdges `json:"edges"`
  47. selectValues sql.SelectValues
  48. }
  49. // ProxyEdges holds the relations/edges for other nodes in the graph.
  50. type ProxyEdges struct {
  51. // Accounts holds the value of the accounts edge.
  52. Accounts []*Account `json:"accounts,omitempty"`
  53. // PrimaryProxies holds the value of the primary_proxies edge.
  54. PrimaryProxies []*Proxy `json:"primary_proxies,omitempty"`
  55. // BackupProxy holds the value of the backup_proxy edge.
  56. BackupProxy *Proxy `json:"backup_proxy,omitempty"`
  57. // loadedTypes holds the information for reporting if a
  58. // type was loaded (or requested) in eager-loading or not.
  59. loadedTypes [3]bool
  60. }
  61. // AccountsOrErr returns the Accounts value or an error if the edge
  62. // was not loaded in eager-loading.
  63. func (e ProxyEdges) AccountsOrErr() ([]*Account, error) {
  64. if e.loadedTypes[0] {
  65. return e.Accounts, nil
  66. }
  67. return nil, &NotLoadedError{edge: "accounts"}
  68. }
  69. // PrimaryProxiesOrErr returns the PrimaryProxies value or an error if the edge
  70. // was not loaded in eager-loading.
  71. func (e ProxyEdges) PrimaryProxiesOrErr() ([]*Proxy, error) {
  72. if e.loadedTypes[1] {
  73. return e.PrimaryProxies, nil
  74. }
  75. return nil, &NotLoadedError{edge: "primary_proxies"}
  76. }
  77. // BackupProxyOrErr returns the BackupProxy value or an error if the edge
  78. // was not loaded in eager-loading, or loaded but was not found.
  79. func (e ProxyEdges) BackupProxyOrErr() (*Proxy, error) {
  80. if e.BackupProxy != nil {
  81. return e.BackupProxy, nil
  82. } else if e.loadedTypes[2] {
  83. return nil, &NotFoundError{label: proxy.Label}
  84. }
  85. return nil, &NotLoadedError{edge: "backup_proxy"}
  86. }
  87. // scanValues returns the types for scanning values from sql.Rows.
  88. func (*Proxy) scanValues(columns []string) ([]any, error) {
  89. values := make([]any, len(columns))
  90. for i := range columns {
  91. switch columns[i] {
  92. case proxy.FieldID, proxy.FieldPort, proxy.FieldBackupProxyID, proxy.FieldExpiryWarnDays:
  93. values[i] = new(sql.NullInt64)
  94. case proxy.FieldName, proxy.FieldProtocol, proxy.FieldHost, proxy.FieldUsername, proxy.FieldPassword, proxy.FieldStatus, proxy.FieldFallbackMode:
  95. values[i] = new(sql.NullString)
  96. case proxy.FieldCreatedAt, proxy.FieldUpdatedAt, proxy.FieldDeletedAt, proxy.FieldExpiresAt:
  97. values[i] = new(sql.NullTime)
  98. default:
  99. values[i] = new(sql.UnknownType)
  100. }
  101. }
  102. return values, nil
  103. }
  104. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  105. // to the Proxy fields.
  106. func (_m *Proxy) assignValues(columns []string, values []any) error {
  107. if m, n := len(values), len(columns); m < n {
  108. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  109. }
  110. for i := range columns {
  111. switch columns[i] {
  112. case proxy.FieldID:
  113. value, ok := values[i].(*sql.NullInt64)
  114. if !ok {
  115. return fmt.Errorf("unexpected type %T for field id", value)
  116. }
  117. _m.ID = int64(value.Int64)
  118. case proxy.FieldCreatedAt:
  119. if value, ok := values[i].(*sql.NullTime); !ok {
  120. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  121. } else if value.Valid {
  122. _m.CreatedAt = value.Time
  123. }
  124. case proxy.FieldUpdatedAt:
  125. if value, ok := values[i].(*sql.NullTime); !ok {
  126. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  127. } else if value.Valid {
  128. _m.UpdatedAt = value.Time
  129. }
  130. case proxy.FieldDeletedAt:
  131. if value, ok := values[i].(*sql.NullTime); !ok {
  132. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  133. } else if value.Valid {
  134. _m.DeletedAt = new(time.Time)
  135. *_m.DeletedAt = value.Time
  136. }
  137. case proxy.FieldName:
  138. if value, ok := values[i].(*sql.NullString); !ok {
  139. return fmt.Errorf("unexpected type %T for field name", values[i])
  140. } else if value.Valid {
  141. _m.Name = value.String
  142. }
  143. case proxy.FieldProtocol:
  144. if value, ok := values[i].(*sql.NullString); !ok {
  145. return fmt.Errorf("unexpected type %T for field protocol", values[i])
  146. } else if value.Valid {
  147. _m.Protocol = value.String
  148. }
  149. case proxy.FieldHost:
  150. if value, ok := values[i].(*sql.NullString); !ok {
  151. return fmt.Errorf("unexpected type %T for field host", values[i])
  152. } else if value.Valid {
  153. _m.Host = value.String
  154. }
  155. case proxy.FieldPort:
  156. if value, ok := values[i].(*sql.NullInt64); !ok {
  157. return fmt.Errorf("unexpected type %T for field port", values[i])
  158. } else if value.Valid {
  159. _m.Port = int(value.Int64)
  160. }
  161. case proxy.FieldUsername:
  162. if value, ok := values[i].(*sql.NullString); !ok {
  163. return fmt.Errorf("unexpected type %T for field username", values[i])
  164. } else if value.Valid {
  165. _m.Username = new(string)
  166. *_m.Username = value.String
  167. }
  168. case proxy.FieldPassword:
  169. if value, ok := values[i].(*sql.NullString); !ok {
  170. return fmt.Errorf("unexpected type %T for field password", values[i])
  171. } else if value.Valid {
  172. _m.Password = new(string)
  173. *_m.Password = value.String
  174. }
  175. case proxy.FieldStatus:
  176. if value, ok := values[i].(*sql.NullString); !ok {
  177. return fmt.Errorf("unexpected type %T for field status", values[i])
  178. } else if value.Valid {
  179. _m.Status = value.String
  180. }
  181. case proxy.FieldExpiresAt:
  182. if value, ok := values[i].(*sql.NullTime); !ok {
  183. return fmt.Errorf("unexpected type %T for field expires_at", values[i])
  184. } else if value.Valid {
  185. _m.ExpiresAt = new(time.Time)
  186. *_m.ExpiresAt = value.Time
  187. }
  188. case proxy.FieldFallbackMode:
  189. if value, ok := values[i].(*sql.NullString); !ok {
  190. return fmt.Errorf("unexpected type %T for field fallback_mode", values[i])
  191. } else if value.Valid {
  192. _m.FallbackMode = value.String
  193. }
  194. case proxy.FieldBackupProxyID:
  195. if value, ok := values[i].(*sql.NullInt64); !ok {
  196. return fmt.Errorf("unexpected type %T for field backup_proxy_id", values[i])
  197. } else if value.Valid {
  198. _m.BackupProxyID = new(int64)
  199. *_m.BackupProxyID = value.Int64
  200. }
  201. case proxy.FieldExpiryWarnDays:
  202. if value, ok := values[i].(*sql.NullInt64); !ok {
  203. return fmt.Errorf("unexpected type %T for field expiry_warn_days", values[i])
  204. } else if value.Valid {
  205. _m.ExpiryWarnDays = int(value.Int64)
  206. }
  207. default:
  208. _m.selectValues.Set(columns[i], values[i])
  209. }
  210. }
  211. return nil
  212. }
  213. // Value returns the ent.Value that was dynamically selected and assigned to the Proxy.
  214. // This includes values selected through modifiers, order, etc.
  215. func (_m *Proxy) Value(name string) (ent.Value, error) {
  216. return _m.selectValues.Get(name)
  217. }
  218. // QueryAccounts queries the "accounts" edge of the Proxy entity.
  219. func (_m *Proxy) QueryAccounts() *AccountQuery {
  220. return NewProxyClient(_m.config).QueryAccounts(_m)
  221. }
  222. // QueryPrimaryProxies queries the "primary_proxies" edge of the Proxy entity.
  223. func (_m *Proxy) QueryPrimaryProxies() *ProxyQuery {
  224. return NewProxyClient(_m.config).QueryPrimaryProxies(_m)
  225. }
  226. // QueryBackupProxy queries the "backup_proxy" edge of the Proxy entity.
  227. func (_m *Proxy) QueryBackupProxy() *ProxyQuery {
  228. return NewProxyClient(_m.config).QueryBackupProxy(_m)
  229. }
  230. // Update returns a builder for updating this Proxy.
  231. // Note that you need to call Proxy.Unwrap() before calling this method if this Proxy
  232. // was returned from a transaction, and the transaction was committed or rolled back.
  233. func (_m *Proxy) Update() *ProxyUpdateOne {
  234. return NewProxyClient(_m.config).UpdateOne(_m)
  235. }
  236. // Unwrap unwraps the Proxy entity that was returned from a transaction after it was closed,
  237. // so that all future queries will be executed through the driver which created the transaction.
  238. func (_m *Proxy) Unwrap() *Proxy {
  239. _tx, ok := _m.config.driver.(*txDriver)
  240. if !ok {
  241. panic("ent: Proxy is not a transactional entity")
  242. }
  243. _m.config.driver = _tx.drv
  244. return _m
  245. }
  246. // String implements the fmt.Stringer.
  247. func (_m *Proxy) String() string {
  248. var builder strings.Builder
  249. builder.WriteString("Proxy(")
  250. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  251. builder.WriteString("created_at=")
  252. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  253. builder.WriteString(", ")
  254. builder.WriteString("updated_at=")
  255. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  256. builder.WriteString(", ")
  257. if v := _m.DeletedAt; v != nil {
  258. builder.WriteString("deleted_at=")
  259. builder.WriteString(v.Format(time.ANSIC))
  260. }
  261. builder.WriteString(", ")
  262. builder.WriteString("name=")
  263. builder.WriteString(_m.Name)
  264. builder.WriteString(", ")
  265. builder.WriteString("protocol=")
  266. builder.WriteString(_m.Protocol)
  267. builder.WriteString(", ")
  268. builder.WriteString("host=")
  269. builder.WriteString(_m.Host)
  270. builder.WriteString(", ")
  271. builder.WriteString("port=")
  272. builder.WriteString(fmt.Sprintf("%v", _m.Port))
  273. builder.WriteString(", ")
  274. if v := _m.Username; v != nil {
  275. builder.WriteString("username=")
  276. builder.WriteString(*v)
  277. }
  278. builder.WriteString(", ")
  279. if v := _m.Password; v != nil {
  280. builder.WriteString("password=")
  281. builder.WriteString(*v)
  282. }
  283. builder.WriteString(", ")
  284. builder.WriteString("status=")
  285. builder.WriteString(_m.Status)
  286. builder.WriteString(", ")
  287. if v := _m.ExpiresAt; v != nil {
  288. builder.WriteString("expires_at=")
  289. builder.WriteString(v.Format(time.ANSIC))
  290. }
  291. builder.WriteString(", ")
  292. builder.WriteString("fallback_mode=")
  293. builder.WriteString(_m.FallbackMode)
  294. builder.WriteString(", ")
  295. if v := _m.BackupProxyID; v != nil {
  296. builder.WriteString("backup_proxy_id=")
  297. builder.WriteString(fmt.Sprintf("%v", *v))
  298. }
  299. builder.WriteString(", ")
  300. builder.WriteString("expiry_warn_days=")
  301. builder.WriteString(fmt.Sprintf("%v", _m.ExpiryWarnDays))
  302. builder.WriteByte(')')
  303. return builder.String()
  304. }
  305. // Proxies is a parsable slice of Proxy.
  306. type Proxies []*Proxy