user.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "code.osinet.fr/fgm/go__ent_demo/ent/user"
  7. "entgo.io/ent/dialect/sql"
  8. )
  9. // User is the model entity for the User schema.
  10. type User struct {
  11. config `gqlgen:"-" json:"-"`
  12. // ID of the ent.
  13. ID int `json:"id,omitempty"`
  14. // Age holds the value of the "age" field.
  15. Age int `json:"age,omitempty"`
  16. // Name holds the value of the "name" field.
  17. // This is the last name
  18. Name string `json:"name,omitempty" gqlgen:"gql_name"`
  19. // Password holds the value of the "password" field.
  20. Password string `gqlgen:"-" json:"-"`
  21. // Size holds the value of the "size" field.
  22. // the helmet size
  23. Size user.Size `json:"size,omitempty"`
  24. // SpouseID holds the value of the "spouse_id" field.
  25. SpouseID int `json:"spouse_id,omitempty"`
  26. // Edges holds the relations/edges for other nodes in the graph.
  27. // The values are being populated by the UserQuery when eager-loading is set.
  28. Edges UserEdges `json:"edges"`
  29. }
  30. // UserEdges holds the relations/edges for other nodes in the graph.
  31. type UserEdges struct {
  32. // Cars holds the value of the cars edge.
  33. Cars []*Car `json:"cars,omitempty"`
  34. // Groups holds the value of the groups edge.
  35. Groups []*Group `json:"groups,omitempty"`
  36. // Spouse holds the value of the spouse edge.
  37. Spouse *User `json:"spouse,omitempty"`
  38. // Followers holds the value of the followers edge.
  39. Followers []*User `json:"followers,omitempty"`
  40. // Following holds the value of the following edge.
  41. Following []*User `json:"following,omitempty"`
  42. // Friends holds the value of the friends edge.
  43. Friends []*User `json:"friends,omitempty"`
  44. // loadedTypes holds the information for reporting if a
  45. // type was loaded (or requested) in eager-loading or not.
  46. loadedTypes [6]bool
  47. }
  48. // CarsOrErr returns the Cars value or an error if the edge
  49. // was not loaded in eager-loading.
  50. func (e UserEdges) CarsOrErr() ([]*Car, error) {
  51. if e.loadedTypes[0] {
  52. return e.Cars, nil
  53. }
  54. return nil, &NotLoadedError{edge: "cars"}
  55. }
  56. // GroupsOrErr returns the Groups value or an error if the edge
  57. // was not loaded in eager-loading.
  58. func (e UserEdges) GroupsOrErr() ([]*Group, error) {
  59. if e.loadedTypes[1] {
  60. return e.Groups, nil
  61. }
  62. return nil, &NotLoadedError{edge: "groups"}
  63. }
  64. // SpouseOrErr returns the Spouse value or an error if the edge
  65. // was not loaded in eager-loading, or loaded but was not found.
  66. func (e UserEdges) SpouseOrErr() (*User, error) {
  67. if e.loadedTypes[2] {
  68. if e.Spouse == nil {
  69. // The edge spouse was loaded in eager-loading,
  70. // but was not found.
  71. return nil, &NotFoundError{label: user.Label}
  72. }
  73. return e.Spouse, nil
  74. }
  75. return nil, &NotLoadedError{edge: "spouse"}
  76. }
  77. // FollowersOrErr returns the Followers value or an error if the edge
  78. // was not loaded in eager-loading.
  79. func (e UserEdges) FollowersOrErr() ([]*User, error) {
  80. if e.loadedTypes[3] {
  81. return e.Followers, nil
  82. }
  83. return nil, &NotLoadedError{edge: "followers"}
  84. }
  85. // FollowingOrErr returns the Following value or an error if the edge
  86. // was not loaded in eager-loading.
  87. func (e UserEdges) FollowingOrErr() ([]*User, error) {
  88. if e.loadedTypes[4] {
  89. return e.Following, nil
  90. }
  91. return nil, &NotLoadedError{edge: "following"}
  92. }
  93. // FriendsOrErr returns the Friends value or an error if the edge
  94. // was not loaded in eager-loading.
  95. func (e UserEdges) FriendsOrErr() ([]*User, error) {
  96. if e.loadedTypes[5] {
  97. return e.Friends, nil
  98. }
  99. return nil, &NotLoadedError{edge: "friends"}
  100. }
  101. // scanValues returns the types for scanning values from sql.Rows.
  102. func (*User) scanValues(columns []string) ([]interface{}, error) {
  103. values := make([]interface{}, len(columns))
  104. for i := range columns {
  105. switch columns[i] {
  106. case user.FieldID, user.FieldAge, user.FieldSpouseID:
  107. values[i] = new(sql.NullInt64)
  108. case user.FieldName, user.FieldPassword, user.FieldSize:
  109. values[i] = new(sql.NullString)
  110. default:
  111. return nil, fmt.Errorf("unexpected column %q for type User", columns[i])
  112. }
  113. }
  114. return values, nil
  115. }
  116. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  117. // to the User fields.
  118. func (u *User) assignValues(columns []string, values []interface{}) error {
  119. if m, n := len(values), len(columns); m < n {
  120. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  121. }
  122. for i := range columns {
  123. switch columns[i] {
  124. case user.FieldID:
  125. value, ok := values[i].(*sql.NullInt64)
  126. if !ok {
  127. return fmt.Errorf("unexpected type %T for field id", value)
  128. }
  129. u.ID = int(value.Int64)
  130. case user.FieldAge:
  131. if value, ok := values[i].(*sql.NullInt64); !ok {
  132. return fmt.Errorf("unexpected type %T for field age", values[i])
  133. } else if value.Valid {
  134. u.Age = int(value.Int64)
  135. }
  136. case user.FieldName:
  137. if value, ok := values[i].(*sql.NullString); !ok {
  138. return fmt.Errorf("unexpected type %T for field name", values[i])
  139. } else if value.Valid {
  140. u.Name = value.String
  141. }
  142. case user.FieldPassword:
  143. if value, ok := values[i].(*sql.NullString); !ok {
  144. return fmt.Errorf("unexpected type %T for field password", values[i])
  145. } else if value.Valid {
  146. u.Password = value.String
  147. }
  148. case user.FieldSize:
  149. if value, ok := values[i].(*sql.NullString); !ok {
  150. return fmt.Errorf("unexpected type %T for field size", values[i])
  151. } else if value.Valid {
  152. u.Size = user.Size(value.String)
  153. }
  154. case user.FieldSpouseID:
  155. if value, ok := values[i].(*sql.NullInt64); !ok {
  156. return fmt.Errorf("unexpected type %T for field spouse_id", values[i])
  157. } else if value.Valid {
  158. u.SpouseID = int(value.Int64)
  159. }
  160. }
  161. }
  162. return nil
  163. }
  164. // QueryCars queries the "cars" edge of the User entity.
  165. func (u *User) QueryCars() *CarQuery {
  166. return (&UserClient{config: u.config}).QueryCars(u)
  167. }
  168. // QueryGroups queries the "groups" edge of the User entity.
  169. func (u *User) QueryGroups() *GroupQuery {
  170. return (&UserClient{config: u.config}).QueryGroups(u)
  171. }
  172. // QuerySpouse queries the "spouse" edge of the User entity.
  173. func (u *User) QuerySpouse() *UserQuery {
  174. return (&UserClient{config: u.config}).QuerySpouse(u)
  175. }
  176. // QueryFollowers queries the "followers" edge of the User entity.
  177. func (u *User) QueryFollowers() *UserQuery {
  178. return (&UserClient{config: u.config}).QueryFollowers(u)
  179. }
  180. // QueryFollowing queries the "following" edge of the User entity.
  181. func (u *User) QueryFollowing() *UserQuery {
  182. return (&UserClient{config: u.config}).QueryFollowing(u)
  183. }
  184. // QueryFriends queries the "friends" edge of the User entity.
  185. func (u *User) QueryFriends() *UserQuery {
  186. return (&UserClient{config: u.config}).QueryFriends(u)
  187. }
  188. // Update returns a builder for updating this User.
  189. // Note that you need to call User.Unwrap() before calling this method if this User
  190. // was returned from a transaction, and the transaction was committed or rolled back.
  191. func (u *User) Update() *UserUpdateOne {
  192. return (&UserClient{config: u.config}).UpdateOne(u)
  193. }
  194. // Unwrap unwraps the User entity that was returned from a transaction after it was closed,
  195. // so that all future queries will be executed through the driver which created the transaction.
  196. func (u *User) Unwrap() *User {
  197. tx, ok := u.config.driver.(*txDriver)
  198. if !ok {
  199. panic("ent: User is not a transactional entity")
  200. }
  201. u.config.driver = tx.drv
  202. return u
  203. }
  204. // String implements the fmt.Stringer.
  205. func (u *User) String() string {
  206. var builder strings.Builder
  207. builder.WriteString("User(")
  208. builder.WriteString(fmt.Sprintf("id=%v", u.ID))
  209. builder.WriteString(", age=")
  210. builder.WriteString(fmt.Sprintf("%v", u.Age))
  211. builder.WriteString(", name=")
  212. builder.WriteString(u.Name)
  213. builder.WriteString(", password=<sensitive>")
  214. builder.WriteString(", size=")
  215. builder.WriteString(fmt.Sprintf("%v", u.Size))
  216. builder.WriteString(", spouse_id=")
  217. builder.WriteString(fmt.Sprintf("%v", u.SpouseID))
  218. builder.WriteByte(')')
  219. return builder.String()
  220. }
  221. // Users is a parsable slice of User.
  222. type Users []*User
  223. func (u Users) config(cfg config) {
  224. for _i := range u {
  225. u[_i].config = cfg
  226. }
  227. }