agent.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // Agent is the model entity for the Agent schema.
  12. type Agent struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID uint64 `json:"id,omitempty"`
  16. // Create Time | 创建日期
  17. CreatedAt time.Time `json:"created_at,omitempty"`
  18. // Update Time | 修改日期
  19. UpdatedAt time.Time `json:"updated_at,omitempty"`
  20. // Delete Time | 删除日期
  21. DeletedAt time.Time `json:"deleted_at,omitempty"`
  22. // name | 角色名称
  23. Name string `json:"name,omitempty"`
  24. // role | 角色设定
  25. Role string `json:"role,omitempty"`
  26. // status | 状态 1-正常 2-禁用
  27. Status int `json:"status,omitempty"`
  28. // background | 背景介绍
  29. Background string `json:"background,omitempty"`
  30. // examples | 对话案例
  31. Examples string `json:"examples,omitempty"`
  32. // organization_id | 租户ID
  33. OrganizationID uint64 `json:"organization_id,omitempty"`
  34. selectValues sql.SelectValues
  35. }
  36. // scanValues returns the types for scanning values from sql.Rows.
  37. func (*Agent) scanValues(columns []string) ([]any, error) {
  38. values := make([]any, len(columns))
  39. for i := range columns {
  40. switch columns[i] {
  41. case agent.FieldID, agent.FieldStatus, agent.FieldOrganizationID:
  42. values[i] = new(sql.NullInt64)
  43. case agent.FieldName, agent.FieldRole, agent.FieldBackground, agent.FieldExamples:
  44. values[i] = new(sql.NullString)
  45. case agent.FieldCreatedAt, agent.FieldUpdatedAt, agent.FieldDeletedAt:
  46. values[i] = new(sql.NullTime)
  47. default:
  48. values[i] = new(sql.UnknownType)
  49. }
  50. }
  51. return values, nil
  52. }
  53. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  54. // to the Agent fields.
  55. func (a *Agent) assignValues(columns []string, values []any) error {
  56. if m, n := len(values), len(columns); m < n {
  57. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  58. }
  59. for i := range columns {
  60. switch columns[i] {
  61. case agent.FieldID:
  62. value, ok := values[i].(*sql.NullInt64)
  63. if !ok {
  64. return fmt.Errorf("unexpected type %T for field id", value)
  65. }
  66. a.ID = uint64(value.Int64)
  67. case agent.FieldCreatedAt:
  68. if value, ok := values[i].(*sql.NullTime); !ok {
  69. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  70. } else if value.Valid {
  71. a.CreatedAt = value.Time
  72. }
  73. case agent.FieldUpdatedAt:
  74. if value, ok := values[i].(*sql.NullTime); !ok {
  75. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  76. } else if value.Valid {
  77. a.UpdatedAt = value.Time
  78. }
  79. case agent.FieldDeletedAt:
  80. if value, ok := values[i].(*sql.NullTime); !ok {
  81. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  82. } else if value.Valid {
  83. a.DeletedAt = value.Time
  84. }
  85. case agent.FieldName:
  86. if value, ok := values[i].(*sql.NullString); !ok {
  87. return fmt.Errorf("unexpected type %T for field name", values[i])
  88. } else if value.Valid {
  89. a.Name = value.String
  90. }
  91. case agent.FieldRole:
  92. if value, ok := values[i].(*sql.NullString); !ok {
  93. return fmt.Errorf("unexpected type %T for field role", values[i])
  94. } else if value.Valid {
  95. a.Role = value.String
  96. }
  97. case agent.FieldStatus:
  98. if value, ok := values[i].(*sql.NullInt64); !ok {
  99. return fmt.Errorf("unexpected type %T for field status", values[i])
  100. } else if value.Valid {
  101. a.Status = int(value.Int64)
  102. }
  103. case agent.FieldBackground:
  104. if value, ok := values[i].(*sql.NullString); !ok {
  105. return fmt.Errorf("unexpected type %T for field background", values[i])
  106. } else if value.Valid {
  107. a.Background = value.String
  108. }
  109. case agent.FieldExamples:
  110. if value, ok := values[i].(*sql.NullString); !ok {
  111. return fmt.Errorf("unexpected type %T for field examples", values[i])
  112. } else if value.Valid {
  113. a.Examples = value.String
  114. }
  115. case agent.FieldOrganizationID:
  116. if value, ok := values[i].(*sql.NullInt64); !ok {
  117. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  118. } else if value.Valid {
  119. a.OrganizationID = uint64(value.Int64)
  120. }
  121. default:
  122. a.selectValues.Set(columns[i], values[i])
  123. }
  124. }
  125. return nil
  126. }
  127. // Value returns the ent.Value that was dynamically selected and assigned to the Agent.
  128. // This includes values selected through modifiers, order, etc.
  129. func (a *Agent) Value(name string) (ent.Value, error) {
  130. return a.selectValues.Get(name)
  131. }
  132. // Update returns a builder for updating this Agent.
  133. // Note that you need to call Agent.Unwrap() before calling this method if this Agent
  134. // was returned from a transaction, and the transaction was committed or rolled back.
  135. func (a *Agent) Update() *AgentUpdateOne {
  136. return NewAgentClient(a.config).UpdateOne(a)
  137. }
  138. // Unwrap unwraps the Agent entity that was returned from a transaction after it was closed,
  139. // so that all future queries will be executed through the driver which created the transaction.
  140. func (a *Agent) Unwrap() *Agent {
  141. _tx, ok := a.config.driver.(*txDriver)
  142. if !ok {
  143. panic("ent: Agent is not a transactional entity")
  144. }
  145. a.config.driver = _tx.drv
  146. return a
  147. }
  148. // String implements the fmt.Stringer.
  149. func (a *Agent) String() string {
  150. var builder strings.Builder
  151. builder.WriteString("Agent(")
  152. builder.WriteString(fmt.Sprintf("id=%v, ", a.ID))
  153. builder.WriteString("created_at=")
  154. builder.WriteString(a.CreatedAt.Format(time.ANSIC))
  155. builder.WriteString(", ")
  156. builder.WriteString("updated_at=")
  157. builder.WriteString(a.UpdatedAt.Format(time.ANSIC))
  158. builder.WriteString(", ")
  159. builder.WriteString("deleted_at=")
  160. builder.WriteString(a.DeletedAt.Format(time.ANSIC))
  161. builder.WriteString(", ")
  162. builder.WriteString("name=")
  163. builder.WriteString(a.Name)
  164. builder.WriteString(", ")
  165. builder.WriteString("role=")
  166. builder.WriteString(a.Role)
  167. builder.WriteString(", ")
  168. builder.WriteString("status=")
  169. builder.WriteString(fmt.Sprintf("%v", a.Status))
  170. builder.WriteString(", ")
  171. builder.WriteString("background=")
  172. builder.WriteString(a.Background)
  173. builder.WriteString(", ")
  174. builder.WriteString("examples=")
  175. builder.WriteString(a.Examples)
  176. builder.WriteString(", ")
  177. builder.WriteString("organization_id=")
  178. builder.WriteString(fmt.Sprintf("%v", a.OrganizationID))
  179. builder.WriteByte(')')
  180. return builder.String()
  181. }
  182. // Agents is a parsable slice of Agent.
  183. type Agents []*Agent