car.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "code.osinet.fr/fgm/go__ent_demo/ent/car"
  8. "code.osinet.fr/fgm/go__ent_demo/ent/user"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // Car is the model entity for the Car schema.
  12. type Car struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID int `json:"id,omitempty"`
  16. // Model holds the value of the "model" field.
  17. Model string `json:"model,omitempty"`
  18. // RegisteredAt holds the value of the "registered_at" field.
  19. RegisteredAt time.Time `json:"registered_at,omitempty"`
  20. // Edges holds the relations/edges for other nodes in the graph.
  21. // The values are being populated by the CarQuery when eager-loading is set.
  22. Edges CarEdges `json:"edges"`
  23. user_cars *int
  24. }
  25. // CarEdges holds the relations/edges for other nodes in the graph.
  26. type CarEdges struct {
  27. // Owner holds the value of the owner edge.
  28. Owner *User `json:"owner,omitempty"`
  29. // loadedTypes holds the information for reporting if a
  30. // type was loaded (or requested) in eager-loading or not.
  31. loadedTypes [1]bool
  32. }
  33. // OwnerOrErr returns the Owner value or an error if the edge
  34. // was not loaded in eager-loading, or loaded but was not found.
  35. func (e CarEdges) OwnerOrErr() (*User, error) {
  36. if e.loadedTypes[0] {
  37. if e.Owner == nil {
  38. // The edge owner was loaded in eager-loading,
  39. // but was not found.
  40. return nil, &NotFoundError{label: user.Label}
  41. }
  42. return e.Owner, nil
  43. }
  44. return nil, &NotLoadedError{edge: "owner"}
  45. }
  46. // scanValues returns the types for scanning values from sql.Rows.
  47. func (*Car) scanValues(columns []string) ([]interface{}, error) {
  48. values := make([]interface{}, len(columns))
  49. for i := range columns {
  50. switch columns[i] {
  51. case car.FieldID:
  52. values[i] = new(sql.NullInt64)
  53. case car.FieldModel:
  54. values[i] = new(sql.NullString)
  55. case car.FieldRegisteredAt:
  56. values[i] = new(sql.NullTime)
  57. case car.ForeignKeys[0]: // user_cars
  58. values[i] = new(sql.NullInt64)
  59. default:
  60. return nil, fmt.Errorf("unexpected column %q for type Car", columns[i])
  61. }
  62. }
  63. return values, nil
  64. }
  65. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  66. // to the Car fields.
  67. func (c *Car) assignValues(columns []string, values []interface{}) error {
  68. if m, n := len(values), len(columns); m < n {
  69. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  70. }
  71. for i := range columns {
  72. switch columns[i] {
  73. case car.FieldID:
  74. value, ok := values[i].(*sql.NullInt64)
  75. if !ok {
  76. return fmt.Errorf("unexpected type %T for field id", value)
  77. }
  78. c.ID = int(value.Int64)
  79. case car.FieldModel:
  80. if value, ok := values[i].(*sql.NullString); !ok {
  81. return fmt.Errorf("unexpected type %T for field model", values[i])
  82. } else if value.Valid {
  83. c.Model = value.String
  84. }
  85. case car.FieldRegisteredAt:
  86. if value, ok := values[i].(*sql.NullTime); !ok {
  87. return fmt.Errorf("unexpected type %T for field registered_at", values[i])
  88. } else if value.Valid {
  89. c.RegisteredAt = value.Time
  90. }
  91. case car.ForeignKeys[0]:
  92. if value, ok := values[i].(*sql.NullInt64); !ok {
  93. return fmt.Errorf("unexpected type %T for edge-field user_cars", value)
  94. } else if value.Valid {
  95. c.user_cars = new(int)
  96. *c.user_cars = int(value.Int64)
  97. }
  98. }
  99. }
  100. return nil
  101. }
  102. // QueryOwner queries the "owner" edge of the Car entity.
  103. func (c *Car) QueryOwner() *UserQuery {
  104. return (&CarClient{config: c.config}).QueryOwner(c)
  105. }
  106. // Update returns a builder for updating this Car.
  107. // Note that you need to call Car.Unwrap() before calling this method if this Car
  108. // was returned from a transaction, and the transaction was committed or rolled back.
  109. func (c *Car) Update() *CarUpdateOne {
  110. return (&CarClient{config: c.config}).UpdateOne(c)
  111. }
  112. // Unwrap unwraps the Car entity that was returned from a transaction after it was closed,
  113. // so that all future queries will be executed through the driver which created the transaction.
  114. func (c *Car) Unwrap() *Car {
  115. tx, ok := c.config.driver.(*txDriver)
  116. if !ok {
  117. panic("ent: Car is not a transactional entity")
  118. }
  119. c.config.driver = tx.drv
  120. return c
  121. }
  122. // String implements the fmt.Stringer.
  123. func (c *Car) String() string {
  124. var builder strings.Builder
  125. builder.WriteString("Car(")
  126. builder.WriteString(fmt.Sprintf("id=%v", c.ID))
  127. builder.WriteString(", model=")
  128. builder.WriteString(c.Model)
  129. builder.WriteString(", registered_at=")
  130. builder.WriteString(c.RegisteredAt.Format(time.ANSIC))
  131. builder.WriteByte(')')
  132. return builder.String()
  133. }
  134. // Cars is a parsable slice of Car.
  135. type Cars []*Car
  136. func (c Cars) config(cfg config) {
  137. for _i := range c {
  138. c[_i].config = cfg
  139. }
  140. }