apikey.go 8.2 KB

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