userplatformquota.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "entgo.io/ent"
  8. "entgo.io/ent/dialect/sql"
  9. "github.com/Wei-Shaw/sub2api/ent/user"
  10. "github.com/Wei-Shaw/sub2api/ent/userplatformquota"
  11. )
  12. // UserPlatformQuota is the model entity for the UserPlatformQuota schema.
  13. type UserPlatformQuota struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID int64 `json:"id,omitempty"`
  17. // CreatedAt holds the value of the "created_at" field.
  18. CreatedAt time.Time `json:"created_at,omitempty"`
  19. // UpdatedAt holds the value of the "updated_at" field.
  20. UpdatedAt time.Time `json:"updated_at,omitempty"`
  21. // DeletedAt holds the value of the "deleted_at" field.
  22. DeletedAt *time.Time `json:"deleted_at,omitempty"`
  23. // UserID holds the value of the "user_id" field.
  24. UserID int64 `json:"user_id,omitempty"`
  25. // Platform holds the value of the "platform" field.
  26. Platform string `json:"platform,omitempty"`
  27. // DailyLimitUsd holds the value of the "daily_limit_usd" field.
  28. DailyLimitUsd *float64 `json:"daily_limit_usd,omitempty"`
  29. // WeeklyLimitUsd holds the value of the "weekly_limit_usd" field.
  30. WeeklyLimitUsd *float64 `json:"weekly_limit_usd,omitempty"`
  31. // MonthlyLimitUsd holds the value of the "monthly_limit_usd" field.
  32. MonthlyLimitUsd *float64 `json:"monthly_limit_usd,omitempty"`
  33. // DailyUsageUsd holds the value of the "daily_usage_usd" field.
  34. DailyUsageUsd float64 `json:"daily_usage_usd,omitempty"`
  35. // WeeklyUsageUsd holds the value of the "weekly_usage_usd" field.
  36. WeeklyUsageUsd float64 `json:"weekly_usage_usd,omitempty"`
  37. // MonthlyUsageUsd holds the value of the "monthly_usage_usd" field.
  38. MonthlyUsageUsd float64 `json:"monthly_usage_usd,omitempty"`
  39. // DailyWindowStart holds the value of the "daily_window_start" field.
  40. DailyWindowStart *time.Time `json:"daily_window_start,omitempty"`
  41. // WeeklyWindowStart holds the value of the "weekly_window_start" field.
  42. WeeklyWindowStart *time.Time `json:"weekly_window_start,omitempty"`
  43. // MonthlyWindowStart holds the value of the "monthly_window_start" field.
  44. MonthlyWindowStart *time.Time `json:"monthly_window_start,omitempty"`
  45. // Edges holds the relations/edges for other nodes in the graph.
  46. // The values are being populated by the UserPlatformQuotaQuery when eager-loading is set.
  47. Edges UserPlatformQuotaEdges `json:"edges"`
  48. selectValues sql.SelectValues
  49. }
  50. // UserPlatformQuotaEdges holds the relations/edges for other nodes in the graph.
  51. type UserPlatformQuotaEdges struct {
  52. // User holds the value of the user edge.
  53. User *User `json:"user,omitempty"`
  54. // loadedTypes holds the information for reporting if a
  55. // type was loaded (or requested) in eager-loading or not.
  56. loadedTypes [1]bool
  57. }
  58. // UserOrErr returns the User value or an error if the edge
  59. // was not loaded in eager-loading, or loaded but was not found.
  60. func (e UserPlatformQuotaEdges) UserOrErr() (*User, error) {
  61. if e.User != nil {
  62. return e.User, nil
  63. } else if e.loadedTypes[0] {
  64. return nil, &NotFoundError{label: user.Label}
  65. }
  66. return nil, &NotLoadedError{edge: "user"}
  67. }
  68. // scanValues returns the types for scanning values from sql.Rows.
  69. func (*UserPlatformQuota) scanValues(columns []string) ([]any, error) {
  70. values := make([]any, len(columns))
  71. for i := range columns {
  72. switch columns[i] {
  73. case userplatformquota.FieldDailyLimitUsd, userplatformquota.FieldWeeklyLimitUsd, userplatformquota.FieldMonthlyLimitUsd, userplatformquota.FieldDailyUsageUsd, userplatformquota.FieldWeeklyUsageUsd, userplatformquota.FieldMonthlyUsageUsd:
  74. values[i] = new(sql.NullFloat64)
  75. case userplatformquota.FieldID, userplatformquota.FieldUserID:
  76. values[i] = new(sql.NullInt64)
  77. case userplatformquota.FieldPlatform:
  78. values[i] = new(sql.NullString)
  79. case userplatformquota.FieldCreatedAt, userplatformquota.FieldUpdatedAt, userplatformquota.FieldDeletedAt, userplatformquota.FieldDailyWindowStart, userplatformquota.FieldWeeklyWindowStart, userplatformquota.FieldMonthlyWindowStart:
  80. values[i] = new(sql.NullTime)
  81. default:
  82. values[i] = new(sql.UnknownType)
  83. }
  84. }
  85. return values, nil
  86. }
  87. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  88. // to the UserPlatformQuota fields.
  89. func (_m *UserPlatformQuota) assignValues(columns []string, values []any) error {
  90. if m, n := len(values), len(columns); m < n {
  91. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  92. }
  93. for i := range columns {
  94. switch columns[i] {
  95. case userplatformquota.FieldID:
  96. value, ok := values[i].(*sql.NullInt64)
  97. if !ok {
  98. return fmt.Errorf("unexpected type %T for field id", value)
  99. }
  100. _m.ID = int64(value.Int64)
  101. case userplatformquota.FieldCreatedAt:
  102. if value, ok := values[i].(*sql.NullTime); !ok {
  103. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  104. } else if value.Valid {
  105. _m.CreatedAt = value.Time
  106. }
  107. case userplatformquota.FieldUpdatedAt:
  108. if value, ok := values[i].(*sql.NullTime); !ok {
  109. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  110. } else if value.Valid {
  111. _m.UpdatedAt = value.Time
  112. }
  113. case userplatformquota.FieldDeletedAt:
  114. if value, ok := values[i].(*sql.NullTime); !ok {
  115. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  116. } else if value.Valid {
  117. _m.DeletedAt = new(time.Time)
  118. *_m.DeletedAt = value.Time
  119. }
  120. case userplatformquota.FieldUserID:
  121. if value, ok := values[i].(*sql.NullInt64); !ok {
  122. return fmt.Errorf("unexpected type %T for field user_id", values[i])
  123. } else if value.Valid {
  124. _m.UserID = value.Int64
  125. }
  126. case userplatformquota.FieldPlatform:
  127. if value, ok := values[i].(*sql.NullString); !ok {
  128. return fmt.Errorf("unexpected type %T for field platform", values[i])
  129. } else if value.Valid {
  130. _m.Platform = value.String
  131. }
  132. case userplatformquota.FieldDailyLimitUsd:
  133. if value, ok := values[i].(*sql.NullFloat64); !ok {
  134. return fmt.Errorf("unexpected type %T for field daily_limit_usd", values[i])
  135. } else if value.Valid {
  136. _m.DailyLimitUsd = new(float64)
  137. *_m.DailyLimitUsd = value.Float64
  138. }
  139. case userplatformquota.FieldWeeklyLimitUsd:
  140. if value, ok := values[i].(*sql.NullFloat64); !ok {
  141. return fmt.Errorf("unexpected type %T for field weekly_limit_usd", values[i])
  142. } else if value.Valid {
  143. _m.WeeklyLimitUsd = new(float64)
  144. *_m.WeeklyLimitUsd = value.Float64
  145. }
  146. case userplatformquota.FieldMonthlyLimitUsd:
  147. if value, ok := values[i].(*sql.NullFloat64); !ok {
  148. return fmt.Errorf("unexpected type %T for field monthly_limit_usd", values[i])
  149. } else if value.Valid {
  150. _m.MonthlyLimitUsd = new(float64)
  151. *_m.MonthlyLimitUsd = value.Float64
  152. }
  153. case userplatformquota.FieldDailyUsageUsd:
  154. if value, ok := values[i].(*sql.NullFloat64); !ok {
  155. return fmt.Errorf("unexpected type %T for field daily_usage_usd", values[i])
  156. } else if value.Valid {
  157. _m.DailyUsageUsd = value.Float64
  158. }
  159. case userplatformquota.FieldWeeklyUsageUsd:
  160. if value, ok := values[i].(*sql.NullFloat64); !ok {
  161. return fmt.Errorf("unexpected type %T for field weekly_usage_usd", values[i])
  162. } else if value.Valid {
  163. _m.WeeklyUsageUsd = value.Float64
  164. }
  165. case userplatformquota.FieldMonthlyUsageUsd:
  166. if value, ok := values[i].(*sql.NullFloat64); !ok {
  167. return fmt.Errorf("unexpected type %T for field monthly_usage_usd", values[i])
  168. } else if value.Valid {
  169. _m.MonthlyUsageUsd = value.Float64
  170. }
  171. case userplatformquota.FieldDailyWindowStart:
  172. if value, ok := values[i].(*sql.NullTime); !ok {
  173. return fmt.Errorf("unexpected type %T for field daily_window_start", values[i])
  174. } else if value.Valid {
  175. _m.DailyWindowStart = new(time.Time)
  176. *_m.DailyWindowStart = value.Time
  177. }
  178. case userplatformquota.FieldWeeklyWindowStart:
  179. if value, ok := values[i].(*sql.NullTime); !ok {
  180. return fmt.Errorf("unexpected type %T for field weekly_window_start", values[i])
  181. } else if value.Valid {
  182. _m.WeeklyWindowStart = new(time.Time)
  183. *_m.WeeklyWindowStart = value.Time
  184. }
  185. case userplatformquota.FieldMonthlyWindowStart:
  186. if value, ok := values[i].(*sql.NullTime); !ok {
  187. return fmt.Errorf("unexpected type %T for field monthly_window_start", values[i])
  188. } else if value.Valid {
  189. _m.MonthlyWindowStart = new(time.Time)
  190. *_m.MonthlyWindowStart = value.Time
  191. }
  192. default:
  193. _m.selectValues.Set(columns[i], values[i])
  194. }
  195. }
  196. return nil
  197. }
  198. // Value returns the ent.Value that was dynamically selected and assigned to the UserPlatformQuota.
  199. // This includes values selected through modifiers, order, etc.
  200. func (_m *UserPlatformQuota) Value(name string) (ent.Value, error) {
  201. return _m.selectValues.Get(name)
  202. }
  203. // QueryUser queries the "user" edge of the UserPlatformQuota entity.
  204. func (_m *UserPlatformQuota) QueryUser() *UserQuery {
  205. return NewUserPlatformQuotaClient(_m.config).QueryUser(_m)
  206. }
  207. // Update returns a builder for updating this UserPlatformQuota.
  208. // Note that you need to call UserPlatformQuota.Unwrap() before calling this method if this UserPlatformQuota
  209. // was returned from a transaction, and the transaction was committed or rolled back.
  210. func (_m *UserPlatformQuota) Update() *UserPlatformQuotaUpdateOne {
  211. return NewUserPlatformQuotaClient(_m.config).UpdateOne(_m)
  212. }
  213. // Unwrap unwraps the UserPlatformQuota entity that was returned from a transaction after it was closed,
  214. // so that all future queries will be executed through the driver which created the transaction.
  215. func (_m *UserPlatformQuota) Unwrap() *UserPlatformQuota {
  216. _tx, ok := _m.config.driver.(*txDriver)
  217. if !ok {
  218. panic("ent: UserPlatformQuota is not a transactional entity")
  219. }
  220. _m.config.driver = _tx.drv
  221. return _m
  222. }
  223. // String implements the fmt.Stringer.
  224. func (_m *UserPlatformQuota) String() string {
  225. var builder strings.Builder
  226. builder.WriteString("UserPlatformQuota(")
  227. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  228. builder.WriteString("created_at=")
  229. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  230. builder.WriteString(", ")
  231. builder.WriteString("updated_at=")
  232. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  233. builder.WriteString(", ")
  234. if v := _m.DeletedAt; v != nil {
  235. builder.WriteString("deleted_at=")
  236. builder.WriteString(v.Format(time.ANSIC))
  237. }
  238. builder.WriteString(", ")
  239. builder.WriteString("user_id=")
  240. builder.WriteString(fmt.Sprintf("%v", _m.UserID))
  241. builder.WriteString(", ")
  242. builder.WriteString("platform=")
  243. builder.WriteString(_m.Platform)
  244. builder.WriteString(", ")
  245. if v := _m.DailyLimitUsd; v != nil {
  246. builder.WriteString("daily_limit_usd=")
  247. builder.WriteString(fmt.Sprintf("%v", *v))
  248. }
  249. builder.WriteString(", ")
  250. if v := _m.WeeklyLimitUsd; v != nil {
  251. builder.WriteString("weekly_limit_usd=")
  252. builder.WriteString(fmt.Sprintf("%v", *v))
  253. }
  254. builder.WriteString(", ")
  255. if v := _m.MonthlyLimitUsd; v != nil {
  256. builder.WriteString("monthly_limit_usd=")
  257. builder.WriteString(fmt.Sprintf("%v", *v))
  258. }
  259. builder.WriteString(", ")
  260. builder.WriteString("daily_usage_usd=")
  261. builder.WriteString(fmt.Sprintf("%v", _m.DailyUsageUsd))
  262. builder.WriteString(", ")
  263. builder.WriteString("weekly_usage_usd=")
  264. builder.WriteString(fmt.Sprintf("%v", _m.WeeklyUsageUsd))
  265. builder.WriteString(", ")
  266. builder.WriteString("monthly_usage_usd=")
  267. builder.WriteString(fmt.Sprintf("%v", _m.MonthlyUsageUsd))
  268. builder.WriteString(", ")
  269. if v := _m.DailyWindowStart; v != nil {
  270. builder.WriteString("daily_window_start=")
  271. builder.WriteString(v.Format(time.ANSIC))
  272. }
  273. builder.WriteString(", ")
  274. if v := _m.WeeklyWindowStart; v != nil {
  275. builder.WriteString("weekly_window_start=")
  276. builder.WriteString(v.Format(time.ANSIC))
  277. }
  278. builder.WriteString(", ")
  279. if v := _m.MonthlyWindowStart; v != nil {
  280. builder.WriteString("monthly_window_start=")
  281. builder.WriteString(v.Format(time.ANSIC))
  282. }
  283. builder.WriteByte(')')
  284. return builder.String()
  285. }
  286. // UserPlatformQuotaSlice is a parsable slice of UserPlatformQuota.
  287. type UserPlatformQuotaSlice []*UserPlatformQuota