group.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/group"
  7. "entgo.io/ent/dialect/sql"
  8. )
  9. // Group is the model entity for the Group schema.
  10. type Group struct {
  11. config `json:"-"`
  12. // ID of the ent.
  13. ID int `json:"id,omitempty"`
  14. // Name holds the value of the "name" field.
  15. Name string `json:"name,omitempty"`
  16. // Edges holds the relations/edges for other nodes in the graph.
  17. // The values are being populated by the GroupQuery when eager-loading is set.
  18. Edges GroupEdges `json:"edges"`
  19. }
  20. // GroupEdges holds the relations/edges for other nodes in the graph.
  21. type GroupEdges struct {
  22. // Users holds the value of the users edge.
  23. Users []*User `json:"users,omitempty"`
  24. // loadedTypes holds the information for reporting if a
  25. // type was loaded (or requested) in eager-loading or not.
  26. loadedTypes [1]bool
  27. }
  28. // UsersOrErr returns the Users value or an error if the edge
  29. // was not loaded in eager-loading.
  30. func (e GroupEdges) UsersOrErr() ([]*User, error) {
  31. if e.loadedTypes[0] {
  32. return e.Users, nil
  33. }
  34. return nil, &NotLoadedError{edge: "users"}
  35. }
  36. // scanValues returns the types for scanning values from sql.Rows.
  37. func (*Group) scanValues(columns []string) ([]interface{}, error) {
  38. values := make([]interface{}, len(columns))
  39. for i := range columns {
  40. switch columns[i] {
  41. case group.FieldID:
  42. values[i] = new(sql.NullInt64)
  43. case group.FieldName:
  44. values[i] = new(sql.NullString)
  45. default:
  46. return nil, fmt.Errorf("unexpected column %q for type Group", columns[i])
  47. }
  48. }
  49. return values, nil
  50. }
  51. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  52. // to the Group fields.
  53. func (gr *Group) assignValues(columns []string, values []interface{}) error {
  54. if m, n := len(values), len(columns); m < n {
  55. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  56. }
  57. for i := range columns {
  58. switch columns[i] {
  59. case group.FieldID:
  60. value, ok := values[i].(*sql.NullInt64)
  61. if !ok {
  62. return fmt.Errorf("unexpected type %T for field id", value)
  63. }
  64. gr.ID = int(value.Int64)
  65. case group.FieldName:
  66. if value, ok := values[i].(*sql.NullString); !ok {
  67. return fmt.Errorf("unexpected type %T for field name", values[i])
  68. } else if value.Valid {
  69. gr.Name = value.String
  70. }
  71. }
  72. }
  73. return nil
  74. }
  75. // QueryUsers queries the "users" edge of the Group entity.
  76. func (gr *Group) QueryUsers() *UserQuery {
  77. return (&GroupClient{config: gr.config}).QueryUsers(gr)
  78. }
  79. // Update returns a builder for updating this Group.
  80. // Note that you need to call Group.Unwrap() before calling this method if this Group
  81. // was returned from a transaction, and the transaction was committed or rolled back.
  82. func (gr *Group) Update() *GroupUpdateOne {
  83. return (&GroupClient{config: gr.config}).UpdateOne(gr)
  84. }
  85. // Unwrap unwraps the Group entity that was returned from a transaction after it was closed,
  86. // so that all future queries will be executed through the driver which created the transaction.
  87. func (gr *Group) Unwrap() *Group {
  88. tx, ok := gr.config.driver.(*txDriver)
  89. if !ok {
  90. panic("ent: Group is not a transactional entity")
  91. }
  92. gr.config.driver = tx.drv
  93. return gr
  94. }
  95. // String implements the fmt.Stringer.
  96. func (gr *Group) String() string {
  97. var builder strings.Builder
  98. builder.WriteString("Group(")
  99. builder.WriteString(fmt.Sprintf("id=%v", gr.ID))
  100. builder.WriteString(", name=")
  101. builder.WriteString(gr.Name)
  102. builder.WriteByte(')')
  103. return builder.String()
  104. }
  105. // Groups is a parsable slice of Group.
  106. type Groups []*Group
  107. func (gr Groups) config(cfg config) {
  108. for _i := range gr {
  109. gr[_i].config = cfg
  110. }
  111. }