car.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "code.osinet.fr/fgm/entdemo/ent/car"
  8. "code.osinet.fr/fgm/entdemo/ent/user"
  9. "github.com/facebookincubator/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
  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() []interface{} {
  48. return []interface{}{
  49. &sql.NullInt64{}, // id
  50. &sql.NullString{}, // model
  51. &sql.NullTime{}, // registered_at
  52. }
  53. }
  54. // fkValues returns the types for scanning foreign-keys values from sql.Rows.
  55. func (*Car) fkValues() []interface{} {
  56. return []interface{}{
  57. &sql.NullInt64{}, // user_cars
  58. }
  59. }
  60. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  61. // to the Car fields.
  62. func (c *Car) assignValues(values ...interface{}) error {
  63. if m, n := len(values), len(car.Columns); m < n {
  64. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  65. }
  66. value, ok := values[0].(*sql.NullInt64)
  67. if !ok {
  68. return fmt.Errorf("unexpected type %T for field id", value)
  69. }
  70. c.ID = int(value.Int64)
  71. values = values[1:]
  72. if value, ok := values[0].(*sql.NullString); !ok {
  73. return fmt.Errorf("unexpected type %T for field model", values[0])
  74. } else if value.Valid {
  75. c.Model = value.String
  76. }
  77. if value, ok := values[1].(*sql.NullTime); !ok {
  78. return fmt.Errorf("unexpected type %T for field registered_at", values[1])
  79. } else if value.Valid {
  80. c.RegisteredAt = value.Time
  81. }
  82. values = values[2:]
  83. if len(values) == len(car.ForeignKeys) {
  84. if value, ok := values[0].(*sql.NullInt64); !ok {
  85. return fmt.Errorf("unexpected type %T for edge-field user_cars", value)
  86. } else if value.Valid {
  87. c.user_cars = new(int)
  88. *c.user_cars = int(value.Int64)
  89. }
  90. }
  91. return nil
  92. }
  93. // QueryOwner queries the owner edge of the Car.
  94. func (c *Car) QueryOwner() *UserQuery {
  95. return (&CarClient{config: c.config}).QueryOwner(c)
  96. }
  97. // Update returns a builder for updating this Car.
  98. // Note that, you need to call Car.Unwrap() before calling this method, if this Car
  99. // was returned from a transaction, and the transaction was committed or rolled back.
  100. func (c *Car) Update() *CarUpdateOne {
  101. return (&CarClient{config: c.config}).UpdateOne(c)
  102. }
  103. // Unwrap unwraps the entity that was returned from a transaction after it was closed,
  104. // so that all next queries will be executed through the driver which created the transaction.
  105. func (c *Car) Unwrap() *Car {
  106. tx, ok := c.config.driver.(*txDriver)
  107. if !ok {
  108. panic("ent: Car is not a transactional entity")
  109. }
  110. c.config.driver = tx.drv
  111. return c
  112. }
  113. // String implements the fmt.Stringer.
  114. func (c *Car) String() string {
  115. var builder strings.Builder
  116. builder.WriteString("Car(")
  117. builder.WriteString(fmt.Sprintf("id=%v", c.ID))
  118. builder.WriteString(", model=")
  119. builder.WriteString(c.Model)
  120. builder.WriteString(", registered_at=")
  121. builder.WriteString(c.RegisteredAt.Format(time.ANSIC))
  122. builder.WriteByte(')')
  123. return builder.String()
  124. }
  125. // Cars is a parsable slice of Car.
  126. type Cars []*Car
  127. func (c Cars) config(cfg config) {
  128. for _i := range c {
  129. c[_i].config = cfg
  130. }
  131. }