wx.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/agent"
  8. "wechat-api/ent/server"
  9. "wechat-api/ent/wx"
  10. "entgo.io/ent"
  11. "entgo.io/ent/dialect/sql"
  12. )
  13. // Wx is the model entity for the Wx schema.
  14. type Wx struct {
  15. config `json:"-"`
  16. // ID of the ent.
  17. ID uint64 `json:"id,omitempty"`
  18. // Create Time | 创建日期
  19. CreatedAt time.Time `json:"created_at,omitempty"`
  20. // Update Time | 修改日期
  21. UpdatedAt time.Time `json:"updated_at,omitempty"`
  22. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  23. Status uint8 `json:"status,omitempty"`
  24. // Delete Time | 删除日期
  25. DeletedAt time.Time `json:"deleted_at,omitempty"`
  26. // 服务器id
  27. ServerID uint64 `json:"server_id,omitempty"`
  28. // 端口号
  29. Port string `json:"port,omitempty"`
  30. // 进程号
  31. ProcessID string `json:"process_id,omitempty"`
  32. // 回调地址
  33. Callback string `json:"callback,omitempty"`
  34. // 微信id
  35. Wxid string `json:"wxid,omitempty"`
  36. // 微信账号
  37. Account string `json:"account,omitempty"`
  38. // 微信昵称
  39. Nickname string `json:"nickname,omitempty"`
  40. // 手机号
  41. Tel string `json:"tel,omitempty"`
  42. // 微信头像
  43. HeadBig string `json:"head_big,omitempty"`
  44. // 机构 ID
  45. OrganizationID uint64 `json:"organization_id,omitempty"`
  46. // 模式ID
  47. AgentID uint64 `json:"agent_id,omitempty"`
  48. // Edges holds the relations/edges for other nodes in the graph.
  49. // The values are being populated by the WxQuery when eager-loading is set.
  50. Edges WxEdges `json:"edges"`
  51. selectValues sql.SelectValues
  52. }
  53. // WxEdges holds the relations/edges for other nodes in the graph.
  54. type WxEdges struct {
  55. // Server holds the value of the server edge.
  56. Server *Server `json:"server,omitempty"`
  57. // Agent holds the value of the agent edge.
  58. Agent *Agent `json:"agent,omitempty"`
  59. // loadedTypes holds the information for reporting if a
  60. // type was loaded (or requested) in eager-loading or not.
  61. loadedTypes [2]bool
  62. }
  63. // ServerOrErr returns the Server value or an error if the edge
  64. // was not loaded in eager-loading, or loaded but was not found.
  65. func (e WxEdges) ServerOrErr() (*Server, error) {
  66. if e.Server != nil {
  67. return e.Server, nil
  68. } else if e.loadedTypes[0] {
  69. return nil, &NotFoundError{label: server.Label}
  70. }
  71. return nil, &NotLoadedError{edge: "server"}
  72. }
  73. // AgentOrErr returns the Agent value or an error if the edge
  74. // was not loaded in eager-loading, or loaded but was not found.
  75. func (e WxEdges) AgentOrErr() (*Agent, error) {
  76. if e.Agent != nil {
  77. return e.Agent, nil
  78. } else if e.loadedTypes[1] {
  79. return nil, &NotFoundError{label: agent.Label}
  80. }
  81. return nil, &NotLoadedError{edge: "agent"}
  82. }
  83. // scanValues returns the types for scanning values from sql.Rows.
  84. func (*Wx) scanValues(columns []string) ([]any, error) {
  85. values := make([]any, len(columns))
  86. for i := range columns {
  87. switch columns[i] {
  88. case wx.FieldID, wx.FieldStatus, wx.FieldServerID, wx.FieldOrganizationID, wx.FieldAgentID:
  89. values[i] = new(sql.NullInt64)
  90. case wx.FieldPort, wx.FieldProcessID, wx.FieldCallback, wx.FieldWxid, wx.FieldAccount, wx.FieldNickname, wx.FieldTel, wx.FieldHeadBig:
  91. values[i] = new(sql.NullString)
  92. case wx.FieldCreatedAt, wx.FieldUpdatedAt, wx.FieldDeletedAt:
  93. values[i] = new(sql.NullTime)
  94. default:
  95. values[i] = new(sql.UnknownType)
  96. }
  97. }
  98. return values, nil
  99. }
  100. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  101. // to the Wx fields.
  102. func (w *Wx) assignValues(columns []string, values []any) error {
  103. if m, n := len(values), len(columns); m < n {
  104. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  105. }
  106. for i := range columns {
  107. switch columns[i] {
  108. case wx.FieldID:
  109. value, ok := values[i].(*sql.NullInt64)
  110. if !ok {
  111. return fmt.Errorf("unexpected type %T for field id", value)
  112. }
  113. w.ID = uint64(value.Int64)
  114. case wx.FieldCreatedAt:
  115. if value, ok := values[i].(*sql.NullTime); !ok {
  116. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  117. } else if value.Valid {
  118. w.CreatedAt = value.Time
  119. }
  120. case wx.FieldUpdatedAt:
  121. if value, ok := values[i].(*sql.NullTime); !ok {
  122. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  123. } else if value.Valid {
  124. w.UpdatedAt = value.Time
  125. }
  126. case wx.FieldStatus:
  127. if value, ok := values[i].(*sql.NullInt64); !ok {
  128. return fmt.Errorf("unexpected type %T for field status", values[i])
  129. } else if value.Valid {
  130. w.Status = uint8(value.Int64)
  131. }
  132. case wx.FieldDeletedAt:
  133. if value, ok := values[i].(*sql.NullTime); !ok {
  134. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  135. } else if value.Valid {
  136. w.DeletedAt = value.Time
  137. }
  138. case wx.FieldServerID:
  139. if value, ok := values[i].(*sql.NullInt64); !ok {
  140. return fmt.Errorf("unexpected type %T for field server_id", values[i])
  141. } else if value.Valid {
  142. w.ServerID = uint64(value.Int64)
  143. }
  144. case wx.FieldPort:
  145. if value, ok := values[i].(*sql.NullString); !ok {
  146. return fmt.Errorf("unexpected type %T for field port", values[i])
  147. } else if value.Valid {
  148. w.Port = value.String
  149. }
  150. case wx.FieldProcessID:
  151. if value, ok := values[i].(*sql.NullString); !ok {
  152. return fmt.Errorf("unexpected type %T for field process_id", values[i])
  153. } else if value.Valid {
  154. w.ProcessID = value.String
  155. }
  156. case wx.FieldCallback:
  157. if value, ok := values[i].(*sql.NullString); !ok {
  158. return fmt.Errorf("unexpected type %T for field callback", values[i])
  159. } else if value.Valid {
  160. w.Callback = value.String
  161. }
  162. case wx.FieldWxid:
  163. if value, ok := values[i].(*sql.NullString); !ok {
  164. return fmt.Errorf("unexpected type %T for field wxid", values[i])
  165. } else if value.Valid {
  166. w.Wxid = value.String
  167. }
  168. case wx.FieldAccount:
  169. if value, ok := values[i].(*sql.NullString); !ok {
  170. return fmt.Errorf("unexpected type %T for field account", values[i])
  171. } else if value.Valid {
  172. w.Account = value.String
  173. }
  174. case wx.FieldNickname:
  175. if value, ok := values[i].(*sql.NullString); !ok {
  176. return fmt.Errorf("unexpected type %T for field nickname", values[i])
  177. } else if value.Valid {
  178. w.Nickname = value.String
  179. }
  180. case wx.FieldTel:
  181. if value, ok := values[i].(*sql.NullString); !ok {
  182. return fmt.Errorf("unexpected type %T for field tel", values[i])
  183. } else if value.Valid {
  184. w.Tel = value.String
  185. }
  186. case wx.FieldHeadBig:
  187. if value, ok := values[i].(*sql.NullString); !ok {
  188. return fmt.Errorf("unexpected type %T for field head_big", values[i])
  189. } else if value.Valid {
  190. w.HeadBig = value.String
  191. }
  192. case wx.FieldOrganizationID:
  193. if value, ok := values[i].(*sql.NullInt64); !ok {
  194. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  195. } else if value.Valid {
  196. w.OrganizationID = uint64(value.Int64)
  197. }
  198. case wx.FieldAgentID:
  199. if value, ok := values[i].(*sql.NullInt64); !ok {
  200. return fmt.Errorf("unexpected type %T for field agent_id", values[i])
  201. } else if value.Valid {
  202. w.AgentID = uint64(value.Int64)
  203. }
  204. default:
  205. w.selectValues.Set(columns[i], values[i])
  206. }
  207. }
  208. return nil
  209. }
  210. // Value returns the ent.Value that was dynamically selected and assigned to the Wx.
  211. // This includes values selected through modifiers, order, etc.
  212. func (w *Wx) Value(name string) (ent.Value, error) {
  213. return w.selectValues.Get(name)
  214. }
  215. // QueryServer queries the "server" edge of the Wx entity.
  216. func (w *Wx) QueryServer() *ServerQuery {
  217. return NewWxClient(w.config).QueryServer(w)
  218. }
  219. // QueryAgent queries the "agent" edge of the Wx entity.
  220. func (w *Wx) QueryAgent() *AgentQuery {
  221. return NewWxClient(w.config).QueryAgent(w)
  222. }
  223. // Update returns a builder for updating this Wx.
  224. // Note that you need to call Wx.Unwrap() before calling this method if this Wx
  225. // was returned from a transaction, and the transaction was committed or rolled back.
  226. func (w *Wx) Update() *WxUpdateOne {
  227. return NewWxClient(w.config).UpdateOne(w)
  228. }
  229. // Unwrap unwraps the Wx entity that was returned from a transaction after it was closed,
  230. // so that all future queries will be executed through the driver which created the transaction.
  231. func (w *Wx) Unwrap() *Wx {
  232. _tx, ok := w.config.driver.(*txDriver)
  233. if !ok {
  234. panic("ent: Wx is not a transactional entity")
  235. }
  236. w.config.driver = _tx.drv
  237. return w
  238. }
  239. // String implements the fmt.Stringer.
  240. func (w *Wx) String() string {
  241. var builder strings.Builder
  242. builder.WriteString("Wx(")
  243. builder.WriteString(fmt.Sprintf("id=%v, ", w.ID))
  244. builder.WriteString("created_at=")
  245. builder.WriteString(w.CreatedAt.Format(time.ANSIC))
  246. builder.WriteString(", ")
  247. builder.WriteString("updated_at=")
  248. builder.WriteString(w.UpdatedAt.Format(time.ANSIC))
  249. builder.WriteString(", ")
  250. builder.WriteString("status=")
  251. builder.WriteString(fmt.Sprintf("%v", w.Status))
  252. builder.WriteString(", ")
  253. builder.WriteString("deleted_at=")
  254. builder.WriteString(w.DeletedAt.Format(time.ANSIC))
  255. builder.WriteString(", ")
  256. builder.WriteString("server_id=")
  257. builder.WriteString(fmt.Sprintf("%v", w.ServerID))
  258. builder.WriteString(", ")
  259. builder.WriteString("port=")
  260. builder.WriteString(w.Port)
  261. builder.WriteString(", ")
  262. builder.WriteString("process_id=")
  263. builder.WriteString(w.ProcessID)
  264. builder.WriteString(", ")
  265. builder.WriteString("callback=")
  266. builder.WriteString(w.Callback)
  267. builder.WriteString(", ")
  268. builder.WriteString("wxid=")
  269. builder.WriteString(w.Wxid)
  270. builder.WriteString(", ")
  271. builder.WriteString("account=")
  272. builder.WriteString(w.Account)
  273. builder.WriteString(", ")
  274. builder.WriteString("nickname=")
  275. builder.WriteString(w.Nickname)
  276. builder.WriteString(", ")
  277. builder.WriteString("tel=")
  278. builder.WriteString(w.Tel)
  279. builder.WriteString(", ")
  280. builder.WriteString("head_big=")
  281. builder.WriteString(w.HeadBig)
  282. builder.WriteString(", ")
  283. builder.WriteString("organization_id=")
  284. builder.WriteString(fmt.Sprintf("%v", w.OrganizationID))
  285. builder.WriteString(", ")
  286. builder.WriteString("agent_id=")
  287. builder.WriteString(fmt.Sprintf("%v", w.AgentID))
  288. builder.WriteByte(')')
  289. return builder.String()
  290. }
  291. // Wxes is a parsable slice of Wx.
  292. type Wxes []*Wx