userallowedgroup.go 5.6 KB

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