token.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/token"
  9. "entgo.io/ent"
  10. "entgo.io/ent/dialect/sql"
  11. )
  12. // Token is the model entity for the Token schema.
  13. type Token struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID uint64 `json:"id,omitempty"`
  17. // Create Time | 创建日期
  18. CreatedAt time.Time `json:"created_at,omitempty"`
  19. // Update Time | 修改日期
  20. UpdatedAt time.Time `json:"updated_at,omitempty"`
  21. // Delete Time | 删除日期
  22. DeletedAt time.Time `json:"deleted_at,omitempty"`
  23. // 过期时间
  24. ExpireAt time.Time `json:"expire_at,omitempty"`
  25. // Token
  26. Token string `json:"token,omitempty"`
  27. // Mac地址
  28. MAC string `json:"mac,omitempty"`
  29. // 租户ID
  30. OrganizationID uint64 `json:"organization_id,omitempty"`
  31. // 智能体ID
  32. AgentID uint64 `json:"agent_id,omitempty"`
  33. // 定制agent服务地址
  34. CustomAgentBase string `json:"custom_agent_base,omitempty"`
  35. // 定制agent服务密钥
  36. CustomAgentKey string `json:"custom_agent_key,omitempty"`
  37. // 大模型服务地址
  38. OpenaiBase string `json:"openai_base,omitempty"`
  39. // 大模型服务密钥
  40. OpenaiKey string `json:"openai_key,omitempty"`
  41. // Edges holds the relations/edges for other nodes in the graph.
  42. // The values are being populated by the TokenQuery when eager-loading is set.
  43. Edges TokenEdges `json:"edges"`
  44. selectValues sql.SelectValues
  45. }
  46. // TokenEdges holds the relations/edges for other nodes in the graph.
  47. type TokenEdges struct {
  48. // Agent holds the value of the agent edge.
  49. Agent *Agent `json:"agent,omitempty"`
  50. // loadedTypes holds the information for reporting if a
  51. // type was loaded (or requested) in eager-loading or not.
  52. loadedTypes [1]bool
  53. }
  54. // AgentOrErr returns the Agent value or an error if the edge
  55. // was not loaded in eager-loading, or loaded but was not found.
  56. func (e TokenEdges) AgentOrErr() (*Agent, error) {
  57. if e.Agent != nil {
  58. return e.Agent, nil
  59. } else if e.loadedTypes[0] {
  60. return nil, &NotFoundError{label: agent.Label}
  61. }
  62. return nil, &NotLoadedError{edge: "agent"}
  63. }
  64. // scanValues returns the types for scanning values from sql.Rows.
  65. func (*Token) scanValues(columns []string) ([]any, error) {
  66. values := make([]any, len(columns))
  67. for i := range columns {
  68. switch columns[i] {
  69. case token.FieldID, token.FieldOrganizationID, token.FieldAgentID:
  70. values[i] = new(sql.NullInt64)
  71. case token.FieldToken, token.FieldMAC, token.FieldCustomAgentBase, token.FieldCustomAgentKey, token.FieldOpenaiBase, token.FieldOpenaiKey:
  72. values[i] = new(sql.NullString)
  73. case token.FieldCreatedAt, token.FieldUpdatedAt, token.FieldDeletedAt, token.FieldExpireAt:
  74. values[i] = new(sql.NullTime)
  75. default:
  76. values[i] = new(sql.UnknownType)
  77. }
  78. }
  79. return values, nil
  80. }
  81. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  82. // to the Token fields.
  83. func (t *Token) assignValues(columns []string, values []any) error {
  84. if m, n := len(values), len(columns); m < n {
  85. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  86. }
  87. for i := range columns {
  88. switch columns[i] {
  89. case token.FieldID:
  90. value, ok := values[i].(*sql.NullInt64)
  91. if !ok {
  92. return fmt.Errorf("unexpected type %T for field id", value)
  93. }
  94. t.ID = uint64(value.Int64)
  95. case token.FieldCreatedAt:
  96. if value, ok := values[i].(*sql.NullTime); !ok {
  97. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  98. } else if value.Valid {
  99. t.CreatedAt = value.Time
  100. }
  101. case token.FieldUpdatedAt:
  102. if value, ok := values[i].(*sql.NullTime); !ok {
  103. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  104. } else if value.Valid {
  105. t.UpdatedAt = value.Time
  106. }
  107. case token.FieldDeletedAt:
  108. if value, ok := values[i].(*sql.NullTime); !ok {
  109. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  110. } else if value.Valid {
  111. t.DeletedAt = value.Time
  112. }
  113. case token.FieldExpireAt:
  114. if value, ok := values[i].(*sql.NullTime); !ok {
  115. return fmt.Errorf("unexpected type %T for field expire_at", values[i])
  116. } else if value.Valid {
  117. t.ExpireAt = value.Time
  118. }
  119. case token.FieldToken:
  120. if value, ok := values[i].(*sql.NullString); !ok {
  121. return fmt.Errorf("unexpected type %T for field token", values[i])
  122. } else if value.Valid {
  123. t.Token = value.String
  124. }
  125. case token.FieldMAC:
  126. if value, ok := values[i].(*sql.NullString); !ok {
  127. return fmt.Errorf("unexpected type %T for field mac", values[i])
  128. } else if value.Valid {
  129. t.MAC = value.String
  130. }
  131. case token.FieldOrganizationID:
  132. if value, ok := values[i].(*sql.NullInt64); !ok {
  133. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  134. } else if value.Valid {
  135. t.OrganizationID = uint64(value.Int64)
  136. }
  137. case token.FieldAgentID:
  138. if value, ok := values[i].(*sql.NullInt64); !ok {
  139. return fmt.Errorf("unexpected type %T for field agent_id", values[i])
  140. } else if value.Valid {
  141. t.AgentID = uint64(value.Int64)
  142. }
  143. case token.FieldCustomAgentBase:
  144. if value, ok := values[i].(*sql.NullString); !ok {
  145. return fmt.Errorf("unexpected type %T for field custom_agent_base", values[i])
  146. } else if value.Valid {
  147. t.CustomAgentBase = value.String
  148. }
  149. case token.FieldCustomAgentKey:
  150. if value, ok := values[i].(*sql.NullString); !ok {
  151. return fmt.Errorf("unexpected type %T for field custom_agent_key", values[i])
  152. } else if value.Valid {
  153. t.CustomAgentKey = value.String
  154. }
  155. case token.FieldOpenaiBase:
  156. if value, ok := values[i].(*sql.NullString); !ok {
  157. return fmt.Errorf("unexpected type %T for field openai_base", values[i])
  158. } else if value.Valid {
  159. t.OpenaiBase = value.String
  160. }
  161. case token.FieldOpenaiKey:
  162. if value, ok := values[i].(*sql.NullString); !ok {
  163. return fmt.Errorf("unexpected type %T for field openai_key", values[i])
  164. } else if value.Valid {
  165. t.OpenaiKey = value.String
  166. }
  167. default:
  168. t.selectValues.Set(columns[i], values[i])
  169. }
  170. }
  171. return nil
  172. }
  173. // Value returns the ent.Value that was dynamically selected and assigned to the Token.
  174. // This includes values selected through modifiers, order, etc.
  175. func (t *Token) Value(name string) (ent.Value, error) {
  176. return t.selectValues.Get(name)
  177. }
  178. // QueryAgent queries the "agent" edge of the Token entity.
  179. func (t *Token) QueryAgent() *AgentQuery {
  180. return NewTokenClient(t.config).QueryAgent(t)
  181. }
  182. // Update returns a builder for updating this Token.
  183. // Note that you need to call Token.Unwrap() before calling this method if this Token
  184. // was returned from a transaction, and the transaction was committed or rolled back.
  185. func (t *Token) Update() *TokenUpdateOne {
  186. return NewTokenClient(t.config).UpdateOne(t)
  187. }
  188. // Unwrap unwraps the Token entity that was returned from a transaction after it was closed,
  189. // so that all future queries will be executed through the driver which created the transaction.
  190. func (t *Token) Unwrap() *Token {
  191. _tx, ok := t.config.driver.(*txDriver)
  192. if !ok {
  193. panic("ent: Token is not a transactional entity")
  194. }
  195. t.config.driver = _tx.drv
  196. return t
  197. }
  198. // String implements the fmt.Stringer.
  199. func (t *Token) String() string {
  200. var builder strings.Builder
  201. builder.WriteString("Token(")
  202. builder.WriteString(fmt.Sprintf("id=%v, ", t.ID))
  203. builder.WriteString("created_at=")
  204. builder.WriteString(t.CreatedAt.Format(time.ANSIC))
  205. builder.WriteString(", ")
  206. builder.WriteString("updated_at=")
  207. builder.WriteString(t.UpdatedAt.Format(time.ANSIC))
  208. builder.WriteString(", ")
  209. builder.WriteString("deleted_at=")
  210. builder.WriteString(t.DeletedAt.Format(time.ANSIC))
  211. builder.WriteString(", ")
  212. builder.WriteString("expire_at=")
  213. builder.WriteString(t.ExpireAt.Format(time.ANSIC))
  214. builder.WriteString(", ")
  215. builder.WriteString("token=")
  216. builder.WriteString(t.Token)
  217. builder.WriteString(", ")
  218. builder.WriteString("mac=")
  219. builder.WriteString(t.MAC)
  220. builder.WriteString(", ")
  221. builder.WriteString("organization_id=")
  222. builder.WriteString(fmt.Sprintf("%v", t.OrganizationID))
  223. builder.WriteString(", ")
  224. builder.WriteString("agent_id=")
  225. builder.WriteString(fmt.Sprintf("%v", t.AgentID))
  226. builder.WriteString(", ")
  227. builder.WriteString("custom_agent_base=")
  228. builder.WriteString(t.CustomAgentBase)
  229. builder.WriteString(", ")
  230. builder.WriteString("custom_agent_key=")
  231. builder.WriteString(t.CustomAgentKey)
  232. builder.WriteString(", ")
  233. builder.WriteString("openai_base=")
  234. builder.WriteString(t.OpenaiBase)
  235. builder.WriteString(", ")
  236. builder.WriteString("openai_key=")
  237. builder.WriteString(t.OpenaiKey)
  238. builder.WriteByte(')')
  239. return builder.String()
  240. }
  241. // Tokens is a parsable slice of Token.
  242. type Tokens []*Token