usagetotal.go 6.6 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/usagetotal"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // UsageTotal is the model entity for the UsageTotal schema.
  12. type UsageTotal 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. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  21. Status uint8 `json:"status,omitempty"`
  22. // 1 微信 2 名片
  23. Type int `json:"type,omitempty"`
  24. // 微信或名片id
  25. BotID string `json:"bot_id,omitempty"`
  26. // 使用token总数
  27. TotalTokens uint64 `json:"total_tokens,omitempty"`
  28. // 重制后的起始usage_detail 索引
  29. StartIndex uint64 `json:"start_index,omitempty"`
  30. // usage_detail 索引
  31. EndIndex uint64 `json:"end_index,omitempty"`
  32. // 机构 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 (*UsageTotal) scanValues(columns []string) ([]any, error) {
  38. values := make([]any, len(columns))
  39. for i := range columns {
  40. switch columns[i] {
  41. case usagetotal.FieldID, usagetotal.FieldStatus, usagetotal.FieldType, usagetotal.FieldTotalTokens, usagetotal.FieldStartIndex, usagetotal.FieldEndIndex, usagetotal.FieldOrganizationID:
  42. values[i] = new(sql.NullInt64)
  43. case usagetotal.FieldBotID:
  44. values[i] = new(sql.NullString)
  45. case usagetotal.FieldCreatedAt, usagetotal.FieldUpdatedAt:
  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 UsageTotal fields.
  55. func (ut *UsageTotal) 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 usagetotal.FieldID:
  62. value, ok := values[i].(*sql.NullInt64)
  63. if !ok {
  64. return fmt.Errorf("unexpected type %T for field id", value)
  65. }
  66. ut.ID = uint64(value.Int64)
  67. case usagetotal.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. ut.CreatedAt = value.Time
  72. }
  73. case usagetotal.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. ut.UpdatedAt = value.Time
  78. }
  79. case usagetotal.FieldStatus:
  80. if value, ok := values[i].(*sql.NullInt64); !ok {
  81. return fmt.Errorf("unexpected type %T for field status", values[i])
  82. } else if value.Valid {
  83. ut.Status = uint8(value.Int64)
  84. }
  85. case usagetotal.FieldType:
  86. if value, ok := values[i].(*sql.NullInt64); !ok {
  87. return fmt.Errorf("unexpected type %T for field type", values[i])
  88. } else if value.Valid {
  89. ut.Type = int(value.Int64)
  90. }
  91. case usagetotal.FieldBotID:
  92. if value, ok := values[i].(*sql.NullString); !ok {
  93. return fmt.Errorf("unexpected type %T for field bot_id", values[i])
  94. } else if value.Valid {
  95. ut.BotID = value.String
  96. }
  97. case usagetotal.FieldTotalTokens:
  98. if value, ok := values[i].(*sql.NullInt64); !ok {
  99. return fmt.Errorf("unexpected type %T for field total_tokens", values[i])
  100. } else if value.Valid {
  101. ut.TotalTokens = uint64(value.Int64)
  102. }
  103. case usagetotal.FieldStartIndex:
  104. if value, ok := values[i].(*sql.NullInt64); !ok {
  105. return fmt.Errorf("unexpected type %T for field start_index", values[i])
  106. } else if value.Valid {
  107. ut.StartIndex = uint64(value.Int64)
  108. }
  109. case usagetotal.FieldEndIndex:
  110. if value, ok := values[i].(*sql.NullInt64); !ok {
  111. return fmt.Errorf("unexpected type %T for field end_index", values[i])
  112. } else if value.Valid {
  113. ut.EndIndex = uint64(value.Int64)
  114. }
  115. case usagetotal.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. ut.OrganizationID = uint64(value.Int64)
  120. }
  121. default:
  122. ut.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 UsageTotal.
  128. // This includes values selected through modifiers, order, etc.
  129. func (ut *UsageTotal) Value(name string) (ent.Value, error) {
  130. return ut.selectValues.Get(name)
  131. }
  132. // Update returns a builder for updating this UsageTotal.
  133. // Note that you need to call UsageTotal.Unwrap() before calling this method if this UsageTotal
  134. // was returned from a transaction, and the transaction was committed or rolled back.
  135. func (ut *UsageTotal) Update() *UsageTotalUpdateOne {
  136. return NewUsageTotalClient(ut.config).UpdateOne(ut)
  137. }
  138. // Unwrap unwraps the UsageTotal 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 (ut *UsageTotal) Unwrap() *UsageTotal {
  141. _tx, ok := ut.config.driver.(*txDriver)
  142. if !ok {
  143. panic("ent: UsageTotal is not a transactional entity")
  144. }
  145. ut.config.driver = _tx.drv
  146. return ut
  147. }
  148. // String implements the fmt.Stringer.
  149. func (ut *UsageTotal) String() string {
  150. var builder strings.Builder
  151. builder.WriteString("UsageTotal(")
  152. builder.WriteString(fmt.Sprintf("id=%v, ", ut.ID))
  153. builder.WriteString("created_at=")
  154. builder.WriteString(ut.CreatedAt.Format(time.ANSIC))
  155. builder.WriteString(", ")
  156. builder.WriteString("updated_at=")
  157. builder.WriteString(ut.UpdatedAt.Format(time.ANSIC))
  158. builder.WriteString(", ")
  159. builder.WriteString("status=")
  160. builder.WriteString(fmt.Sprintf("%v", ut.Status))
  161. builder.WriteString(", ")
  162. builder.WriteString("type=")
  163. builder.WriteString(fmt.Sprintf("%v", ut.Type))
  164. builder.WriteString(", ")
  165. builder.WriteString("bot_id=")
  166. builder.WriteString(ut.BotID)
  167. builder.WriteString(", ")
  168. builder.WriteString("total_tokens=")
  169. builder.WriteString(fmt.Sprintf("%v", ut.TotalTokens))
  170. builder.WriteString(", ")
  171. builder.WriteString("start_index=")
  172. builder.WriteString(fmt.Sprintf("%v", ut.StartIndex))
  173. builder.WriteString(", ")
  174. builder.WriteString("end_index=")
  175. builder.WriteString(fmt.Sprintf("%v", ut.EndIndex))
  176. builder.WriteString(", ")
  177. builder.WriteString("organization_id=")
  178. builder.WriteString(fmt.Sprintf("%v", ut.OrganizationID))
  179. builder.WriteByte(')')
  180. return builder.String()
  181. }
  182. // UsageTotals is a parsable slice of UsageTotal.
  183. type UsageTotals []*UsageTotal