user.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "code.osinet.fr/fgm/entdemo/ent/user"
  7. "github.com/facebookincubator/ent/dialect/sql"
  8. )
  9. // User is the model entity for the User schema.
  10. type User struct {
  11. config `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. Name string `json:"name,omitempty"`
  18. // Edges holds the relations/edges for other nodes in the graph.
  19. // The values are being populated by the UserQuery when eager-loading is set.
  20. Edges UserEdges `json:"edges"`
  21. }
  22. // UserEdges holds the relations/edges for other nodes in the graph.
  23. type UserEdges struct {
  24. // Cars holds the value of the cars edge.
  25. Cars []*Car
  26. // Groups holds the value of the groups edge.
  27. Groups []*Group
  28. // loadedTypes holds the information for reporting if a
  29. // type was loaded (or requested) in eager-loading or not.
  30. loadedTypes [2]bool
  31. }
  32. // CarsOrErr returns the Cars value or an error if the edge
  33. // was not loaded in eager-loading.
  34. func (e UserEdges) CarsOrErr() ([]*Car, error) {
  35. if e.loadedTypes[0] {
  36. return e.Cars, nil
  37. }
  38. return nil, &NotLoadedError{edge: "cars"}
  39. }
  40. // GroupsOrErr returns the Groups value or an error if the edge
  41. // was not loaded in eager-loading.
  42. func (e UserEdges) GroupsOrErr() ([]*Group, error) {
  43. if e.loadedTypes[1] {
  44. return e.Groups, nil
  45. }
  46. return nil, &NotLoadedError{edge: "groups"}
  47. }
  48. // scanValues returns the types for scanning values from sql.Rows.
  49. func (*User) scanValues() []interface{} {
  50. return []interface{}{
  51. &sql.NullInt64{}, // id
  52. &sql.NullInt64{}, // age
  53. &sql.NullString{}, // name
  54. }
  55. }
  56. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  57. // to the User fields.
  58. func (u *User) assignValues(values ...interface{}) error {
  59. if m, n := len(values), len(user.Columns); m < n {
  60. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  61. }
  62. value, ok := values[0].(*sql.NullInt64)
  63. if !ok {
  64. return fmt.Errorf("unexpected type %T for field id", value)
  65. }
  66. u.ID = int(value.Int64)
  67. values = values[1:]
  68. if value, ok := values[0].(*sql.NullInt64); !ok {
  69. return fmt.Errorf("unexpected type %T for field age", values[0])
  70. } else if value.Valid {
  71. u.Age = int(value.Int64)
  72. }
  73. if value, ok := values[1].(*sql.NullString); !ok {
  74. return fmt.Errorf("unexpected type %T for field name", values[1])
  75. } else if value.Valid {
  76. u.Name = value.String
  77. }
  78. return nil
  79. }
  80. // QueryCars queries the cars edge of the User.
  81. func (u *User) QueryCars() *CarQuery {
  82. return (&UserClient{config: u.config}).QueryCars(u)
  83. }
  84. // QueryGroups queries the groups edge of the User.
  85. func (u *User) QueryGroups() *GroupQuery {
  86. return (&UserClient{config: u.config}).QueryGroups(u)
  87. }
  88. // Update returns a builder for updating this User.
  89. // Note that, you need to call User.Unwrap() before calling this method, if this User
  90. // was returned from a transaction, and the transaction was committed or rolled back.
  91. func (u *User) Update() *UserUpdateOne {
  92. return (&UserClient{config: u.config}).UpdateOne(u)
  93. }
  94. // Unwrap unwraps the entity that was returned from a transaction after it was closed,
  95. // so that all next queries will be executed through the driver which created the transaction.
  96. func (u *User) Unwrap() *User {
  97. tx, ok := u.config.driver.(*txDriver)
  98. if !ok {
  99. panic("ent: User is not a transactional entity")
  100. }
  101. u.config.driver = tx.drv
  102. return u
  103. }
  104. // String implements the fmt.Stringer.
  105. func (u *User) String() string {
  106. var builder strings.Builder
  107. builder.WriteString("User(")
  108. builder.WriteString(fmt.Sprintf("id=%v", u.ID))
  109. builder.WriteString(", age=")
  110. builder.WriteString(fmt.Sprintf("%v", u.Age))
  111. builder.WriteString(", name=")
  112. builder.WriteString(u.Name)
  113. builder.WriteByte(')')
  114. return builder.String()
  115. }
  116. // Users is a parsable slice of User.
  117. type Users []*User
  118. func (u Users) config(cfg config) {
  119. for _i := range u {
  120. u[_i].config = cfg
  121. }
  122. }