accountgroup.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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/account"
  10. "github.com/Wei-Shaw/sub2api/ent/accountgroup"
  11. "github.com/Wei-Shaw/sub2api/ent/group"
  12. )
  13. // AccountGroup is the model entity for the AccountGroup schema.
  14. type AccountGroup struct {
  15. config `json:"-"`
  16. // AccountID holds the value of the "account_id" field.
  17. AccountID int64 `json:"account_id,omitempty"`
  18. // GroupID holds the value of the "group_id" field.
  19. GroupID int64 `json:"group_id,omitempty"`
  20. // Priority holds the value of the "priority" field.
  21. Priority int `json:"priority,omitempty"`
  22. // CreatedAt holds the value of the "created_at" field.
  23. CreatedAt time.Time `json:"created_at,omitempty"`
  24. // Edges holds the relations/edges for other nodes in the graph.
  25. // The values are being populated by the AccountGroupQuery when eager-loading is set.
  26. Edges AccountGroupEdges `json:"edges"`
  27. selectValues sql.SelectValues
  28. }
  29. // AccountGroupEdges holds the relations/edges for other nodes in the graph.
  30. type AccountGroupEdges struct {
  31. // Account holds the value of the account edge.
  32. Account *Account `json:"account,omitempty"`
  33. // Group holds the value of the group edge.
  34. Group *Group `json:"group,omitempty"`
  35. // loadedTypes holds the information for reporting if a
  36. // type was loaded (or requested) in eager-loading or not.
  37. loadedTypes [2]bool
  38. }
  39. // AccountOrErr returns the Account value or an error if the edge
  40. // was not loaded in eager-loading, or loaded but was not found.
  41. func (e AccountGroupEdges) AccountOrErr() (*Account, error) {
  42. if e.Account != nil {
  43. return e.Account, nil
  44. } else if e.loadedTypes[0] {
  45. return nil, &NotFoundError{label: account.Label}
  46. }
  47. return nil, &NotLoadedError{edge: "account"}
  48. }
  49. // GroupOrErr returns the Group value or an error if the edge
  50. // was not loaded in eager-loading, or loaded but was not found.
  51. func (e AccountGroupEdges) GroupOrErr() (*Group, error) {
  52. if e.Group != nil {
  53. return e.Group, nil
  54. } else if e.loadedTypes[1] {
  55. return nil, &NotFoundError{label: group.Label}
  56. }
  57. return nil, &NotLoadedError{edge: "group"}
  58. }
  59. // scanValues returns the types for scanning values from sql.Rows.
  60. func (*AccountGroup) scanValues(columns []string) ([]any, error) {
  61. values := make([]any, len(columns))
  62. for i := range columns {
  63. switch columns[i] {
  64. case accountgroup.FieldAccountID, accountgroup.FieldGroupID, accountgroup.FieldPriority:
  65. values[i] = new(sql.NullInt64)
  66. case accountgroup.FieldCreatedAt:
  67. values[i] = new(sql.NullTime)
  68. default:
  69. values[i] = new(sql.UnknownType)
  70. }
  71. }
  72. return values, nil
  73. }
  74. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  75. // to the AccountGroup fields.
  76. func (_m *AccountGroup) assignValues(columns []string, values []any) error {
  77. if m, n := len(values), len(columns); m < n {
  78. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  79. }
  80. for i := range columns {
  81. switch columns[i] {
  82. case accountgroup.FieldAccountID:
  83. if value, ok := values[i].(*sql.NullInt64); !ok {
  84. return fmt.Errorf("unexpected type %T for field account_id", values[i])
  85. } else if value.Valid {
  86. _m.AccountID = value.Int64
  87. }
  88. case accountgroup.FieldGroupID:
  89. if value, ok := values[i].(*sql.NullInt64); !ok {
  90. return fmt.Errorf("unexpected type %T for field group_id", values[i])
  91. } else if value.Valid {
  92. _m.GroupID = value.Int64
  93. }
  94. case accountgroup.FieldPriority:
  95. if value, ok := values[i].(*sql.NullInt64); !ok {
  96. return fmt.Errorf("unexpected type %T for field priority", values[i])
  97. } else if value.Valid {
  98. _m.Priority = int(value.Int64)
  99. }
  100. case accountgroup.FieldCreatedAt:
  101. if value, ok := values[i].(*sql.NullTime); !ok {
  102. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  103. } else if value.Valid {
  104. _m.CreatedAt = value.Time
  105. }
  106. default:
  107. _m.selectValues.Set(columns[i], values[i])
  108. }
  109. }
  110. return nil
  111. }
  112. // Value returns the ent.Value that was dynamically selected and assigned to the AccountGroup.
  113. // This includes values selected through modifiers, order, etc.
  114. func (_m *AccountGroup) Value(name string) (ent.Value, error) {
  115. return _m.selectValues.Get(name)
  116. }
  117. // QueryAccount queries the "account" edge of the AccountGroup entity.
  118. func (_m *AccountGroup) QueryAccount() *AccountQuery {
  119. return NewAccountGroupClient(_m.config).QueryAccount(_m)
  120. }
  121. // QueryGroup queries the "group" edge of the AccountGroup entity.
  122. func (_m *AccountGroup) QueryGroup() *GroupQuery {
  123. return NewAccountGroupClient(_m.config).QueryGroup(_m)
  124. }
  125. // Update returns a builder for updating this AccountGroup.
  126. // Note that you need to call AccountGroup.Unwrap() before calling this method if this AccountGroup
  127. // was returned from a transaction, and the transaction was committed or rolled back.
  128. func (_m *AccountGroup) Update() *AccountGroupUpdateOne {
  129. return NewAccountGroupClient(_m.config).UpdateOne(_m)
  130. }
  131. // Unwrap unwraps the AccountGroup entity that was returned from a transaction after it was closed,
  132. // so that all future queries will be executed through the driver which created the transaction.
  133. func (_m *AccountGroup) Unwrap() *AccountGroup {
  134. _tx, ok := _m.config.driver.(*txDriver)
  135. if !ok {
  136. panic("ent: AccountGroup is not a transactional entity")
  137. }
  138. _m.config.driver = _tx.drv
  139. return _m
  140. }
  141. // String implements the fmt.Stringer.
  142. func (_m *AccountGroup) String() string {
  143. var builder strings.Builder
  144. builder.WriteString("AccountGroup(")
  145. builder.WriteString("account_id=")
  146. builder.WriteString(fmt.Sprintf("%v", _m.AccountID))
  147. builder.WriteString(", ")
  148. builder.WriteString("group_id=")
  149. builder.WriteString(fmt.Sprintf("%v", _m.GroupID))
  150. builder.WriteString(", ")
  151. builder.WriteString("priority=")
  152. builder.WriteString(fmt.Sprintf("%v", _m.Priority))
  153. builder.WriteString(", ")
  154. builder.WriteString("created_at=")
  155. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  156. builder.WriteByte(')')
  157. return builder.String()
  158. }
  159. // AccountGroups is a parsable slice of AccountGroup.
  160. type AccountGroups []*AccountGroup