agentbase.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "wechat-api/ent/agentbase"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // AgentBase is the model entity for the AgentBase schema.
  12. type AgentBase struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. // id
  16. ID string `json:"id,omitempty"`
  17. // q
  18. Q string `json:"q,omitempty"`
  19. // a
  20. A string `json:"a,omitempty"`
  21. // chunk_index
  22. ChunkIndex uint64 `json:"chunk_index,omitempty"`
  23. // indexes
  24. Indexes []string `json:"indexes,omitempty"`
  25. // dataset_id
  26. DatasetID string `json:"dataset_id,omitempty"`
  27. // collection_id
  28. CollectionID string `json:"collection_id,omitempty"`
  29. // source_name
  30. SourceName string `json:"source_name,omitempty"`
  31. // can_write
  32. CanWrite []bool `json:"can_write,omitempty"`
  33. // is_owner
  34. IsOwner []bool `json:"is_owner,omitempty"`
  35. // Edges holds the relations/edges for other nodes in the graph.
  36. // The values are being populated by the AgentBaseQuery when eager-loading is set.
  37. Edges AgentBaseEdges `json:"edges"`
  38. selectValues sql.SelectValues
  39. }
  40. // AgentBaseEdges holds the relations/edges for other nodes in the graph.
  41. type AgentBaseEdges struct {
  42. // WxAgent holds the value of the wx_agent edge.
  43. WxAgent []*Wx `json:"wx_agent,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. // WxAgentOrErr returns the WxAgent value or an error if the edge
  49. // was not loaded in eager-loading.
  50. func (e AgentBaseEdges) WxAgentOrErr() ([]*Wx, error) {
  51. if e.loadedTypes[0] {
  52. return e.WxAgent, nil
  53. }
  54. return nil, &NotLoadedError{edge: "wx_agent"}
  55. }
  56. // scanValues returns the types for scanning values from sql.Rows.
  57. func (*AgentBase) scanValues(columns []string) ([]any, error) {
  58. values := make([]any, len(columns))
  59. for i := range columns {
  60. switch columns[i] {
  61. case agentbase.FieldIndexes, agentbase.FieldCanWrite, agentbase.FieldIsOwner:
  62. values[i] = new([]byte)
  63. case agentbase.FieldChunkIndex:
  64. values[i] = new(sql.NullInt64)
  65. case agentbase.FieldID, agentbase.FieldQ, agentbase.FieldA, agentbase.FieldDatasetID, agentbase.FieldCollectionID, agentbase.FieldSourceName:
  66. values[i] = new(sql.NullString)
  67. default:
  68. values[i] = new(sql.UnknownType)
  69. }
  70. }
  71. return values, nil
  72. }
  73. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  74. // to the AgentBase fields.
  75. func (ab *AgentBase) assignValues(columns []string, values []any) error {
  76. if m, n := len(values), len(columns); m < n {
  77. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  78. }
  79. for i := range columns {
  80. switch columns[i] {
  81. case agentbase.FieldID:
  82. if value, ok := values[i].(*sql.NullString); !ok {
  83. return fmt.Errorf("unexpected type %T for field id", values[i])
  84. } else if value.Valid {
  85. ab.ID = value.String
  86. }
  87. case agentbase.FieldQ:
  88. if value, ok := values[i].(*sql.NullString); !ok {
  89. return fmt.Errorf("unexpected type %T for field q", values[i])
  90. } else if value.Valid {
  91. ab.Q = value.String
  92. }
  93. case agentbase.FieldA:
  94. if value, ok := values[i].(*sql.NullString); !ok {
  95. return fmt.Errorf("unexpected type %T for field a", values[i])
  96. } else if value.Valid {
  97. ab.A = value.String
  98. }
  99. case agentbase.FieldChunkIndex:
  100. if value, ok := values[i].(*sql.NullInt64); !ok {
  101. return fmt.Errorf("unexpected type %T for field chunk_index", values[i])
  102. } else if value.Valid {
  103. ab.ChunkIndex = uint64(value.Int64)
  104. }
  105. case agentbase.FieldIndexes:
  106. if value, ok := values[i].(*[]byte); !ok {
  107. return fmt.Errorf("unexpected type %T for field indexes", values[i])
  108. } else if value != nil && len(*value) > 0 {
  109. if err := json.Unmarshal(*value, &ab.Indexes); err != nil {
  110. return fmt.Errorf("unmarshal field indexes: %w", err)
  111. }
  112. }
  113. case agentbase.FieldDatasetID:
  114. if value, ok := values[i].(*sql.NullString); !ok {
  115. return fmt.Errorf("unexpected type %T for field dataset_id", values[i])
  116. } else if value.Valid {
  117. ab.DatasetID = value.String
  118. }
  119. case agentbase.FieldCollectionID:
  120. if value, ok := values[i].(*sql.NullString); !ok {
  121. return fmt.Errorf("unexpected type %T for field collection_id", values[i])
  122. } else if value.Valid {
  123. ab.CollectionID = value.String
  124. }
  125. case agentbase.FieldSourceName:
  126. if value, ok := values[i].(*sql.NullString); !ok {
  127. return fmt.Errorf("unexpected type %T for field source_name", values[i])
  128. } else if value.Valid {
  129. ab.SourceName = value.String
  130. }
  131. case agentbase.FieldCanWrite:
  132. if value, ok := values[i].(*[]byte); !ok {
  133. return fmt.Errorf("unexpected type %T for field can_write", values[i])
  134. } else if value != nil && len(*value) > 0 {
  135. if err := json.Unmarshal(*value, &ab.CanWrite); err != nil {
  136. return fmt.Errorf("unmarshal field can_write: %w", err)
  137. }
  138. }
  139. case agentbase.FieldIsOwner:
  140. if value, ok := values[i].(*[]byte); !ok {
  141. return fmt.Errorf("unexpected type %T for field is_owner", values[i])
  142. } else if value != nil && len(*value) > 0 {
  143. if err := json.Unmarshal(*value, &ab.IsOwner); err != nil {
  144. return fmt.Errorf("unmarshal field is_owner: %w", err)
  145. }
  146. }
  147. default:
  148. ab.selectValues.Set(columns[i], values[i])
  149. }
  150. }
  151. return nil
  152. }
  153. // Value returns the ent.Value that was dynamically selected and assigned to the AgentBase.
  154. // This includes values selected through modifiers, order, etc.
  155. func (ab *AgentBase) Value(name string) (ent.Value, error) {
  156. return ab.selectValues.Get(name)
  157. }
  158. // QueryWxAgent queries the "wx_agent" edge of the AgentBase entity.
  159. func (ab *AgentBase) QueryWxAgent() *WxQuery {
  160. return NewAgentBaseClient(ab.config).QueryWxAgent(ab)
  161. }
  162. // Update returns a builder for updating this AgentBase.
  163. // Note that you need to call AgentBase.Unwrap() before calling this method if this AgentBase
  164. // was returned from a transaction, and the transaction was committed or rolled back.
  165. func (ab *AgentBase) Update() *AgentBaseUpdateOne {
  166. return NewAgentBaseClient(ab.config).UpdateOne(ab)
  167. }
  168. // Unwrap unwraps the AgentBase entity that was returned from a transaction after it was closed,
  169. // so that all future queries will be executed through the driver which created the transaction.
  170. func (ab *AgentBase) Unwrap() *AgentBase {
  171. _tx, ok := ab.config.driver.(*txDriver)
  172. if !ok {
  173. panic("ent: AgentBase is not a transactional entity")
  174. }
  175. ab.config.driver = _tx.drv
  176. return ab
  177. }
  178. // String implements the fmt.Stringer.
  179. func (ab *AgentBase) String() string {
  180. var builder strings.Builder
  181. builder.WriteString("AgentBase(")
  182. builder.WriteString(fmt.Sprintf("id=%v, ", ab.ID))
  183. builder.WriteString("q=")
  184. builder.WriteString(ab.Q)
  185. builder.WriteString(", ")
  186. builder.WriteString("a=")
  187. builder.WriteString(ab.A)
  188. builder.WriteString(", ")
  189. builder.WriteString("chunk_index=")
  190. builder.WriteString(fmt.Sprintf("%v", ab.ChunkIndex))
  191. builder.WriteString(", ")
  192. builder.WriteString("indexes=")
  193. builder.WriteString(fmt.Sprintf("%v", ab.Indexes))
  194. builder.WriteString(", ")
  195. builder.WriteString("dataset_id=")
  196. builder.WriteString(ab.DatasetID)
  197. builder.WriteString(", ")
  198. builder.WriteString("collection_id=")
  199. builder.WriteString(ab.CollectionID)
  200. builder.WriteString(", ")
  201. builder.WriteString("source_name=")
  202. builder.WriteString(ab.SourceName)
  203. builder.WriteString(", ")
  204. builder.WriteString("can_write=")
  205. builder.WriteString(fmt.Sprintf("%v", ab.CanWrite))
  206. builder.WriteString(", ")
  207. builder.WriteString("is_owner=")
  208. builder.WriteString(fmt.Sprintf("%v", ab.IsOwner))
  209. builder.WriteByte(')')
  210. return builder.String()
  211. }
  212. // AgentBases is a parsable slice of AgentBase.
  213. type AgentBases []*AgentBase