subscriptionplan.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/subscriptionplan"
  10. )
  11. // SubscriptionPlan is the model entity for the SubscriptionPlan schema.
  12. type SubscriptionPlan struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID int64 `json:"id,omitempty"`
  16. // GroupID holds the value of the "group_id" field.
  17. GroupID int64 `json:"group_id,omitempty"`
  18. // Name holds the value of the "name" field.
  19. Name string `json:"name,omitempty"`
  20. // Description holds the value of the "description" field.
  21. Description string `json:"description,omitempty"`
  22. // Price holds the value of the "price" field.
  23. Price float64 `json:"price,omitempty"`
  24. // OriginalPrice holds the value of the "original_price" field.
  25. OriginalPrice *float64 `json:"original_price,omitempty"`
  26. // Currency holds the value of the "currency" field.
  27. Currency string `json:"currency,omitempty"`
  28. // ValidityDays holds the value of the "validity_days" field.
  29. ValidityDays int `json:"validity_days,omitempty"`
  30. // ValidityUnit holds the value of the "validity_unit" field.
  31. ValidityUnit string `json:"validity_unit,omitempty"`
  32. // Features holds the value of the "features" field.
  33. Features string `json:"features,omitempty"`
  34. // ProductName holds the value of the "product_name" field.
  35. ProductName string `json:"product_name,omitempty"`
  36. // ForSale holds the value of the "for_sale" field.
  37. ForSale bool `json:"for_sale,omitempty"`
  38. // SortOrder holds the value of the "sort_order" field.
  39. SortOrder int `json:"sort_order,omitempty"`
  40. // CreatedAt holds the value of the "created_at" field.
  41. CreatedAt time.Time `json:"created_at,omitempty"`
  42. // UpdatedAt holds the value of the "updated_at" field.
  43. UpdatedAt time.Time `json:"updated_at,omitempty"`
  44. selectValues sql.SelectValues
  45. }
  46. // scanValues returns the types for scanning values from sql.Rows.
  47. func (*SubscriptionPlan) scanValues(columns []string) ([]any, error) {
  48. values := make([]any, len(columns))
  49. for i := range columns {
  50. switch columns[i] {
  51. case subscriptionplan.FieldForSale:
  52. values[i] = new(sql.NullBool)
  53. case subscriptionplan.FieldPrice, subscriptionplan.FieldOriginalPrice:
  54. values[i] = new(sql.NullFloat64)
  55. case subscriptionplan.FieldID, subscriptionplan.FieldGroupID, subscriptionplan.FieldValidityDays, subscriptionplan.FieldSortOrder:
  56. values[i] = new(sql.NullInt64)
  57. case subscriptionplan.FieldName, subscriptionplan.FieldDescription, subscriptionplan.FieldCurrency, subscriptionplan.FieldValidityUnit, subscriptionplan.FieldFeatures, subscriptionplan.FieldProductName:
  58. values[i] = new(sql.NullString)
  59. case subscriptionplan.FieldCreatedAt, subscriptionplan.FieldUpdatedAt:
  60. values[i] = new(sql.NullTime)
  61. default:
  62. values[i] = new(sql.UnknownType)
  63. }
  64. }
  65. return values, nil
  66. }
  67. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  68. // to the SubscriptionPlan fields.
  69. func (_m *SubscriptionPlan) assignValues(columns []string, values []any) error {
  70. if m, n := len(values), len(columns); m < n {
  71. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  72. }
  73. for i := range columns {
  74. switch columns[i] {
  75. case subscriptionplan.FieldID:
  76. value, ok := values[i].(*sql.NullInt64)
  77. if !ok {
  78. return fmt.Errorf("unexpected type %T for field id", value)
  79. }
  80. _m.ID = int64(value.Int64)
  81. case subscriptionplan.FieldGroupID:
  82. if value, ok := values[i].(*sql.NullInt64); !ok {
  83. return fmt.Errorf("unexpected type %T for field group_id", values[i])
  84. } else if value.Valid {
  85. _m.GroupID = value.Int64
  86. }
  87. case subscriptionplan.FieldName:
  88. if value, ok := values[i].(*sql.NullString); !ok {
  89. return fmt.Errorf("unexpected type %T for field name", values[i])
  90. } else if value.Valid {
  91. _m.Name = value.String
  92. }
  93. case subscriptionplan.FieldDescription:
  94. if value, ok := values[i].(*sql.NullString); !ok {
  95. return fmt.Errorf("unexpected type %T for field description", values[i])
  96. } else if value.Valid {
  97. _m.Description = value.String
  98. }
  99. case subscriptionplan.FieldPrice:
  100. if value, ok := values[i].(*sql.NullFloat64); !ok {
  101. return fmt.Errorf("unexpected type %T for field price", values[i])
  102. } else if value.Valid {
  103. _m.Price = value.Float64
  104. }
  105. case subscriptionplan.FieldOriginalPrice:
  106. if value, ok := values[i].(*sql.NullFloat64); !ok {
  107. return fmt.Errorf("unexpected type %T for field original_price", values[i])
  108. } else if value.Valid {
  109. _m.OriginalPrice = new(float64)
  110. *_m.OriginalPrice = value.Float64
  111. }
  112. case subscriptionplan.FieldCurrency:
  113. if value, ok := values[i].(*sql.NullString); !ok {
  114. return fmt.Errorf("unexpected type %T for field currency", values[i])
  115. } else if value.Valid {
  116. _m.Currency = value.String
  117. }
  118. case subscriptionplan.FieldValidityDays:
  119. if value, ok := values[i].(*sql.NullInt64); !ok {
  120. return fmt.Errorf("unexpected type %T for field validity_days", values[i])
  121. } else if value.Valid {
  122. _m.ValidityDays = int(value.Int64)
  123. }
  124. case subscriptionplan.FieldValidityUnit:
  125. if value, ok := values[i].(*sql.NullString); !ok {
  126. return fmt.Errorf("unexpected type %T for field validity_unit", values[i])
  127. } else if value.Valid {
  128. _m.ValidityUnit = value.String
  129. }
  130. case subscriptionplan.FieldFeatures:
  131. if value, ok := values[i].(*sql.NullString); !ok {
  132. return fmt.Errorf("unexpected type %T for field features", values[i])
  133. } else if value.Valid {
  134. _m.Features = value.String
  135. }
  136. case subscriptionplan.FieldProductName:
  137. if value, ok := values[i].(*sql.NullString); !ok {
  138. return fmt.Errorf("unexpected type %T for field product_name", values[i])
  139. } else if value.Valid {
  140. _m.ProductName = value.String
  141. }
  142. case subscriptionplan.FieldForSale:
  143. if value, ok := values[i].(*sql.NullBool); !ok {
  144. return fmt.Errorf("unexpected type %T for field for_sale", values[i])
  145. } else if value.Valid {
  146. _m.ForSale = value.Bool
  147. }
  148. case subscriptionplan.FieldSortOrder:
  149. if value, ok := values[i].(*sql.NullInt64); !ok {
  150. return fmt.Errorf("unexpected type %T for field sort_order", values[i])
  151. } else if value.Valid {
  152. _m.SortOrder = int(value.Int64)
  153. }
  154. case subscriptionplan.FieldCreatedAt:
  155. if value, ok := values[i].(*sql.NullTime); !ok {
  156. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  157. } else if value.Valid {
  158. _m.CreatedAt = value.Time
  159. }
  160. case subscriptionplan.FieldUpdatedAt:
  161. if value, ok := values[i].(*sql.NullTime); !ok {
  162. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  163. } else if value.Valid {
  164. _m.UpdatedAt = value.Time
  165. }
  166. default:
  167. _m.selectValues.Set(columns[i], values[i])
  168. }
  169. }
  170. return nil
  171. }
  172. // Value returns the ent.Value that was dynamically selected and assigned to the SubscriptionPlan.
  173. // This includes values selected through modifiers, order, etc.
  174. func (_m *SubscriptionPlan) Value(name string) (ent.Value, error) {
  175. return _m.selectValues.Get(name)
  176. }
  177. // Update returns a builder for updating this SubscriptionPlan.
  178. // Note that you need to call SubscriptionPlan.Unwrap() before calling this method if this SubscriptionPlan
  179. // was returned from a transaction, and the transaction was committed or rolled back.
  180. func (_m *SubscriptionPlan) Update() *SubscriptionPlanUpdateOne {
  181. return NewSubscriptionPlanClient(_m.config).UpdateOne(_m)
  182. }
  183. // Unwrap unwraps the SubscriptionPlan entity that was returned from a transaction after it was closed,
  184. // so that all future queries will be executed through the driver which created the transaction.
  185. func (_m *SubscriptionPlan) Unwrap() *SubscriptionPlan {
  186. _tx, ok := _m.config.driver.(*txDriver)
  187. if !ok {
  188. panic("ent: SubscriptionPlan is not a transactional entity")
  189. }
  190. _m.config.driver = _tx.drv
  191. return _m
  192. }
  193. // String implements the fmt.Stringer.
  194. func (_m *SubscriptionPlan) String() string {
  195. var builder strings.Builder
  196. builder.WriteString("SubscriptionPlan(")
  197. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  198. builder.WriteString("group_id=")
  199. builder.WriteString(fmt.Sprintf("%v", _m.GroupID))
  200. builder.WriteString(", ")
  201. builder.WriteString("name=")
  202. builder.WriteString(_m.Name)
  203. builder.WriteString(", ")
  204. builder.WriteString("description=")
  205. builder.WriteString(_m.Description)
  206. builder.WriteString(", ")
  207. builder.WriteString("price=")
  208. builder.WriteString(fmt.Sprintf("%v", _m.Price))
  209. builder.WriteString(", ")
  210. if v := _m.OriginalPrice; v != nil {
  211. builder.WriteString("original_price=")
  212. builder.WriteString(fmt.Sprintf("%v", *v))
  213. }
  214. builder.WriteString(", ")
  215. builder.WriteString("currency=")
  216. builder.WriteString(_m.Currency)
  217. builder.WriteString(", ")
  218. builder.WriteString("validity_days=")
  219. builder.WriteString(fmt.Sprintf("%v", _m.ValidityDays))
  220. builder.WriteString(", ")
  221. builder.WriteString("validity_unit=")
  222. builder.WriteString(_m.ValidityUnit)
  223. builder.WriteString(", ")
  224. builder.WriteString("features=")
  225. builder.WriteString(_m.Features)
  226. builder.WriteString(", ")
  227. builder.WriteString("product_name=")
  228. builder.WriteString(_m.ProductName)
  229. builder.WriteString(", ")
  230. builder.WriteString("for_sale=")
  231. builder.WriteString(fmt.Sprintf("%v", _m.ForSale))
  232. builder.WriteString(", ")
  233. builder.WriteString("sort_order=")
  234. builder.WriteString(fmt.Sprintf("%v", _m.SortOrder))
  235. builder.WriteString(", ")
  236. builder.WriteString("created_at=")
  237. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  238. builder.WriteString(", ")
  239. builder.WriteString("updated_at=")
  240. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  241. builder.WriteByte(')')
  242. return builder.String()
  243. }
  244. // SubscriptionPlans is a parsable slice of SubscriptionPlan.
  245. type SubscriptionPlans []*SubscriptionPlan