usagetotal.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. // 使用积分总数
  29. Credits float64 `json:"credits,omitempty"`
  30. // 重制后的起始usage_detail 索引
  31. StartIndex uint64 `json:"start_index,omitempty"`
  32. // usage_detail 索引
  33. EndIndex uint64 `json:"end_index,omitempty"`
  34. // 机构 ID
  35. OrganizationID uint64 `json:"organization_id,omitempty"`
  36. selectValues sql.SelectValues
  37. }
  38. // scanValues returns the types for scanning values from sql.Rows.
  39. func (*UsageTotal) scanValues(columns []string) ([]any, error) {
  40. values := make([]any, len(columns))
  41. for i := range columns {
  42. switch columns[i] {
  43. case usagetotal.FieldCredits:
  44. values[i] = new(sql.NullFloat64)
  45. case usagetotal.FieldID, usagetotal.FieldStatus, usagetotal.FieldType, usagetotal.FieldTotalTokens, usagetotal.FieldStartIndex, usagetotal.FieldEndIndex, usagetotal.FieldOrganizationID:
  46. values[i] = new(sql.NullInt64)
  47. case usagetotal.FieldBotID:
  48. values[i] = new(sql.NullString)
  49. case usagetotal.FieldCreatedAt, usagetotal.FieldUpdatedAt:
  50. values[i] = new(sql.NullTime)
  51. default:
  52. values[i] = new(sql.UnknownType)
  53. }
  54. }
  55. return values, nil
  56. }
  57. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  58. // to the UsageTotal fields.
  59. func (ut *UsageTotal) assignValues(columns []string, values []any) error {
  60. if m, n := len(values), len(columns); m < n {
  61. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  62. }
  63. for i := range columns {
  64. switch columns[i] {
  65. case usagetotal.FieldID:
  66. value, ok := values[i].(*sql.NullInt64)
  67. if !ok {
  68. return fmt.Errorf("unexpected type %T for field id", value)
  69. }
  70. ut.ID = uint64(value.Int64)
  71. case usagetotal.FieldCreatedAt:
  72. if value, ok := values[i].(*sql.NullTime); !ok {
  73. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  74. } else if value.Valid {
  75. ut.CreatedAt = value.Time
  76. }
  77. case usagetotal.FieldUpdatedAt:
  78. if value, ok := values[i].(*sql.NullTime); !ok {
  79. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  80. } else if value.Valid {
  81. ut.UpdatedAt = value.Time
  82. }
  83. case usagetotal.FieldStatus:
  84. if value, ok := values[i].(*sql.NullInt64); !ok {
  85. return fmt.Errorf("unexpected type %T for field status", values[i])
  86. } else if value.Valid {
  87. ut.Status = uint8(value.Int64)
  88. }
  89. case usagetotal.FieldType:
  90. if value, ok := values[i].(*sql.NullInt64); !ok {
  91. return fmt.Errorf("unexpected type %T for field type", values[i])
  92. } else if value.Valid {
  93. ut.Type = int(value.Int64)
  94. }
  95. case usagetotal.FieldBotID:
  96. if value, ok := values[i].(*sql.NullString); !ok {
  97. return fmt.Errorf("unexpected type %T for field bot_id", values[i])
  98. } else if value.Valid {
  99. ut.BotID = value.String
  100. }
  101. case usagetotal.FieldTotalTokens:
  102. if value, ok := values[i].(*sql.NullInt64); !ok {
  103. return fmt.Errorf("unexpected type %T for field total_tokens", values[i])
  104. } else if value.Valid {
  105. ut.TotalTokens = uint64(value.Int64)
  106. }
  107. case usagetotal.FieldCredits:
  108. if value, ok := values[i].(*sql.NullFloat64); !ok {
  109. return fmt.Errorf("unexpected type %T for field credits", values[i])
  110. } else if value.Valid {
  111. ut.Credits = value.Float64
  112. }
  113. case usagetotal.FieldStartIndex:
  114. if value, ok := values[i].(*sql.NullInt64); !ok {
  115. return fmt.Errorf("unexpected type %T for field start_index", values[i])
  116. } else if value.Valid {
  117. ut.StartIndex = uint64(value.Int64)
  118. }
  119. case usagetotal.FieldEndIndex:
  120. if value, ok := values[i].(*sql.NullInt64); !ok {
  121. return fmt.Errorf("unexpected type %T for field end_index", values[i])
  122. } else if value.Valid {
  123. ut.EndIndex = uint64(value.Int64)
  124. }
  125. case usagetotal.FieldOrganizationID:
  126. if value, ok := values[i].(*sql.NullInt64); !ok {
  127. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  128. } else if value.Valid {
  129. ut.OrganizationID = uint64(value.Int64)
  130. }
  131. default:
  132. ut.selectValues.Set(columns[i], values[i])
  133. }
  134. }
  135. return nil
  136. }
  137. // Value returns the ent.Value that was dynamically selected and assigned to the UsageTotal.
  138. // This includes values selected through modifiers, order, etc.
  139. func (ut *UsageTotal) Value(name string) (ent.Value, error) {
  140. return ut.selectValues.Get(name)
  141. }
  142. // Update returns a builder for updating this UsageTotal.
  143. // Note that you need to call UsageTotal.Unwrap() before calling this method if this UsageTotal
  144. // was returned from a transaction, and the transaction was committed or rolled back.
  145. func (ut *UsageTotal) Update() *UsageTotalUpdateOne {
  146. return NewUsageTotalClient(ut.config).UpdateOne(ut)
  147. }
  148. // Unwrap unwraps the UsageTotal entity that was returned from a transaction after it was closed,
  149. // so that all future queries will be executed through the driver which created the transaction.
  150. func (ut *UsageTotal) Unwrap() *UsageTotal {
  151. _tx, ok := ut.config.driver.(*txDriver)
  152. if !ok {
  153. panic("ent: UsageTotal is not a transactional entity")
  154. }
  155. ut.config.driver = _tx.drv
  156. return ut
  157. }
  158. // String implements the fmt.Stringer.
  159. func (ut *UsageTotal) String() string {
  160. var builder strings.Builder
  161. builder.WriteString("UsageTotal(")
  162. builder.WriteString(fmt.Sprintf("id=%v, ", ut.ID))
  163. builder.WriteString("created_at=")
  164. builder.WriteString(ut.CreatedAt.Format(time.ANSIC))
  165. builder.WriteString(", ")
  166. builder.WriteString("updated_at=")
  167. builder.WriteString(ut.UpdatedAt.Format(time.ANSIC))
  168. builder.WriteString(", ")
  169. builder.WriteString("status=")
  170. builder.WriteString(fmt.Sprintf("%v", ut.Status))
  171. builder.WriteString(", ")
  172. builder.WriteString("type=")
  173. builder.WriteString(fmt.Sprintf("%v", ut.Type))
  174. builder.WriteString(", ")
  175. builder.WriteString("bot_id=")
  176. builder.WriteString(ut.BotID)
  177. builder.WriteString(", ")
  178. builder.WriteString("total_tokens=")
  179. builder.WriteString(fmt.Sprintf("%v", ut.TotalTokens))
  180. builder.WriteString(", ")
  181. builder.WriteString("credits=")
  182. builder.WriteString(fmt.Sprintf("%v", ut.Credits))
  183. builder.WriteString(", ")
  184. builder.WriteString("start_index=")
  185. builder.WriteString(fmt.Sprintf("%v", ut.StartIndex))
  186. builder.WriteString(", ")
  187. builder.WriteString("end_index=")
  188. builder.WriteString(fmt.Sprintf("%v", ut.EndIndex))
  189. builder.WriteString(", ")
  190. builder.WriteString("organization_id=")
  191. builder.WriteString(fmt.Sprintf("%v", ut.OrganizationID))
  192. builder.WriteByte(')')
  193. return builder.String()
  194. }
  195. // UsageTotals is a parsable slice of UsageTotal.
  196. type UsageTotals []*UsageTotal